Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.contents += [self.year, self.month, self.minutes]
def unserialize(self, val):
CompositeType.unserialize(self, val)
minutes = self.minutes.value
hours = minutes // 60
days = hours // 24
hours -= (days*24)
minutes -= (days*24*60)+(hours*60)
try:
self.value = datetime.datetime(self.year.value, self.month.value, days+1, hours, minutes)
except ValueError:
debug('value error while attempting to construct datetime object')
self.value = None
class Time(CompositeType):
"""time value as used in the clock info response"""
def __init__(self, hour=0, minute=0, second=0):
CompositeType.__init__(self)
self.hour = Int(hour, 2)
self.minute = Int(minute, 2)
self.second = Int(second, 2)
self.contents += [self.hour, self.minute, self.second]
def unserialize(self, val):
CompositeType.unserialize(self, val)
self.value = datetime.time(self.hour.value, self.minute.value, self.second.value)
class DateStr(CompositeType):
"""date value as used in the datetime info response"""
def unserialize(self, val):
CompositeType.unserialize(self, val)
minutes = self.minutes.value
hours = minutes // 60
days = hours // 24
hours -= (days*24)
minutes -= (days*24*60)+(hours*60)
try:
self.value = datetime.datetime(self.year.value, self.month.value, days+1, hours, minutes)
except ValueError:
debug('value error while attempting to construct datetime object')
self.value = None
def unserialize(self, val):
Int.unserialize(self, val)
self.value = (self.value - self.LOGADDR_OFFSET) // 32
def __init__(self, mac, idx):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(idx, length=2))
def serialize(self):
fmt = "%%0%dX" % self.length
return sc(fmt % self.value)
def unserialize(self, val):
self.value = int(val, 16)
class UnixTimestamp(Int):
def __init__(self, value, length=8):
Int.__init__(self, value, length=length)
def unserialize(self, val):
Int.unserialize(self, val)
self.value = datetime.datetime.fromtimestamp(self.value)
class Year2k(Int):
"""year value that is offset from the year 2000"""
def unserialize(self, val):
Int.unserialize(self, val)
self.value += PLUGWISE_EPOCH
class DateTime(CompositeType):
"""datetime value as used in the general info response
format is: YYMMmmmm
where year is offset value from the epoch which is Y2K
and last four bytes are offset from the beginning of the month in minutes
"""
def __init__(self, year=0, month=0, minutes=0):
CompositeType.__init__(self)
self.year = Year2k(year-PLUGWISE_EPOCH, 2)
def __init__(self, seqnr = None):
PlugwiseResponse.__init__(self, seqnr)
self.exsisting = Int(0, 2)
self.allowed = Int(0, 2)
self.params += [self.exsisting, self.allowed]
def __init__(self, seqnr = None):
PlugwiseResponse.__init__(self, seqnr)
self.pulse_1s = SInt(0, 4)
self.pulse_8s = SInt(0, 4)
self.pulse_hour = Int(0, 8)
self.pulse_prod_hour = SInt(0, 8)
self.unknown2 = Int(0, 4)
self.params += [self.pulse_1s, self.pulse_8s, self.pulse_hour, self.pulse_prod_hour, self.unknown2]
def __init__(self, seqnr = None):
PlugwiseResponse.__init__(self, seqnr)
self.time = TimeStr()
self.day_of_week = Int(0, 2)
self.date = DateStr()
self.params += [self.time, self.day_of_week, self.date]
def __init__(self, mac, moduletype, timeout):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(moduletype, length=2))
self.args.append(Int(timeout, length=2))
def __init__(self, seqnr = None):
PlugwiseResponse.__init__(self, seqnr)
self.features = Int(0, 16)
self.params += [self.features]