Skip to content

Commit

Permalink
more logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Nov 13, 2024
1 parent a081f12 commit 32941f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions aioacaia/decode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Message decoding functions, taken from pyacaia."""

import logging

from bleak import BleakGATTCharacteristic
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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:])


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 32941f9

Please sign in to comment.