File: usage_bridge.md

package info (click to toggle)
python-aioswitcher 6.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,556 kB
  • sloc: python: 4,913; makefile: 8
file content (22 lines) | stat: -rw-r--r-- 727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Use the Bridge to discover devices and their state. The following excerpt will print all discovered devices for 60 seconds.

```python linenums="1" hl_lines="9"
import asyncio
from dataclasses import asdict
from aioswitcher.bridge import SwitcherBridge

async def print_devices(delay):
    def on_device_found_callback(device):
        print(asdict(device)) # (1)

    async with SwitcherBridge(on_device_found_callback):
        await asyncio.sleep(delay)

asyncio.run(print_devices(60))
```

1. for the callback types, check the device pacakge for implementations of
    [SwitcherBase](./codedocs.md#src.aioswitcher.device.SwitcherBase).

!!!note
    Switcher devices broadcast a state message approximately every 4 seconds.