diff --git a/adafruit_portalbase/__init__.py b/adafruit_portalbase/__init__.py index 38b9352..953163d 100644 --- a/adafruit_portalbase/__init__.py +++ b/adafruit_portalbase/__init__.py @@ -480,12 +480,12 @@ class PortalBase: 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 diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 288aa3d..33937e7 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -201,14 +201,16 @@ class NetworkBase: """ 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. """ - self.connect() + self.connect(max_attempts=max_attempts) api_url = None reply = None try: @@ -256,14 +258,18 @@ class NetworkBase: return reply - def get_local_time(self, location=None): + def get_local_time(self, location=None, max_attempts=10): """ 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) + reply = self.get_strftime( + TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts + ) if reply: times = reply.split(" ") the_date = times[0]