-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_esphome.py
62 lines (49 loc) · 1.36 KB
/
test_esphome.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# import aioesphomeapi
import asyncio
from lights import get_lights
from setup import Setup
setup = Setup('setup.json')
cycle = [
(1.0, 0, 0.5),
(0, 0, 1.0),
(0, 1.0, 0),
(1.0, 0.5, 0),
(1.0, 0, 0)
]
async def main():
lights = get_lights(setup)
lights.start()
run_ = True
sleep_time = 1
cycle1 = 0
cycle2 = 1
while run_:
await asyncio.sleep(sleep_time)
# breakpoint()
lights[0][0].command(rgb=cycle[cycle1], brightness=0.5)
lights[0][1].command(rgb=cycle[cycle2], brightness=0.5)
# sensors, services = await client.list_entities_services()
# print(f'{sensors=}, {services=}')
cycle1 += 1
if cycle1 > len(cycle) - 1:
cycle1 = 0
cycle2 += 1
if cycle2 > len(cycle) - 1:
cycle2 = 0
# async def main():
# """Connect to an ESPHome device and wait for state changes."""
# cli = aioesphomeapi.APIClient('192.168.9.4', 6053, None)
# await cli.connect(login=True)
# def change_callback(state):
# """Print the state changes of the device.."""
# print(state)
# # Subscribe to the state changes
# await cli.subscribe_states(change_callback)
loop = asyncio.get_event_loop()
try:
asyncio.ensure_future(main())
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()