Skip to content

Commit 082f62b

Browse files
mrmcwethytannewt
authored andcommitted
allow time.struct_time as the __set__ value
Updated BCDDateTimeRegister to allow time.struct_time as the __set__ value. This change makes this class and the alarm class consistent.
1 parent 122609f commit 082f62b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

adafruit_register/i2c_bcd_datetime.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class BCDDateTimeRegister:
4747
4848
\* Setting weekday_first=False will flip the weekday/day order so that day comes first.
4949
50-
Values are `DateTimeTuple`
50+
Values are `time.struct_time`
5151
5252
:param int register_address: The register address to start the read
5353
:param bool weekday_first: True if weekday is in a lower register than the day of the month (1-31)
@@ -78,12 +78,12 @@ def __get__(self, obj, objtype=None):
7878
-1))
7979

8080
def __set__(self, obj, value):
81-
self.buffer[1] = _bin2bcd(value.second) & 0x7F # format conversions
82-
self.buffer[2] = _bin2bcd(value.minute)
83-
self.buffer[3] = _bin2bcd(value.hour)
84-
self.buffer[4 + self.weekday_offset] = _bin2bcd(value.weekday + self.weekday_start)
85-
self.buffer[5 - self.weekday_offset] = _bin2bcd(value.day)
86-
self.buffer[6] = _bin2bcd(value.month)
87-
self.buffer[7] = _bin2bcd(value.year - 2000)
81+
self.buffer[1] = _bin2bcd(value.tm_sec) & 0x7F # format conversions
82+
self.buffer[2] = _bin2bcd(value.tm_min)
83+
self.buffer[3] = _bin2bcd(value.tm_hour)
84+
self.buffer[4 + self.weekday_offset] = _bin2bcd(value.tm_wday + self.weekday_start)
85+
self.buffer[5 - self.weekday_offset] = _bin2bcd(value.tm_mday)
86+
self.buffer[6] = _bin2bcd(value.tm_mon)
87+
self.buffer[7] = _bin2bcd(value.tm_year - 2000)
8888
with obj.i2c_device:
8989
obj.i2c_device.write(self.buffer)

0 commit comments

Comments
 (0)