Skip to content

Commit

Permalink
Ignore empty alerts frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Oct 26, 2023
1 parent 301de05 commit 783c6b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pyplumio/structures/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def decode(
"""Decode bytes and return message data and offset."""
start = message[offset + 1]
end = message[offset + 2]

if end == 0:
# No alerts found.
return ensure_dict(data), offset + 1

self._offset = offset + 3
return (
ensure_dict(
Expand Down
12 changes: 11 additions & 1 deletion tests/frames/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
UIDResponse,
)
from pyplumio.helpers.typing import EventDataType
from pyplumio.structures.alerts import ATTR_ALERTS
from pyplumio.structures.data_schema import ATTR_SCHEMA
from pyplumio.structures.mixer_parameters import ATTR_MIXER_PARAMETERS
from pyplumio.structures.thermostat_parameters import (
Expand Down Expand Up @@ -169,13 +170,22 @@ def test_alerts_response(
data: dict[FrameType, EventDataType],
messages: dict[FrameType, bytearray],
) -> None:
"""Test alert response."""
"""Test alerts response."""
frame1 = AlertsResponse(message=messages[FrameType.RESPONSE_ALERTS])
frame2 = AlertsResponse(data=data[FrameType.RESPONSE_ALERTS])
assert frame1.data == data[FrameType.RESPONSE_ALERTS]
assert not frame2.message


def test_alerts_response_with_no_alerts(
data: dict[FrameType, EventDataType],
messages: dict[FrameType, bytearray],
) -> None:
"""Test alerts response with no alerts."""
frame = AlertsResponse(message=bytearray.fromhex("000000"))
assert ATTR_ALERTS not in frame.data


def test_schedule_response(
data: dict[FrameType, EventDataType], messages: dict[FrameType, bytearray]
) -> None:
Expand Down

0 comments on commit 783c6b3

Please sign in to comment.