Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcp: Allow serial number to mismatch in reply #197

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions omnikinverter/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ def parse_messages(serial_number: int, data: bytes) -> dict[str, Any]:
for (message_type, reply_serial_number, message) in _unpack_messages(
bytearray(data)
):
if reply_serial_number != serial_number:
raise OmnikInverterPacketInvalidError(
f"Replied serial number {reply_serial_number} "
f"not equal to request {serial_number}"
if reply_serial_number != serial_number: # pragma: no cover
# This is allowed as it does not seem to be required to pass the serial
# number in the request - though empirical testing has to point out whether
# the request takes longer this way.
LOGGER.debug(
"Replied serial number %s not equal to request %s",
reply_serial_number,
serial_number,
)

if message_type == MESSAGE_TYPE_INFORMATION_REPLY:
Expand Down
12 changes: 0 additions & 12 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,6 @@ async def test_inverter_tcp_end_marker() -> None:
assert str(excinfo.value) == "Invalid end byte"


async def test_inverter_tcp_reply_identical_serial() -> None:
"""Require replied serial to be identical to the request."""

with pytest.raises(OmnikInverterPacketInvalidError) as excinfo:
assert tcp.parse_messages(1234, load_fixture_bytes("tcp_reply.data"))

assert (
str(excinfo.value)
== "Replied serial number 987654321 not equal to request 1234"
)


async def test_inverter_tcp_known_message_type() -> None:
"""Require message type to be known."""

Expand Down