Skip to content

Commit

Permalink
cleaner decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
RealByron committed Dec 2, 2023
1 parent 7a42f20 commit d2781e0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions xknx/telegram/apci.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ def from_knx(cls, raw: bytes) -> MemoryExtendedWrite:
"""Parse/deserialize from KNX/IP raw data."""
size = len(raw) - 6

# inject [0x00] before 3 bytes address to enable unsigned int unpack
count, address, data = struct.unpack(
f"!BI{size}s", bytes([raw[2], 0x00]) + raw[3:]
)
count = raw[2]
address = int.from_bytes(raw[3:6], "big")
data = raw[6:]

return cls(
count=count,
address=address,
Expand Down Expand Up @@ -586,10 +586,10 @@ def from_knx(cls, raw: bytes) -> MemoryExtendedWriteResponse:
"""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, confirmation_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")
confirmation_data = raw[6:]

return cls(
return_code=return_code,
address=address,
Expand Down

0 comments on commit d2781e0

Please sign in to comment.