Skip to content

Commit

Permalink
support two part messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Nov 13, 2024
1 parent 5fbefe5 commit 1be6d3d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion aioacaia/acaiascale.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,15 @@ async def on_bluetooth_data_received(
):
data = self._last_short_msg + data
self._last_short_msg = None
_LOGGER.debug("Restored message from previous data: %s", data)

try:
msg = decode(data)[0]
except AcaiaMessageTooShort as ex:
self._last_short_msg = ex.bytes_recvd
if ex.bytes_recvd[0] != HEADER1 or ex.bytes_recvd[1] != HEADER2:
_LOGGER.debug("Non-header message too short: %s", ex.bytes_recvd)
else:
self._last_short_msg = ex.bytes_recvd
return

if isinstance(msg, Settings):
Expand Down
1 change: 0 additions & 1 deletion aioacaia/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def decode(byte_msg: bytearray):
break

if msg_start < 0 or len(byte_msg) - msg_start < 6:
_LOGGER.debug("Message too short %s", byte_msg)
raise AcaiaMessageTooShort(byte_msg)

msg_end = msg_start + byte_msg[msg_start + 3] + 5
Expand Down
1 change: 1 addition & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


async def main():
# settings, arr = decode(bytearray(b"\xef\xdd\x08\t]\x02\x02\x01\x00\x01\x01\x00\r`"))
scale = AcaiaScale("aa:bb:cc:dd:ee:ff")
await scale.on_bluetooth_data_received(None, bytearray(b"\xef\xdd\x0c"))
res = await scale.on_bluetooth_data_received(
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.5b1",
version="0.1.5",
description="An async implementation of PyAcaia",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 1be6d3d

Please sign in to comment.