From 6eb1f74f83e22e8c3fa6b8663999969bf14914f6 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 15 Feb 2019 23:56:08 -0800 Subject: [PATCH 01/10] Initial Library Work --- adafruit_featherwing/rtc_featherwing.py | 240 ++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100755 adafruit_featherwing/rtc_featherwing.py diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py new file mode 100755 index 0000000..cd7e624 --- /dev/null +++ b/adafruit_featherwing/rtc_featherwing.py @@ -0,0 +1,240 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_featherwing.rtc_featherwing` +==================================================== + +Helper for using the `DS3231 Precision RTC FeatherWing +`_. + +* Author(s): Melissa LeBlanc-Williams +""" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" + +import time +from collections import namedtuple +from adafruit_featherwing import shared +import adafruit_ds3231 + +""" +Other things +Make it 12/24 hour format settable +Have the return values format appropriately +Maybe set based on format +Add all the parameters for RTD +Add some examples for the functions +""" + +class RTCFeatherWing: + """Class representing an `DS3231 Precision RTC FeatherWing + `_. + + Automatically uses the feather's I2C bus.""" + def __init__(self): + self._rtc = adafruit_ds3231.DS3231(shared.I2C_BUS) + + def __setitem__(self, index, value): + """ + Allow updates using setitem if that makes it easier + """ + self._set_time_value(self, index, value) + + def __getitem__(self, index): + """ + Allow retrievals using getitem if that makes it easier + """ + return self._get_time_value(self, index) + + def _set_time_value(self, unit, value): + """ + Set just the specific unit of time + """ + date = self._get_now() + if unit in date: + date[unit] = value + else: + raise ValueError('The specified unit of time is invalid') + + self._rtc.datetime = self._encode(date) + + def _get_time_value(self, unit): + """ + Get just the specific unit of time + """ + time = self._get_now() + if unit in time: + return time[unit] + else: + raise ValueError('The specified unit of time is invalid') + + def _get_now(self): + """ + Return the current date and time in a nice updatable dictionary + """ + now = self._rtc.datetime + MyStruct = namedtuple("MyStruct", "field1 field2 field3") + return {'second': now.tm_sec, 'minute': now.tm_min, 'hour': now.tm_hour, 'day': now.tm_mday, + 'month': now.tm_mon, 'year': now.tm_year, 'weekday': now.tm_wday} + + def _encode(self, date): + """ + Encode the updatable dictionary back into a time struct + """ + now = self._rtc.datetime + return time.struct_time((date['year'], date['month'], date['day'], date['hour'], + date['minute'], date['second'], date['weekday'], now.tm_yday, + now.tm_isdst)) + +#REMOVE ME 20 40 60 80 100 + def set_time(self, hour, minute, second): + """ + Set the time only + + :param int hour: The hour we want to set the time to + :param int minute: The minute we want to set the time to + :param int second: The second we want to set the time to + """ + now = self._get_now() + now['hour'] = hour + now['minute'] = minute + now['second'] = second + self._rtc.datetime = self._encode(now) + + def set_date(self, day, month, year): + """ + Set the date only + + :param int day: The day we want to set the date to + :param int month: The month we want to set the date to + :param int year: The year we want to set the date to + """ + now = self._get_now() + now['day'] = day + now['month'] = month + now['year'] = year + self._rtc.datetime = self._encode(now) + + @property + def datetime(self): + """ + Passthru property to the ds3231 library for compatibility + """ + return self._rtc.datetime + + @datetime.setter + def datetime(self, datetime): + self._rtc.datetime = datetime + + @property + def year(self): + """ + The Current Year + """ + return self._get_time_value('year') + + @year.setter + def year(self, year): + self._set_time_value('year', year) + + @property + def month(self): + """ + The Current Month + """ + return self._get_time_value('month') + + @month.setter + def month(self, month): + self._set_time_value('month', month) + + @property + def day(self): + """ + The Current Day + """ + return self._get_time_value('day') + + @day.setter + def day(self, day): + self._set_time_value('day', day) + + @property + def hour(self): + """ + The Current Hour + """ + return self._get_time_value('hour') + + @hour.setter + def hour(self, hour): + self._set_time_value('hour', hour) + + @property + def minute(self): + """ + The Current Minute + """ + return self._get_time_value('minute') + + @minute.setter + def minute(self, minute): + self._set_time_value('minute', minute) + + @property + def second(self): + """ + The Current Second + """ + return self._get_time_value('second') + + @second.setter + def second(self, second): + self._set_time_value('second', second) + + @property + def weekday(self): + """ + The Current Day of the Week Value (0-6) where Sunday is 0 + """ + return self._get_time_value('weekday') + + @weekday.setter + def weekday(self, weekday): + self._set_time_value('weekday', weekday) + + @property + def weekday_name(self): + """ + The Name for the Current Day of the Week (Read Only) + """ + days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") + return days[self._get_time_value('weekday')] + + @property + def now(self): + """ + The Current Date and Time in Named Tuple Style + """ + DateTime = namedtuple("DateTime", "second minute hour day month year weekday") + return DateTime(**self._get_now()) From eb32577aad6153fefb5d54a08ccce7c7cd0472ca Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 16 Feb 2019 00:06:49 -0800 Subject: [PATCH 02/10] Linting --- adafruit_featherwing/rtc_featherwing.py | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index cd7e624..3a73d0c 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -37,15 +37,6 @@ from adafruit_featherwing import shared import adafruit_ds3231 -""" -Other things -Make it 12/24 hour format settable -Have the return values format appropriately -Maybe set based on format -Add all the parameters for RTD -Add some examples for the functions -""" - class RTCFeatherWing: """Class representing an `DS3231 Precision RTC FeatherWing `_. @@ -58,33 +49,33 @@ def __setitem__(self, index, value): """ Allow updates using setitem if that makes it easier """ - self._set_time_value(self, index, value) + self._set_time_value(index, value) def __getitem__(self, index): """ Allow retrievals using getitem if that makes it easier """ - return self._get_time_value(self, index) + return self._get_time_value(index) def _set_time_value(self, unit, value): """ Set just the specific unit of time """ - date = self._get_now() - if unit in date: - date[unit] = value + now = self._get_now() + if unit in now: + now[unit] = value else: raise ValueError('The specified unit of time is invalid') - self._rtc.datetime = self._encode(date) + self._rtc.datetime = self._encode(now) def _get_time_value(self, unit): """ Get just the specific unit of time """ - time = self._get_now() - if unit in time: - return time[unit] + now = self._get_now() + if unit in now: + return now[unit] else: raise ValueError('The specified unit of time is invalid') @@ -93,7 +84,6 @@ def _get_now(self): Return the current date and time in a nice updatable dictionary """ now = self._rtc.datetime - MyStruct = namedtuple("MyStruct", "field1 field2 field3") return {'second': now.tm_sec, 'minute': now.tm_min, 'hour': now.tm_hour, 'day': now.tm_mday, 'month': now.tm_mon, 'year': now.tm_year, 'weekday': now.tm_wday} @@ -106,7 +96,6 @@ def _encode(self, date): date['minute'], date['second'], date['weekday'], now.tm_yday, now.tm_isdst)) -#REMOVE ME 20 40 60 80 100 def set_time(self, hour, minute, second): """ Set the time only @@ -236,5 +225,5 @@ def now(self): """ The Current Date and Time in Named Tuple Style """ - DateTime = namedtuple("DateTime", "second minute hour day month year weekday") - return DateTime(**self._get_now()) + date_time = namedtuple("DateTime", "second minute hour day month year weekday") + return date_time(**self._get_now()) From 74e2ee88eb5026d6fe49ad2680be41e75cb2ba33 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 16 Feb 2019 18:44:17 -0800 Subject: [PATCH 03/10] Finished RTC FeatherWing library --- README.rst | 1 + adafruit_featherwing/rtc_featherwing.py | 102 ++++++++++++++++++++---- docs/api.rst | 3 + docs/conf.py | 2 +- docs/examples.rst | 6 +- examples/featherwing_rtc_simpletest.py | 39 +++++++++ requirements.txt | 2 +- setup.py | 3 +- 8 files changed, 137 insertions(+), 21 deletions(-) create mode 100755 examples/featherwing_rtc_simpletest.py diff --git a/README.rst b/README.rst index d4f919c..74f7bac 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,7 @@ These drivers depends on: * `HT16K33 `_ * `DotStar `_ * `NeoPixel `_ +* `DS3231 `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index 3a73d0c..ef9367c 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -96,14 +96,46 @@ def _encode(self, date): date['minute'], date['second'], date['weekday'], now.tm_yday, now.tm_isdst)) - def set_time(self, hour, minute, second): + def is_leap_year(self, year=None): + """ + Check if the year is a leap year + + :param int year: (Optional) The year to check. If none is provided, current year is used. + """ + if year is None: + year = self._get_time_value('year') + return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) + + def get_month_days(self, month=None, year=None): + """ + Return the number of days for the month of the given year + + :param int month: (Optional) The month to use. If none is provided, current month is used. + :param int year: (Optional) The year to check. If none is provided, current year is used. + """ + if month is None: + month = self._get_time_value('month') + leap_year = self.is_leap_year(year) + max_days = (31, 29 if leap_year else 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) + return max_days[month - 1] + + def set_time(self, hour, minute, second = 0): """ Set the time only :param int hour: The hour we want to set the time to :param int minute: The minute we want to set the time to - :param int second: The second we want to set the time to + :param int second: (Optional) The second we want to set the time to (default=0) """ + if not isinstance(second, int) or not 0 <= second < 60: + raise ValueError('The second must be an integer in the range of 0-59') + + if not isinstance(minute, int) or not 0 <= minute < 60: + raise ValueError('The minute must be an integer in the range of 0-59') + + if not isinstance(hour, int) or not 0 <= hour < 24: + raise ValueError('The hour must be an integer in the range of 0-23') + now = self._get_now() now['hour'] = hour now['minute'] = minute @@ -118,6 +150,16 @@ def set_date(self, day, month, year): :param int month: The month we want to set the date to :param int year: The year we want to set the date to """ + if not isinstance(year, int): + raise ValueError('The year must be an integer') + + if not isinstance(month, int) or not 1 <= month <= 12: + raise ValueError('The month must be an integer in the range of 1-12') + + month_days = self.get_month_days(month, year) + if not isinstance(day, int) or not 1 <= day <= month_days: + raise ValueError('The day must be an integer in the range of 1-{}'.format(month_days)) + now = self._get_now() now['day'] = day now['month'] = month @@ -144,7 +186,10 @@ def year(self): @year.setter def year(self, year): - self._set_time_value('year', year) + if isinstance(year, int): + self._set_time_value('year', year) + else: + raise ValueError('The year must be an integer') @property def month(self): @@ -155,7 +200,10 @@ def month(self): @month.setter def month(self, month): - self._set_time_value('month', month) + if isinstance(month, int) and 1 <= month <= 12: + self._set_time_value('month', month) + else: + raise ValueError('The month must be an integer in the range of 1-12') @property def day(self): @@ -166,7 +214,11 @@ def day(self): @day.setter def day(self, day): - self._set_time_value('day', day) + month_days = self.get_month_days() + if isinstance(day, int) and 1 <= day <= month_days: + self._set_time_value('day', day) + else: + raise ValueError('The day must be an integer in the range of 1-{}'.format(month_days)) @property def hour(self): @@ -177,7 +229,10 @@ def hour(self): @hour.setter def hour(self, hour): - self._set_time_value('hour', hour) + if isinstance(hour, int) and 0 <= hour < 24: + self._set_time_value('hour', hour) + else: + raise ValueError('The hour must be an integer in the range of 0-23') @property def minute(self): @@ -188,7 +243,10 @@ def minute(self): @minute.setter def minute(self, minute): - self._set_time_value('minute', minute) + if isinstance(minute, int) and 0 <= minute < 60: + self._set_time_value('minute', minute) + else: + raise ValueError('The minute must be an integer in the range of 0-59') @property def second(self): @@ -199,7 +257,10 @@ def second(self): @second.setter def second(self, second): - self._set_time_value('second', second) + if isinstance(second, int) and 0 <= second < 60: + self._set_time_value('second', second) + else: + raise ValueError('The second must be an integer in the range of 0-59') @property def weekday(self): @@ -210,20 +271,27 @@ def weekday(self): @weekday.setter def weekday(self, weekday): - self._set_time_value('weekday', weekday) + if isinstance(weekday, int) and 0 <= weekday < 7: + self._set_time_value('weekday', weekday) + else: + raise ValueError('The weekday must be an integer in the range of 0-6') @property - def weekday_name(self): + def now(self): """ - The Name for the Current Day of the Week (Read Only) + The Current Date and Time in Named Tuple Style (Read Only) """ - days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") - return days[self._get_time_value('weekday')] + date_time = namedtuple("DateTime", "second minute hour day month year weekday") + return date_time(**self._get_now()) @property - def now(self): + def unixtime(self): """ - The Current Date and Time in Named Tuple Style + The Current Date and Time in Unix Time """ - date_time = namedtuple("DateTime", "second minute hour day month year weekday") - return date_time(**self._get_now()) + return time.mktime(self._rtc.datetime) + + @unixtime.setter + def unixtime(self, unixtime): + if isinstance(unixtime, int): + self._rtc.datetime = time.localtime(unixtime) diff --git a/docs/api.rst b/docs/api.rst index 1c1e449..6e46a33 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -15,3 +15,6 @@ .. automodule:: adafruit_featherwing.neopixel_featherwing :members: + +.. automodule:: adafruit_featherwing.rtc_featherwing + :members: diff --git a/docs/conf.py b/docs/conf.py index 77a90fa..20b5b08 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -35,7 +35,7 @@ master_doc = 'index' # General information about the project. -project = u'Adafruit featherwing Library' +project = u'Adafruit FeatherWing Library' copyright = u'2017 Scott Shawcroft' author = u'Scott Shawcroft' diff --git a/docs/examples.rst b/docs/examples.rst index 65a2bc9..3237c13 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -27,7 +27,11 @@ Ensure your device works with this simple test. :caption: examples/featherwing_sevensegment_simpletest.py :linenos: -Other tests +.. literalinclude:: ../examples/featherwing_rtc_simpletest.py + :caption: examples/featherwing_rtc_simpletest.py + :linenos: + +Other Tests ------------ .. literalinclude:: ../examples/featherwing_dotstar_palette_example.py diff --git a/examples/featherwing_rtc_simpletest.py b/examples/featherwing_rtc_simpletest.py new file mode 100755 index 0000000..563fdda --- /dev/null +++ b/examples/featherwing_rtc_simpletest.py @@ -0,0 +1,39 @@ +""" +This example will allow you to set the date and time +and then loop through and display the current time +""" +import time +from adafruit_featherwing import rtc_featherwing + +days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") + +# Create the RTC instance: +rtc = rtc_featherwing.RTCFeatherWing() + +if True: # Change this to True to set the date and time + rtc.set_time(13, 34) # Set the time (seconds are optional) + print(rtc.now) + rtc.set_date(16, 1, 2016) # Set the date + print(rtc.now) + rtc.year = 2019 # Set just the Year + print(rtc.now) + rtc.month = 2 # Set Just the Month + print(rtc.now) + rtc.hour = 16 # Set just the hour + print(rtc.now) + rtc.weekday = 6 # Set just the day of the week (Sunday = 0) + print(rtc.now) + rtc.unixtime = 1550335257 # Or set the date and time with a unix timestamp + +# Main loop: +while True: + now = rtc.now + print("The date is {} {}/{}/{}".format(days[now.weekday], now.day, now.month, now.year)) + print("The time is {}:{:02}:{:02}".format(now.hour, now.minute, now.second)) + print("The UNIX timestamp is {}".format(rtc.unixtime)) + print("The number of days in the current month is {}".format(rtc.get_month_days())) + if rtc.is_leap_year(): + print("This year is a leap year") + else: + print("This year is not a leap year") + time.sleep(1) # wait a second diff --git a/requirements.txt b/requirements.txt index 32c8ec6..2ec7b8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ adafruit-circuitpython-seesaw adafruit-circuitpython-ht16k33 adafruit-circuitpython-dotstar adafruit-circuitpython-neopixel - +adafruit-circuitpython-ds3231 diff --git a/setup.py b/setup.py index 90b67ee..7a8fd3c 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,8 @@ install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice', 'adafruit-circuitpython-register', 'adafruit-circuitpython-ina219', 'adafruit-circuitpython-seesaw', 'adafruit-circuitpython-ht16k33', - 'adafruit-circuitpython-dotstar', 'adafruit-circuitpython-neopixel'], + 'adafruit-circuitpython-dotstar', 'adafruit-circuitpython-neopixel', + 'adafruit-circuitpython-ds3231'], # Choose your license license='MIT', From f81dca22cd0b40b9852421e8cf9885bf542006fc Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 16 Feb 2019 18:47:49 -0800 Subject: [PATCH 04/10] Linting --- adafruit_featherwing/rtc_featherwing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index ef9367c..8b39bbc 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -34,8 +34,8 @@ import time from collections import namedtuple -from adafruit_featherwing import shared import adafruit_ds3231 +from adafruit_featherwing import shared class RTCFeatherWing: """Class representing an `DS3231 Precision RTC FeatherWing @@ -119,7 +119,7 @@ def get_month_days(self, month=None, year=None): max_days = (31, 29 if leap_year else 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) return max_days[month - 1] - def set_time(self, hour, minute, second = 0): + def set_time(self, hour, minute, second=0): """ Set the time only From ac7b6846b7a84790aacbf171961630305221e1ac Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 16 Feb 2019 18:54:30 -0800 Subject: [PATCH 05/10] Final Linting --- examples/featherwing_rtc_simpletest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/featherwing_rtc_simpletest.py b/examples/featherwing_rtc_simpletest.py index 563fdda..19044eb 100755 --- a/examples/featherwing_rtc_simpletest.py +++ b/examples/featherwing_rtc_simpletest.py @@ -10,6 +10,7 @@ # Create the RTC instance: rtc = rtc_featherwing.RTCFeatherWing() +#pylint: disable-msg=using-constant-test if True: # Change this to True to set the date and time rtc.set_time(13, 34) # Set the time (seconds are optional) print(rtc.now) From c75df9fb6f1f77119dc6c63ea3c71146dc00b2be Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 17 Feb 2019 10:03:23 -0800 Subject: [PATCH 06/10] Added error checking to unixtime --- adafruit_featherwing/rtc_featherwing.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index 8b39bbc..5528816 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -289,9 +289,15 @@ def unixtime(self): """ The Current Date and Time in Unix Time """ - return time.mktime(self._rtc.datetime) + try: + return time.mktime(self._rtc.datetime) + except (ValueError, RuntimeError) as error: + print("There was an error attempting to run time.mktime() on this board") @unixtime.setter def unixtime(self, unixtime): if isinstance(unixtime, int): - self._rtc.datetime = time.localtime(unixtime) + try: + self._rtc.datetime = time.localtime(unixtime) + except (ValueError, RuntimeError) as error: + print("There was an error attempting to run time.localtime() on this board") From 7b2c456e0badd99f4702f223def5614e86539f42 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 17 Feb 2019 10:08:08 -0800 Subject: [PATCH 07/10] Fied error messages --- adafruit_featherwing/rtc_featherwing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index 5528816..771952a 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -292,7 +292,11 @@ def unixtime(self): try: return time.mktime(self._rtc.datetime) except (ValueError, RuntimeError) as error: +<<<<<<< Updated upstream print("There was an error attempting to run time.mktime() on this board") +======= + print("Error attempting to run time.mktime() on this board\n", error) +>>>>>>> Stashed changes @unixtime.setter def unixtime(self, unixtime): @@ -300,4 +304,8 @@ def unixtime(self, unixtime): try: self._rtc.datetime = time.localtime(unixtime) except (ValueError, RuntimeError) as error: +<<<<<<< Updated upstream print("There was an error attempting to run time.localtime() on this board") +======= + print("Error attempting to run time.localtime() on this board\n", error) +>>>>>>> Stashed changes From 6f344166aa2fafb3ba91e5049e77e94b342009cc Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 17 Feb 2019 10:14:47 -0800 Subject: [PATCH 08/10] Removed weird space-looking character --- adafruit_featherwing/rtc_featherwing.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index 771952a..7dfd7f8 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -292,11 +292,7 @@ def unixtime(self): try: return time.mktime(self._rtc.datetime) except (ValueError, RuntimeError) as error: -<<<<<<< Updated upstream - print("There was an error attempting to run time.mktime() on this board") -======= print("Error attempting to run time.mktime() on this board\n", error) ->>>>>>> Stashed changes @unixtime.setter def unixtime(self, unixtime): @@ -304,8 +300,4 @@ def unixtime(self, unixtime): try: self._rtc.datetime = time.localtime(unixtime) except (ValueError, RuntimeError) as error: -<<<<<<< Updated upstream - print("There was an error attempting to run time.localtime() on this board") -======= print("Error attempting to run time.localtime() on this board\n", error) ->>>>>>> Stashed changes From a0a11682993c026f5b4c6307b64533f695816b62 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 17 Feb 2019 10:41:11 -0800 Subject: [PATCH 09/10] Fixed the error type to check --- adafruit_featherwing/rtc_featherwing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index 7dfd7f8..d6d1f95 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -34,8 +34,8 @@ import time from collections import namedtuple -import adafruit_ds3231 from adafruit_featherwing import shared +import adafruit_ds3231 class RTCFeatherWing: """Class representing an `DS3231 Precision RTC FeatherWing @@ -291,7 +291,7 @@ def unixtime(self): """ try: return time.mktime(self._rtc.datetime) - except (ValueError, RuntimeError) as error: + except (AttributeError, RuntimeError) as error: print("Error attempting to run time.mktime() on this board\n", error) @unixtime.setter @@ -299,5 +299,5 @@ def unixtime(self, unixtime): if isinstance(unixtime, int): try: self._rtc.datetime = time.localtime(unixtime) - except (ValueError, RuntimeError) as error: + except (AttributeError, RuntimeError) as error: print("Error attempting to run time.localtime() on this board\n", error) From b4de44a409bda6880fcde490eb226d266eb6522a Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 17 Feb 2019 10:43:38 -0800 Subject: [PATCH 10/10] Linting --- adafruit_featherwing/rtc_featherwing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index d6d1f95..246263a 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -34,8 +34,8 @@ import time from collections import namedtuple -from adafruit_featherwing import shared import adafruit_ds3231 +from adafruit_featherwing import shared class RTCFeatherWing: """Class representing an `DS3231 Precision RTC FeatherWing