-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathwebsocket.py
More file actions
31 lines (22 loc) · 799 Bytes
/
Copy pathwebsocket.py
File metadata and controls
31 lines (22 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# pylint: disable=W0621
"""Asynchronous Python client for WLED."""
import asyncio
from wled import WLED, Device
async def main() -> None:
"""Show example of WebSocket usage with WLED."""
async with WLED("10.10.11.135") as led:
await led.connect()
if led.connected:
print("connected!")
def something_updated(device: Device) -> None:
"""Call when WLED reports a state change."""
print("Received an update from WLED")
print(device.state)
print(device.info)
# Start listening
task = asyncio.create_task(led.listen(callback=something_updated))
# Now we stream for an hour
await asyncio.sleep(3600)
task.cancel()
if __name__ == "__main__":
asyncio.run(main())