Skip to content

made printing to console optional when set_time() fails. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions adafruit_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ class NTP:
This module does not handle daylight savings or local time.

:param adafruit_esp32spi esp: ESP32SPI object.
:param bool debug: Set to True to output set_time() failures to console
"""

def __init__(self, esp):
def __init__(self, esp, debug=False):
# Verify ESP32SPI module
if "ESP_SPIcontrol" in str(type(esp)):
self._esp = esp
else:
raise TypeError("Provided object is not an ESP_SPIcontrol object.")
self.valid_time = False
self.debug = debug

def set_time(self, tz_offset=0):
"""Fetches and sets the microcontroller's current time
Expand All @@ -73,5 +75,6 @@ def set_time(self, tz_offset=0):
rtc.RTC().datetime = now
self.valid_time = True
except ValueError as error:
print(str(error))
if self.debug:
print(str(error))
return