Skip to content

Commit

Permalink
cleaner decoding 2
Browse files Browse the repository at this point in the history
  • Loading branch information
RealByron committed Dec 3, 2023
1 parent d2781e0 commit ae7058b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions xknx/telegram/apci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ae7058b

Please sign in to comment.