diff --git a/pyplumio/helpers/uid.py b/pyplumio/helpers/uid.py index cc24e675..1c333d85 100644 --- a/pyplumio/helpers/uid.py +++ b/pyplumio/helpers/uid.py @@ -4,9 +4,9 @@ def unpack_uid(message: bytearray, offset: int = 0) -> str: """Decode and return a complete UID string.""" - uid_length = message[offset] + length = message[offset] offset += 1 - uid = message[offset : uid_length + offset] + uid = message[offset : length + offset] return _encode_base5(uid + _uid_crc(uid)) diff --git a/pyplumio/structures/alerts.py b/pyplumio/structures/alerts.py index 8d1ed5d0..04c1874d 100644 --- a/pyplumio/structures/alerts.py +++ b/pyplumio/structures/alerts.py @@ -26,6 +26,7 @@ def _convert_to_datetime(seconds: int) -> datetime: """Convert timestamp to a datetime object.""" def _seconds_to_datetime_args(seconds: int) -> Generator[Any, None, None]: + """Convert seconds to a kwarg for a datetime class.""" intervals: tuple[tuple[str, int, int], ...] = ( (ATTR_YEAR, 32140800, 2000), # 60sec * 60min * 24h * 31d * 12m (ATTR_MONTH, 2678400, 1), # 60sec * 60min * 24h * 31d diff --git a/pyplumio/util.py b/pyplumio/util.py index 0d668c38..8b626bbf 100644 --- a/pyplumio/util.py +++ b/pyplumio/util.py @@ -4,6 +4,7 @@ import functools import struct +# Data type unpackers. unpack_float = struct.Struct(" str: @@ -24,6 +23,11 @@ def unpack_string(data: bytearray, offset: int = 0) -> str: return data[offset : offset + strlen + 1].decode() +# Frame header packer/unpacker. +pack_header = struct.Struct(" int: """Return a checksum.""" return functools.reduce(lambda x, y: x ^ y, data)