Debian Codegraph @

README.md

raw
1 # aioacaia
2
3 Async Python library for interacting with Acaia Bluetooth scales.
4
5 ## Usage
6
7 ```python
8 import asyncio
9
10 from aioacaia import AcaiaScale
11 from aioacaia.discovery import find_acaia_devices, is_new_scale
12
13
14 async def main() -> None:
15 addresses = await find_acaia_devices()
16 if not addresses:
17 raise RuntimeError("No Acaia scale found")
18
19 address = addresses[0]
20 scale = AcaiaScale(
21 address,
22 is_new_style_scale=await is_new_scale(address),
23 )
24 await scale.connect()
25
26 try:
27 await scale.tare()
28 await scale.start_stop_timer()
29 await scale.reset_timer()
30 finally:
31 await scale.disconnect()
32
33
34 asyncio.run(main())
35 ```
36
37 ## State Updates
38
39 Pass a no-argument callback to receive notification when the scale state changes.
40 The latest values are available through `weight`, `timer`, `flow_rate`, and
41 `device_state`.
42
43 ```python
44 import asyncio
45
46 from aioacaia import AcaiaScale
47
48
49 async def monitor(address: str) -> None:
50 scale: AcaiaScale
51
52 def state_changed() -> None:
53 print(f"Weight: {scale.weight}")
54 print(f"Timer: {scale.timer}")
55 if scale.device_state is not None:
56 print(f"Battery: {scale.device_state.battery_level}%")
57
58 scale = AcaiaScale(address, notify_callback=state_changed)
59 await scale.connect()
60 try:
61 await asyncio.Event().wait()
62 finally:
63 await scale.disconnect()
64
65
66 asyncio.run(monitor("AA:BB:CC:DD:EE:FF"))
67 ```
68
69 `connect()` also accepts a raw Bleak notification callback. Supplying one bypasses
70 the built-in parsing and state updates.