Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.args.append(Int(val, length=2))
#the second parameter is always 0x01
self.args.append(Int(1, length=2))
class PlugwisePrepareScheduleRequest(PlugwiseRequest):
"""Send chunck of On/Off/StandbyKiller Schedule to Stick"""
ID = b'003B'
def __init__(self, idx, schedule_chunk):
# PrepareScedule doesn't send MAC address
PlugwiseRequest.__init__(self, '')
self.args.append(Int(16*idx, length=4))
for i in range(0,8):
self.args.append(SInt(schedule_chunk[i], length=4))
class PlugwiseSendScheduleRequest(PlugwiseRequest):
"""Send chunk of On/Off/StandbyKiller Schedule to Circle(+)"""
ID = b'003C'
def __init__(self, mac, idx):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(idx, length=2))
class PlugwiseSetScheduleValueRequest(PlugwiseRequest):
"""Send chunk of On/Off/StandbyKiller Schedule to Circle(+)"""
ID = b'0059'
def __init__(self, mac, val):
PlugwiseRequest.__init__(self, mac)
self.args.append(SInt(val, length=4))
class PlugwisePingRequest(PlugwiseRequest):
args = b'00000000000000000000'
msg = self.ID+sc(args)+self.mac
checksum = self.calculate_checksum(msg)
full_msg = self.PACKET_HEADER+msg+checksum+self.PACKET_FOOTER
logcomm("SEND %4d ---> %4s %s %16s %4s <---" % (len(full_msg), self.ID, sc(args), self.mac, checksum))
return full_msg
class PlugwiseRemoveNodeRequest(PlugwiseRequest):
"""Send remove node from network request"""
ID = b'001C'
def __init__(self, mac, removemac):
PlugwiseRequest.__init__(self, mac)
self.args.append(String(removemac, length=16))
class PlugwiseResetRequest(PlugwiseRequest):
"""Send preset circle request"""
ID = b'0009'
def __init__(self, mac, moduletype, timeout):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(moduletype, length=2))
self.args.append(Int(timeout, length=2))
class PlugwiseClockSetRequest(PlugwiseRequest):
ID = b'0016'
def __init__(self, mac, dt):
PlugwiseRequest.__init__(self, mac)
passed_days = dt.day - 1
month_minutes = (passed_days*24*60)+(dt.hour*60)+dt.minute
d = DateTime(dt.year, dt.month, month_minutes)
t = Time(dt.hour, dt.minute, dt.second)
day_of_week = Int(dt.weekday() + 1, 2)
# FIXME: use LogAddr instead
log_buf_addr = String('FFFFFFFF', 8)
self.args += [d, log_buf_addr, t, day_of_week]
class PlugwiseSwitchRequest(PlugwiseRequest):
"""switches Plug on or off"""
ID = b'0017'
def __init__(self, mac, on):
PlugwiseRequest.__init__(self, mac)
val = 1 if on == True else 0
self.args.append(Int(val, length=2))
class PlugwiseCalibrationRequest(PlugwiseRequest):
ID = b'0026'
class PlugwisePowerBufferRequest(PlugwiseRequest):
ID = b'0048'
def __init__(self, mac, log_address):
PlugwiseRequest.__init__(self, mac)
class PlugwisePowerBufferRequest(PlugwiseRequest):
ID = b'0048'
def __init__(self, mac, log_address):
PlugwiseRequest.__init__(self, mac)
self.args.append(LogAddr(log_address, 8))
class PlugwiseLogIntervalRequest(PlugwiseRequest):
ID = b'0057'
def __init__(self, mac, usage, production):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(usage, length=4))
self.args.append(Int(production, length=4))
class PlugwiseClearGroupMacRequest(PlugwiseRequest):
ID = b'0058'
def __init__(self, mac, taskId):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(taskId, length=2))
class PlugwiseFeatureSetRequest(PlugwiseRequest):
ID = b'005F'
class PlugwiseDateTimeInfoRequest(PlugwiseRequest):
ID = b'0029'
class PlugwiseSetDateTimeRequest(PlugwiseRequest):
ID = b'0028'
def __init__(self, mac, dt):
def __init__(self, mac, on):
PlugwiseRequest.__init__(self, mac)
val = 1 if on == True else 0
self.args.append(Int(val, length=2))
class PlugwiseCalibrationRequest(PlugwiseRequest):
ID = b'0026'
class PlugwisePowerBufferRequest(PlugwiseRequest):
ID = b'0048'
def __init__(self, mac, log_address):
PlugwiseRequest.__init__(self, mac)
self.args.append(LogAddr(log_address, 8))
class PlugwiseLogIntervalRequest(PlugwiseRequest):
ID = b'0057'
def __init__(self, mac, usage, production):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(usage, length=4))
self.args.append(Int(production, length=4))
class PlugwiseClearGroupMacRequest(PlugwiseRequest):
ID = b'0058'
def __init__(self, mac, taskId):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(taskId, length=2))
class PlugwiseFeatureSetRequest(PlugwiseRequest):
ID = b'005F'
t = Time(dt.hour, dt.minute, dt.second)
day_of_week = Int(dt.weekday() + 1, 2)
# FIXME: use LogAddr instead
log_buf_addr = String('FFFFFFFF', 8)
self.args += [d, log_buf_addr, t, day_of_week]
class PlugwiseSwitchRequest(PlugwiseRequest):
"""switches Plug on or off"""
ID = b'0017'
def __init__(self, mac, on):
PlugwiseRequest.__init__(self, mac)
val = 1 if on == True else 0
self.args.append(Int(val, length=2))
class PlugwiseCalibrationRequest(PlugwiseRequest):
ID = b'0026'
class PlugwisePowerBufferRequest(PlugwiseRequest):
ID = b'0048'
def __init__(self, mac, log_address):
PlugwiseRequest.__init__(self, mac)
self.args.append(LogAddr(log_address, 8))
class PlugwiseLogIntervalRequest(PlugwiseRequest):
ID = b'0057'
def __init__(self, mac, usage, production):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(usage, length=4))
self.args.append(Int(production, length=4))
"""Send chunk of On/Off/StandbyKiller Schedule to Circle(+)"""
ID = b'003C'
def __init__(self, mac, idx):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(idx, length=2))
class PlugwiseSetScheduleValueRequest(PlugwiseRequest):
"""Send chunk of On/Off/StandbyKiller Schedule to Circle(+)"""
ID = b'0059'
def __init__(self, mac, val):
PlugwiseRequest.__init__(self, mac)
self.args.append(SInt(val, length=4))
class PlugwisePingRequest(PlugwiseRequest):
"""Send ping to mac"""
ID = b'000D'
def __init__(self, mac):
PlugwiseRequest.__init__(self, mac)
class PlugwiseAssociatedNodesRequest(PlugwiseRequest):
"""Send populate request"""
ID = b'0018'
def __init__(self, mac, idx):
PlugwiseRequest.__init__(self, mac)
self.args.append(Int(idx, length=2))
class PlugwiseEnableJoiningRequest(PlugwiseRequest):
"""Send a flag which enables or disables joining nodes (cirles) request"""
class PlugwiseRequest(PlugwiseMessage):
def __init__(self, mac):
PlugwiseMessage.__init__(self)
self.args = []
self.mac = sc(mac)
class PlugwiseStatusRequest(PlugwiseRequest):
"""Get Stick Status"""
ID = b'000A'
def __init__(self):
"""message for that initializes the Stick"""
# init doesn't send MAC address
PlugwiseRequest.__init__(self, '')
class PlugwisePowerUsageRequest(PlugwiseRequest):
ID = b'0012'
class PlugwiseInfoRequest(PlugwiseRequest):
ID = b'0023'
class PlugwiseClockInfoRequest(PlugwiseRequest):
ID = b'003E'
class PlugwiseClockSetRequest(PlugwiseRequest):
ID = b'0016'
def __init__(self, mac, dt):
PlugwiseRequest.__init__(self, mac)
passed_days = dt.day - 1
month_minutes = (passed_days*24*60)+(dt.hour*60)+dt.minute
d = DateTime(dt.year, dt.month, month_minutes)
ID = b'0029'
class PlugwiseSetDateTimeRequest(PlugwiseRequest):
ID = b'0028'
def __init__(self, mac, dt):
PlugwiseRequest.__init__(self, mac)
self.args.append(StringVal(dt.second, 2))
self.args.append(StringVal(dt.minute, 2))
self.args.append(StringVal(dt.hour, 2))
self.args.append(StringVal(dt.weekday() + 1, 2))
self.args.append(StringVal(dt.day, 2))
self.args.append(StringVal(dt.month, 2))
self.args.append(StringVal((dt.year-PLUGWISE_EPOCH), 2))
class PlugwiseEnableScheduleRequest(PlugwiseRequest):
"""switches Schedule on or off"""
ID = b'0040'
def __init__(self, mac, on):
PlugwiseRequest.__init__(self, mac)
val = 1 if on == True else 0
self.args.append(Int(val, length=2))
#the second parameter is always 0x01
self.args.append(Int(1, length=2))
class PlugwisePrepareScheduleRequest(PlugwiseRequest):
"""Send chunck of On/Off/StandbyKiller Schedule to Stick"""
ID = b'003B'
def __init__(self, idx, schedule_chunk):
# PrepareScedule doesn't send MAC address