From ae7058b91f9e1c3523ba3c0ca3a6db213763f64b Mon Sep 17 00:00:00 2001 From: RealByron <1749192+RealByron@users.noreply.github.com> Date: Sun, 3 Dec 2023 09:53:02 +0100 Subject: [PATCH] cleaner decoding 2 --- xknx/telegram/apci.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xknx/telegram/apci.py b/xknx/telegram/apci.py index 47d70e2b3..35d08e9d1 100644 --- a/xknx/telegram/apci.py +++ b/xknx/telegram/apci.py @@ -638,8 +638,9 @@ def calculated_length(self) -> int: @classmethod def from_knx(cls, raw: bytes) -> MemoryExtendedRead: """Parse/deserialize from KNX/IP raw data.""" - # inject [0x00] before 3 bytes address to enable unsigned int unpack - count, address = struct.unpack("!BI", bytes([raw[2], 0x00]) + raw[3:]) + count = raw[2] + address = int.from_bytes(raw[3:6], "big") + return cls( count=count, address=address, @@ -689,10 +690,10 @@ def from_knx(cls, raw: bytes) -> MemoryExtendedReadResponse: """Parse/deserialize from KNX/IP raw data.""" size = len(raw) - 6 - # inject [0x00] before 3 bytes address to enable unsigned int unpack - return_code, address, data = struct.unpack( - f"!BI{size}s", bytes([raw[2], 0x00]) + raw[3:] - ) + return_code = raw[2] + address = int.from_bytes(raw[3:6], "big") + data = raw[6:] + return cls( return_code=return_code, address=address,