forked from lkempf/casambi-bt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
46 lines (33 loc) · 1.03 KB
/
demo.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import asyncio
import logging
from CasambiBt import Casambi, discover
_LOGGER = logging.getLogger()
_LOGGER.addHandler(logging.StreamHandler())
async def main() -> None:
logging.getLogger("CasambiBt").setLevel(logging.DEBUG)
# Discover networks
print("Searching...")
devices = await discover()
for i, d in enumerate(devices):
print(f"[{i}]\t{d.address}")
selection = int(input("Select network: "))
device = devices[selection]
pwd = input("Enter password: ")
# Connect to the selected network
casa = Casambi()
try:
await casa.connect(device, pwd)
# Turn all lights on
await casa.turnOn(None)
await asyncio.sleep(5)
# Turn all lights off
await casa.setLevel(None, 0)
await asyncio.sleep(1)
# Print the state of all units
for u in casa.units:
print(u.__repr__())
finally:
await casa.disconnect()
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())