Skip to content

Commit 9c288c6

Browse files
authored
Merge pull request #103 from colonwq/update_get_local_time
Add max_attempts to get_local_time
2 parents 1b0c94a + 46ab21d commit 9c288c6

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

adafruit_portalbase/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PortalBase:
5555
5656
"""
5757

58-
# pylint: disable=too-many-instance-attributes, too-many-branches, too-many-public-methods
58+
# pylint: disable=too-many-instance-attributes, too-many-branches, too-many-public-methods, too-many-arguments
5959
def __init__(
6060
self,
6161
network,
@@ -484,12 +484,12 @@ def _fill_text_labels(self, values):
484484
self._fetch_set_text(string, index=i)
485485
value_index += 1
486486

487-
def get_local_time(self, location=None):
487+
def get_local_time(self, location=None, max_attempts=10):
488488
"""Accessor function for get_local_time()"""
489489
if self.network is None:
490490
raise RuntimeError("network must not be None to use get_local_time()")
491491

492-
return self.network.get_local_time(location=location)
492+
return self.network.get_local_time(location=location, max_attempts=max_attempts)
493493

494494
def push_to_io(self, feed_key, data, metadata=None, precision=None):
495495
"""Push data to an adafruit.io feed

adafruit_portalbase/graphics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def set_background(self, file_or_color, position=None):
102102

103103
def qrcode(
104104
self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000
105-
): # pylint: disable=invalid-name
105+
): # pylint: disable=invalid-name, too-many-arguments
106106
"""Display a QR code
107107
108108
:param qr_data: The data for the QR code, None to remove.

adafruit_portalbase/network.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,17 @@ def url_encode(url):
203203
"""
204204
return url.replace(" ", "+").replace("%", "%25").replace(":", "%3A")
205205

206-
def get_strftime(self, time_format, location=None):
206+
def get_strftime(self, time_format, location=None, max_attempts=10):
207207
"""
208208
Fetch a custom strftime relative to your location.
209209
210210
:param str location: Your city and country, e.g. ``"America/New_York"``.
211+
:param max_attempts: The maximum number of of attempts to connect to WiFi before
212+
failing or use None to disable. Defaults to 10.
211213
212214
"""
213215
# pylint: disable=line-too-long
214-
self.connect()
216+
self.connect(max_attempts=max_attempts)
215217
api_url = None
216218
reply = None
217219
try:
@@ -259,15 +261,19 @@ def get_strftime(self, time_format, location=None):
259261

260262
return reply
261263

262-
def get_local_time(self, location=None):
264+
def get_local_time(self, location=None, max_attempts=10):
263265
# pylint: disable=line-too-long
264266
"""
265267
Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API.
266268
267269
:param str location: Your city and country, e.g. ``"America/New_York"``.
270+
:param max_attempts: The maximum number of of attempts to connect to WiFi before
271+
failing or use None to disable. Defaults to 10.
268272
269273
"""
270-
reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location)
274+
reply = self.get_strftime(
275+
TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts
276+
)
271277
if reply:
272278
times = reply.split(" ")
273279
the_date = times[0]
@@ -631,7 +637,7 @@ def fetch_data(
631637
json_path=None,
632638
regexp_path=None,
633639
timeout=10,
634-
):
640+
): # pylint: disable=too-many-arguments
635641
"""Fetch data from the specified url and perfom any parsing
636642
637643
:param str url: The URL to fetch from.

0 commit comments

Comments
 (0)