Closed
Description
Currently, adafruit_pyportal::get_local_time() raises the exception
ValueError if the REST call returns anything other than a 200:
@@ -722,7 +722,7 @@ class PyPortal:
try:
response = requests.get(api_url, timeout=10)
if response.status_code != 200:
raise ValueError(response.text)
That is okay, except that all the examples that use that method
expect RuntimeError exception in order to handle it gracefully:
$ grep -n 'pyportal.get_local_time' -C 4 PyPortal_Alarm_Clock/code.py
237- # only query the online time once per hour (and on first run)
238- if (not self.refresh_time) or ((now - self.refresh_time) > 3600):
239- logger.debug('Fetching time')
240- try:
241: pyportal.get_local_time(location=secrets['timezone'])
242- self.refresh_time = now
243- except RuntimeError as e:
244- self.refresh_time = now - 3000 # delay 10 minutes before retrying
245- logger.error('Some error occured, retrying! - %s', str(e))
All these example do similar handling:
Adafruit_Learning_System_Guides.git
$ grep -lr 'pyportal.get_local_time' *
PyPortal_Alarm_Clock/code.py
PyPortal_CircuitPython_2020/code.py
PyPortal_Electioncal_US/electioncal.py
PyPortal_EventCountdown/eventcountdown.py
PyPortal_EventCountup/eventcountup.py
PyPortal_Halloween_Countdown/code.py
PyPortal_ISS_Tracker/pp_iss_tracker.py
PyPortal_MogwaiClock/mogwai.py
PyPortal_OpenWeather/openweather.py
PyPortal_Quarantine_Clock/code.py
PyPortal_Quarantine_Clock/month_clock.py
PyPortal_Tides/pp_tides_graphical.py
PyPortal_Tides/pp_tides.py
PyPortal_Tides/admiralty_tides.py
PyPortal_Tides/admiralty_tides_graphical.py
PyPortal_Titano_Weather_Station/code.py
PyPortal_Wakeup_Light/wake_up_light.py
PyPortal_WeeklyCountdown/weeklycountdown.py
PyPortal_on_this_day/code.py
I would think that we should either update all the examples, or
make adafruit_pyportal::get_local_time() return RuntimeError
Metadata
Metadata
Assignees
Labels
No labels