Skip to content

Commit

Permalink
Patch Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lunDreame authored Jan 3, 2025
1 parent bf71e6b commit 35df60f
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions custom_components/kocom_wallpad/pywallpad/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def parse_data(self) -> list[Device]:
)
)

if floor_state > 0 or self._last_data[self.device_id][FLOOR]:
if (isinstance(floor_state, int) and (floor_state > 0)) or self._last_data[self.device_id][FLOOR]:
_LOGGER.debug(f"Support EV floor: {floor_state}")
self._last_data[self.device_id][FLOOR] = True

Expand All @@ -667,27 +667,12 @@ def make_power_status(self, power: bool) -> bytearray:
return super().make_packet(Command.ON, bytearray(self.value))


class WallpadPacket(KocomPacket):
"""Handles packets for wallpad devices."""

def parse_class(self) -> KocomPacket:
"""Parse the class of the packet."""
if self.dest[0] == DeviceType.EV.value:
self.dest = self.src
self.src = self.dest
_LOGGER.debug(f"EV device detected on wallpad.")
return EVPacket(self.packet)
else:
_LOGGER.debug(f"Main device detected on wallpad.")
return KocomPacket(self.packet)


class PacketParser:
"""Parses raw Kocom packets into specific device classes."""

@staticmethod
def parse(packet_data: bytes) -> KocomPacket:
"""Parse a raw packet into a specific packet class."""
"""Parse a raw packet into a specific packet class."""
device_type = packet_data[7]
return PacketParser._get_packet_instance(device_type, packet_data)

Expand Down Expand Up @@ -728,15 +713,19 @@ def _get_packet_instance(device_type: int, packet_data: bytes) -> KocomPacket:
DeviceType.GAS.value: GasPacket,
DeviceType.MOTION.value: MotionPacket,
DeviceType.EV.value: EVPacket,
DeviceType.WALLPAD.value: WallpadPacket,
DeviceType.WALLPAD.value: KocomPacket,
}

packet_class = device_class_map.get(device_type)
if packet_class is None:
_LOGGER.error("Unknown device type: %s, data: %s", format(device_type, 'x'), packet_data.hex())
_LOGGER.error(f"Unknown device type: {hex(device_type)}, data: {packet_data.hex()}")
return KocomPacket(packet_data)

if packet_class == WallpadPacket:
return packet_class(packet_data).parse_class()
if packet_data[5] == DeviceType.EV.value and packet_class == KocomPacket:
packet_data = bytearray(packet_data)
packet_data[5] = 0x01
packet_data[7] = 0x44
_LOGGER.debug(f"EV device detected from wallpad: {packet_data.hex()}")
return EVPacket(bytes(packet_data))

return packet_class(packet_data)

0 comments on commit 35df60f

Please sign in to comment.