Skip to content

Commit

Permalink
Merge pull request #14 from apatt/master
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed May 15, 2018
2 parents 2be5606 + 79a817d commit e64be79
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions adafruit_register/i2c_bcd_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,19 @@ def __get__(self, obj, objtype=None):
return (time.struct_time((2017, 1, mday, hour, minute, seconds, wday, mday, -1)), frequency)

def __set__(self, obj, value):
if len(value) != 2:
raise ValueError("Value must be sequence of length two")
# Turn all components off by default.
for i in range(len(self.buffer) - 1):
self.buffer[i + 1] = ALARM_COMPONENT_DISABLED

frequency = FREQUENCY.index(value[1])
frequency_name = value[1]
error_message = "%s is not a supported frequency" % frequency_name
if frequency_name not in FREQUENCY:
raise ValueError(error_message)

frequency = FREQUENCY.index(frequency_name)
if frequency <= 1 and not self.has_seconds:
raise ValueError(error_message)

# i is the index of the minute byte
i = 2 if self.has_seconds else 1
Expand Down

0 comments on commit e64be79

Please sign in to comment.