Skip to content

Commit

Permalink
fix calculated_length
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin GROSS committed Dec 2, 2023
1 parent 412159b commit 3368877
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions test/telegram_tests/apci_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_calculated_length(self):
payload = MemoryExtendedWrite(
address=0x123456, count=3, data=bytes([0xAA, 0xBB, 0xCC])
)
assert payload.calculated_length() == 9
assert payload.calculated_length() == 8

def test_from_knx(self):
"""Test the from_knx method."""
Expand Down Expand Up @@ -366,14 +366,14 @@ class TestMemoryExtendedWriteResponse:
def test_calculated_length(self):
"""Test the test_calculated_length method."""
payload = MemoryExtendedWriteResponse(return_code=0, address=0x123456)
assert payload.calculated_length() == 6
assert payload.calculated_length() == 5

def test_calculated_lengt_with_confirmation_data(self):
"""Test the test_calculated_length method."""
payload = MemoryExtendedWriteResponse(
return_code=0, address=0x123456, confirmation_data=bytes([0xAA, 0xBB])
)
assert payload.calculated_length() == 8
assert payload.calculated_length() == 7

def test_from_knx(self):
"""Test the from_knx method."""
Expand Down Expand Up @@ -446,7 +446,7 @@ class TestMemoryExtendedRead:
def test_calculated_length(self):
"""Test the test_calculated_length method."""
payload = MemoryExtendedRead(address=0x123456, count=3)
assert payload.calculated_length() == 6
assert payload.calculated_length() == 5

def test_from_knx(self):
"""Test the from_knx method."""
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_calculated_length(self):
payload = MemoryExtendedReadResponse(
return_code=0, address=0x123456, data=bytes([0xAA, 0xBB, 0xCC])
)
assert payload.calculated_length() == 9
assert payload.calculated_length() == 8

def test_from_knx(self):
"""Test the from_knx method."""
Expand Down
10 changes: 5 additions & 5 deletions xknx/telegram/apci.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@ def __init__(self, address: int, data: bytes, count: int | None = None) -> None:

def calculated_length(self) -> int:
"""Get length of APCI payload."""
return 6 + len(self.data)
return 5 + len(self.data)

@classmethod
def from_knx(cls, raw: bytes) -> MemoryExtendedWrite:
"""Parse/deserialize from KNX/IP raw data."""
size = len(raw) - 6
size = len(raw) - 5

# inject [0x00] before 3 bytes address to enable unsigned int unpack
count, address, data = struct.unpack(
Expand Down Expand Up @@ -579,7 +579,7 @@ def __init__(

def calculated_length(self) -> int:
"""Get length of APCI payload."""
return 6 + len(self.confirmation_data)
return 5 + len(self.confirmation_data)

@classmethod
def from_knx(cls, raw: bytes) -> MemoryExtendedWriteResponse:
Expand Down Expand Up @@ -633,7 +633,7 @@ def __init__(self, count: int, address: int) -> None:

def calculated_length(self) -> int:
"""Get length of APCI payload."""
return 6
return 5

@classmethod
def from_knx(cls, raw: bytes) -> MemoryExtendedRead:
Expand Down Expand Up @@ -682,7 +682,7 @@ def __init__(self, return_code: int, address: int, data: bytes = b"") -> None:

def calculated_length(self) -> int:
"""Get length of APCI payload."""
return 6 + len(self.data)
return 5 + len(self.data)

@classmethod
def from_knx(cls, raw: bytes) -> MemoryExtendedReadResponse:
Expand Down

0 comments on commit 3368877

Please sign in to comment.