From 32941f911489df5a6b88c0cf7338f68cdc119a2f Mon Sep 17 00:00:00 2001 From: Josef Zweck <24647999+zweckj@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:43:33 +0100 Subject: [PATCH] more logging messages --- aioacaia/decode.py | 10 ++++++++++ setup.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aioacaia/decode.py b/aioacaia/decode.py index c2a6e39..21d9d78 100644 --- a/aioacaia/decode.py +++ b/aioacaia/decode.py @@ -1,4 +1,5 @@ """Message decoding functions, taken from pyacaia.""" + import logging from bleak import BleakGATTCharacteristic @@ -19,6 +20,11 @@ def __init__(self, msg_type: int, payload: bytearray | list[int]) -> None: self.time: int | None = None self.timer_running: bool | None = None + _LOGGER.debug( + "Message received: msg_type: %s, payload: %s", + str(msg_type), + payload, + ) if self.msg_type == 5: self.value = self._decode_weight(payload) @@ -152,12 +158,15 @@ def decode(byte_msg: bytearray): if byte_msg[i] == HEADER1 and byte_msg[i + 1] == HEADER2: msg_start = i break + if msg_start < 0 or len(byte_msg) - msg_start < 6: + _LOGGER.debug("Message too short %s", byte_msg) return (None, byte_msg) msg_end = msg_start + byte_msg[msg_start + 3] + 5 if msg_end > len(byte_msg): + _LOGGER.debug("Message too long %s", byte_msg) return (None, byte_msg) if msg_start > 0: @@ -176,6 +185,7 @@ def decode(byte_msg: bytearray): str(cmd), str(byte_msg[msg_start:msg_end]), ) + _LOGGER.debug("Full message: %s", byte_msg) return (None, byte_msg[msg_end:]) diff --git a/setup.py b/setup.py index 5b794f1..0034be4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="aioacaia", - version="0.1.3", + version="0.1.4", description="An async implementation of PyAcaia", long_description=readme, long_description_content_type="text/markdown",