From 932e56cca70c35a530c74ab3a0cfb6aa2933e46b Mon Sep 17 00:00:00 2001 From: Keith Schincke Date: Tue, 4 Jun 2024 12:03:00 -0500 Subject: [PATCH 1/4] Add default ma_attempts param to get_local_time --- adafruit_portalbase/network.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 57a6369..9cf7ef2 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -203,11 +203,13 @@ def url_encode(url): """ return url.replace(" ", "+").replace("%", "%25").replace(":", "%3A") - def get_strftime(self, time_format, location=None): + def get_strftime(self, time_format, location=None, max_attempts=10): """ Fetch a custom strftime relative to your location. :param str location: Your city and country, e.g. ``"America/New_York"``. + :param max_attempts: The maximum number of of attempts to connect to WiFi before + failing or use None to disable. Defaults to 10. """ # pylint: disable=line-too-long @@ -259,12 +261,14 @@ def get_strftime(self, time_format, location=None): return reply - def get_local_time(self, location=None): + def get_local_time(self, location=None, max_attempts=10): # pylint: disable=line-too-long """ Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API. :param str location: Your city and country, e.g. ``"America/New_York"``. + :param max_attempts: The maximum number of of attempts to connect to WiFi before + failing or use None to disable. Defaults to 10. """ reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location) From 6eb0c372d3da63db812ddbccbe244607353afe74 Mon Sep 17 00:00:00 2001 From: Keith Schincke Date: Tue, 4 Jun 2024 12:07:00 -0500 Subject: [PATCH 2/4] Appemding the patch to actually do something --- adafruit_portalbase/network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 9cf7ef2..e9a91a9 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -213,7 +213,7 @@ def get_strftime(self, time_format, location=None, max_attempts=10): """ # pylint: disable=line-too-long - self.connect() + self.connect(max_attempts=max_attempts) api_url = None reply = None try: @@ -271,7 +271,7 @@ def get_local_time(self, location=None, max_attempts=10): failing or use None to disable. Defaults to 10. """ - reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location) + reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts) if reply: times = reply.split(" ") the_date = times[0] From a1ed9857b11e4648aa4f204d5efd7438efb248d2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 15 Jul 2024 11:58:56 -0500 Subject: [PATCH 3/4] fixes for format and pylint --- adafruit_portalbase/__init__.py | 2 +- adafruit_portalbase/graphics.py | 2 +- adafruit_portalbase/network.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_portalbase/__init__.py b/adafruit_portalbase/__init__.py index d3f6133..27aa656 100644 --- a/adafruit_portalbase/__init__.py +++ b/adafruit_portalbase/__init__.py @@ -55,7 +55,7 @@ class PortalBase: """ - # pylint: disable=too-many-instance-attributes, too-many-branches, too-many-public-methods + # pylint: disable=too-many-instance-attributes, too-many-branches, too-many-public-methods, too-many-arguments def __init__( self, network, diff --git a/adafruit_portalbase/graphics.py b/adafruit_portalbase/graphics.py index c9bbb0d..2c6114a 100644 --- a/adafruit_portalbase/graphics.py +++ b/adafruit_portalbase/graphics.py @@ -102,7 +102,7 @@ def set_background(self, file_or_color, position=None): def qrcode( self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000 - ): # pylint: disable=invalid-name + ): # pylint: disable=invalid-name, too-many-arguments """Display a QR code :param qr_data: The data for the QR code, None to remove. diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index e9a91a9..71d821c 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -271,7 +271,9 @@ def get_local_time(self, location=None, max_attempts=10): failing or use None to disable. Defaults to 10. """ - reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts) + reply = self.get_strftime( + TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts + ) if reply: times = reply.split(" ") the_date = times[0] @@ -635,7 +637,7 @@ def fetch_data( json_path=None, regexp_path=None, timeout=10, - ): + ): # pylint: disable=too-many-arguments """Fetch data from the specified url and perfom any parsing :param str url: The URL to fetch from. From 46ab21deaa2f18f9e39af468c6e4d9150b68724b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 21 Jul 2024 10:46:37 -0500 Subject: [PATCH 4/4] add max_attempts arg to base.get_local_time() --- adafruit_portalbase/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_portalbase/__init__.py b/adafruit_portalbase/__init__.py index 27aa656..a621382 100644 --- a/adafruit_portalbase/__init__.py +++ b/adafruit_portalbase/__init__.py @@ -484,12 +484,12 @@ def _fill_text_labels(self, values): self._fetch_set_text(string, index=i) value_index += 1 - def get_local_time(self, location=None): + def get_local_time(self, location=None, max_attempts=10): """Accessor function for get_local_time()""" if self.network is None: raise RuntimeError("network must not be None to use get_local_time()") - return self.network.get_local_time(location=location) + return self.network.get_local_time(location=location, max_attempts=max_attempts) def push_to_io(self, feed_key, data, metadata=None, precision=None): """Push data to an adafruit.io feed