Skip to content

Commit

Permalink
fix stop button
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Dec 4, 2023
1 parent d582406 commit 2bfaeb9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
19 changes: 9 additions & 10 deletions pyacaia_async/acaiascale.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ async def connect(

if callback is None:
callback = self.on_bluetooth_data_received

try:
await self._client.start_notify(self._notify_char_id, callback)
await asyncio.sleep(0.5)
Expand All @@ -227,26 +228,24 @@ async def connect(
raise AcaiaError("Error subscribing to notifications") from ex

await self.auth()

if callback is not None:
await self.send_weight_notification_request()
await self.send_weight_notification_request()

except BleakDeviceNotFoundError as ex:
raise AcaiaDeviceNotFound("Device not found") from ex

self._setup_tasks()

def _setup_tasks(self) -> None:
"""Setup background tasks""":
"""Setup background tasks"""
if self._tasks_initialized:
return

self._heartbeat_task = asyncio.create_task(
self._send_heartbeats(
interval=HEARTBEAT_INTERVAL if not self._is_new_style_scale else 1,
new_style_heartbeat=self._is_new_style_scale,
)
self._send_heartbeats(
interval=HEARTBEAT_INTERVAL if not self._is_new_style_scale else 1,
new_style_heartbeat=self._is_new_style_scale,
)
)
self._process_queue_task = asyncio.create_task(self._process_queue())
self._tasks_initialized = True

Expand Down
10 changes: 5 additions & 5 deletions pyacaia_async/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, msg_type: int, payload: bytearray | list[int]) -> None:
self.timer_running = True
self.value = self._decode_weight(payload[2:])
_LOGGER.debug("start (weight: %s)", self.value)
elif (payload[0] == 10 and payload[1] == 7) or (
payload[0] == 10 and payload[1] == 5
):
elif payload[0] == 10 and payload[1] == 7:
self.button = "stop"
self.time = self._decode_time(payload[2:])
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
self.button = "stop"
self.timer_running = False
elif payload[0] == 9 and payload[1] == 7:
self.button = "reset"
self.time = self._decode_time(payload[2:])
Expand Down
6 changes: 5 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@


async def main():
scale = await AcaiaScale.create(mac="11:22:33:44:55", callback=notification_handler)
with open("mac.txt", "r") as f:
mac = f.read().strip()

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

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

await asyncio.sleep(1)
print("starting Timer...")
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="pyacaia_async",
version="0.0.11b8",
version="0.0.11b9",
description="An async implementation of PyAcaia",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 2bfaeb9

Please sign in to comment.