Skip to content

Commit

Permalink
Merge pull request #6 from zweckj/feature/button-parsing
Browse files Browse the repository at this point in the history
improve button parsing
  • Loading branch information
zweckj authored Jan 2, 2025
2 parents 0510e67 + d1cdd92 commit a366620
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
40 changes: 34 additions & 6 deletions aioacaia/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,53 @@ def __init__(self, msg_type: int, payload: bytearray | list[int]) -> None:
self.button = "start"
self.timer_running = True
self.value = self._decode_weight(payload[2:])
_LOGGER.debug("start (weight: %s)", self.value)
_LOGGER.debug("Timer started. Weight: %s", self.value)
elif payload[0] == 8 and payload[1] == 11:
self.button = "start"
self.timer_running = True
_LOGGER.debug("Timer started")
elif payload[0] == 10 and payload[1] == 7:
self.button = "stop"
self.timer_running = False
self.time = self._decode_time(payload[2:])
self.value = self._decode_weight(payload[6:])
_LOGGER.debug("stop time: %s, weight: %s", self.time, self.value)
elif payload[0] == 10 and payload[1] == 5: # stop for new scale
_LOGGER.debug(
"Timer stopped. Time: %s, weight: %s",
self.time,
self.value,
)
elif payload[0] == 10 and payload[1] == 5:
self.button = "stop"
self.timer_running = False
self.time = self._decode_time(payload[2:])
_LOGGER.debug("Timer stopped. Time: %s", self.time)
elif payload[0] == 10 and payload[1] == 13:
self.button = "stop"
self.timer_running = False
_LOGGER.debug("Timer stopped")
elif payload[0] == 9 and payload[1] == 7:
self.button = "reset"
self.time = self._decode_time(payload[2:])
self.value = self._decode_weight(payload[6:])
_LOGGER.debug("reset time: %s, weight: %s", self.time, self.value)
_LOGGER.debug(
"Timer reset. Time: %s, weight: %s", self.time, self.value
)
elif payload[0] == 9 and payload[1] == 5:
self.button = "reset"
self.time = self._decode_time(payload[2:])
_LOGGER.debug("reset time: %s", self.time)

elif payload[0] == 9 and payload[1] == 12:
self.button = "reset"
_LOGGER.debug("Timer reset")
else:
self.button = "unknownbutton"
_LOGGER.debug("unknownbutton %s", str(payload))

_LOGGER.debug(
"Uknown Button: %s,%s. Full payload: %s",
payload[0],
payload[1],
str(payload),
)
else:
raise AcaiaMessageError(bytearray(payload), "Unknown message type")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "aioacaia"
version = "0.1.11"
version = "0.1.12"
license = { text = "MIT" }
description = "An async implementation of PyAcaia"
readme = "README.md"
Expand Down
43 changes: 24 additions & 19 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@
from aioacaia import AcaiaScale
from aioacaia.decode import notification_handler
from aioacaia.decode import decode, Message
from aioacaia.helpers import is_new_scale


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(
None, bytearray(b"\x0c\x05\xdf\x06\x00\x00\x01\x00\x07\x00\x00\x02\xf3\r")
)
decode(
bytearray(b"\xef\xdd\x0c\x0c\x05\xdf\x06\x00\x00\x01\x00\x07\x00\x00\x02\xf3\r")
)
# Message(5, bytearray(b"\xdf\x06\x00\x00\x01\x00\x07\x00\x00\x02\xf3\r"))
# Message(5, b"\xa1\x10\x00\x00\x01\x01\x07\x00\x00\x02\xb5\x18")
# Message(5, bytearray(b"]\x07\x00\x00\x01\x00\x07\x00\x00\x02q\x0e"))
# 0 = 12
# 1 = 5
Message(5, b"\x00\x00\x00\x00\x01\x00\x07\x00\x00\x02\x14\x07")
decode(bytearray(b"\x0c\x05\x00\x00\x00\x00\x01\x00\x07\x00\x00\x02\x14\x07"))
exit(0)
# print(await is_new_scale("60:8A:10:4E:24:50"))
# exit(0)

# # 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(
# None, bytearray(b"\x0c\x05\xdf\x06\x00\x00\x01\x00\x07\x00\x00\x02\xf3\r")
# )
# decode(
# bytearray(b"\xef\xdd\x0c\x0c\x05\xdf\x06\x00\x00\x01\x00\x07\x00\x00\x02\xf3\r")
# )
# # Message(5, bytearray(b"\xdf\x06\x00\x00\x01\x00\x07\x00\x00\x02\xf3\r"))
# # Message(5, b"\xa1\x10\x00\x00\x01\x01\x07\x00\x00\x02\xb5\x18")
# # Message(5, bytearray(b"]\x07\x00\x00\x01\x00\x07\x00\x00\x02q\x0e"))
# # 0 = 12
# # 1 = 5
# Message(5, b"\x00\x00\x00\x00\x01\x00\x07\x00\x00\x02\x14\x07")
# decode(bytearray(b"\x0c\x05\x00\x00\x00\x00\x01\x00\x07\x00\x00\x02\x14\x07"))
# exit(0)

with open("mac.txt", "r") as f:
mac = f.read().strip()

scale = await AcaiaScale.create(mac=mac, callback=None)
scale = AcaiaScale(address_or_ble_device=mac)
await scale.connect()

# await asyncio.sleep(1)
# await scale.tare()
await asyncio.sleep(120)
await asyncio.sleep(300)

await asyncio.sleep(1)
print("starting Timer...")
Expand Down

0 comments on commit a366620

Please sign in to comment.