From 5508d488bf698ff46aac6d98d1d91a7ae4b58e6b Mon Sep 17 00:00:00 2001 From: Josh Gadeken Date: Wed, 6 Oct 2021 22:08:39 -0600 Subject: [PATCH 1/2] [#18] Add type annotations --- adafruit_ntp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_ntp.py b/adafruit_ntp.py index 46142cd..199b342 100644 --- a/adafruit_ntp.py +++ b/adafruit_ntp.py @@ -21,6 +21,7 @@ """ import time import rtc +from adafruit_esp32spi.adafruit_esp32spi import ESP_SPIcontrol __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NTP.git" @@ -34,7 +35,7 @@ class NTP: :param bool debug: Set to True to output set_time() failures to console """ - def __init__(self, esp, debug=False): + def __init__(self, esp: ESP_SPIcontrol, debug: bool = False) -> None: # Verify ESP32SPI module if "ESP_SPIcontrol" in str(type(esp)): self._esp = esp @@ -43,7 +44,7 @@ def __init__(self, esp, debug=False): self.valid_time = False self.debug = debug - def set_time(self, tz_offset=0): + def set_time(self, tz_offset: int = 0) -> None: """Fetches and sets the microcontroller's current time in seconds since since Jan 1, 1970. From 434e796813e2193eee67cdaf64bef2d0427903f8 Mon Sep 17 00:00:00 2001 From: Josh Gadeken Date: Thu, 7 Oct 2021 19:45:47 -0600 Subject: [PATCH 2/2] [#18] Wrap ESP_SPIcontrol import in a try-except --- adafruit_ntp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adafruit_ntp.py b/adafruit_ntp.py index 199b342..1f3ac83 100644 --- a/adafruit_ntp.py +++ b/adafruit_ntp.py @@ -21,7 +21,13 @@ """ import time import rtc -from adafruit_esp32spi.adafruit_esp32spi import ESP_SPIcontrol + +try: + # Used only for typing + import typing # pylint: disable=unused-import + from adafruit_esp32spi.adafruit_esp32spi import ESP_SPIcontrol +except ImportError: + pass __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NTP.git"