Skip to content

Commit

Permalink
Fix pending alert date.
Browse files Browse the repository at this point in the history
While alert is still in progress, it's date is set to "FF FF FF FF".
  • Loading branch information
denpamusic committed Mar 6, 2024
1 parent b9429c8 commit b81ff34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pyplumio/structures/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ATTR_ALERTS: Final = "alerts"
ATTR_TOTAL_ALERTS: Final = "total_alerts"

MAX_UINT32: Final = 4294967295


@lru_cache(maxsize=10)
def _convert_to_datetime(seconds: int) -> datetime:
Expand Down Expand Up @@ -72,7 +74,11 @@ def _unpack_alert(self, message: bytearray) -> Alert:
self._offset += to_seconds.size

from_dt = _convert_to_datetime(from_seconds.value)
to_dt = _convert_to_datetime(to_seconds.value) if to_seconds.value > 0 else None
to_dt = (
None
if to_seconds.value == MAX_UINT32
else _convert_to_datetime(to_seconds.value)
)

return Alert(code, from_dt, to_dt)

Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/responses/alerts.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "alerts",
"message": {
"items": [
"6400021A5493382B9B94382B009C97372B00000000"
"6400021A5493382B9B94382B009C97372BFFFFFFFF"
],
"__bytearray__": true
},
Expand Down

0 comments on commit b81ff34

Please sign in to comment.