Skip to content

Commit ea7fb41

Browse files
committed
Merge branch 'refs/heads/main' into ruff-updates
# Conflicts: # adafruit_portalbase/__init__.py # adafruit_portalbase/graphics.py # adafruit_portalbase/network.py
2 parents 94ff9c0 + 9c288c6 commit ea7fb41

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

adafruit_portalbase/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,12 @@ def _fill_text_labels(self, values):
480480
self._fetch_set_text(string, index=i)
481481
value_index += 1
482482

483-
def get_local_time(self, location=None):
483+
def get_local_time(self, location=None, max_attempts=10):
484484
"""Accessor function for get_local_time()"""
485485
if self.network is None:
486486
raise RuntimeError("network must not be None to use get_local_time()")
487487

488-
return self.network.get_local_time(location=location)
488+
return self.network.get_local_time(location=location, max_attempts=max_attempts)
489489

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

adafruit_portalbase/network.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,16 @@ def url_encode(url):
201201
"""
202202
return url.replace(" ", "+").replace("%", "%25").replace(":", "%3A")
203203

204-
def get_strftime(self, time_format, location=None):
204+
def get_strftime(self, time_format, location=None, max_attempts=10):
205205
"""
206206
Fetch a custom strftime relative to your location.
207207
208208
:param str location: Your city and country, e.g. ``"America/New_York"``.
209+
:param max_attempts: The maximum number of of attempts to connect to WiFi before
210+
failing or use None to disable. Defaults to 10.
209211
210212
"""
211-
self.connect()
213+
self.connect(max_attempts=max_attempts)
212214
api_url = None
213215
reply = None
214216
try:
@@ -256,14 +258,18 @@ def get_strftime(self, time_format, location=None):
256258

257259
return reply
258260

259-
def get_local_time(self, location=None):
261+
def get_local_time(self, location=None, max_attempts=10):
260262
"""
261263
Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API.
262264
263265
:param str location: Your city and country, e.g. ``"America/New_York"``.
266+
:param max_attempts: The maximum number of of attempts to connect to WiFi before
267+
failing or use None to disable. Defaults to 10.
264268
265269
"""
266-
reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location)
270+
reply = self.get_strftime(
271+
TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts
272+
)
267273
if reply:
268274
times = reply.split(" ")
269275
the_date = times[0]

0 commit comments

Comments
 (0)