diff --git a/aioacaia/decode.py b/aioacaia/decode.py index fb1442b..4ff386f 100644 --- a/aioacaia/decode.py +++ b/aioacaia/decode.py @@ -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") diff --git a/pyproject.toml b/pyproject.toml index 7124170..1791c93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/run.py b/run.py index b0f7d87..7634f03 100644 --- a/run.py +++ b/run.py @@ -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...")