Implement PushButton packet

This commit is contained in:
Christian Loch 2021-08-29 17:13:19 +02:00
parent d18082596c
commit d92af91893

View File

@ -1,5 +1,5 @@
import math
from enum import Enum
class MAXPacketFactory:
def create_packet(rec: str):
@ -16,6 +16,8 @@ class MAXPacketFactory:
return MAXWakeUpPacket(rec)
elif pkt_type == 0xF0:
return MAXResetPacket(rec)
elif pkt_type == 0x50:
return MAXPushButtonPacket(rec)
else:
print("Unknown message type: {}".format(pkt_type))
result = MAXPacket()
@ -116,6 +118,32 @@ class MAXAckPacket(MAXPacket):
return result
class PushButtonState(Enum):
AUTO = 0
ECO = 1
UNKNOWN = 2
class MAXPushButtonPacket(MAXPacket):
def __init__(self, rec: str):
self.from_received(rec)
if rec[26:27] == "0":
self.button_state = PushButtonState.ECO
elif rec[26:27] == "1":
self.button_state = PushButtonState.AUTO
else:
self.button_state = PushButtonState.UNKNOWN
if rec[23:24] == "5":
self.retransmit = 1
else:
self.retransmit = 0
def to_string(self):
result = "{}\nMAXPushButtonPacket: button_state={} retransmit={}".format(super().to_string(),
self.button_state, self.retransmit)
return result
class MAXWakeUpPacket(MAXPacket):
def __init__(self, rec):
super().__init__()