|
9 | 9 | async def main(): |
10 | 10 | print("Discovering GoDice devices...") |
11 | 11 | discovery_res = await bleak.BleakScanner.discover(timeout=10, return_adv=True) |
12 | | - dev_advdata_tuples = discovery_res.values() |
13 | | - dev_advdata_tuples = filter_godice_devices(dev_advdata_tuples) |
| 12 | + device_advdata_tuples = discovery_res.values() |
| 13 | + device_advdata_tuples = filter_godice_devices(device_advdata_tuples) |
14 | 14 |
|
15 | 15 | print("Discovered devices...") |
16 | | - print_device_info(dev_advdata_tuples) |
| 16 | + print_device_info(device_advdata_tuples) |
17 | 17 |
|
18 | 18 | print("Connecting to a closest device...") |
19 | | - dev, _adv_data = select_closest_device(dev_advdata_tuples) |
20 | | - client = bleak.BleakClient(dev, timeout=15) |
| 19 | + device, _adv_data = select_closest_device(device_advdata_tuples) |
21 | 20 |
|
22 | 21 | # Python context manager (async with) is used for convenient connection handling |
23 | 22 | # Device stays connected during `async with` block execution and auto-disconnected on block finish |
24 | 23 | # Otherwise, dice.connect/dice.disconnect can be used instead |
25 | | - async with godice.create(client, godice.Shell.D6) as dice: |
26 | | - print(f"Connected to {dev.name}") |
| 24 | + async with godice.create(device.address, godice.Shell.D6) as dice: |
| 25 | + print(f"Connected to {device.name}") |
27 | 26 |
|
28 | 27 | blue_rgb = (0, 0, 255) |
29 | 28 | yellow_rgb = (255, 255, 0) |
|
0 commit comments