forked from angadsingh/wiz_light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·72 lines (61 loc) · 2.26 KB
/
test.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
63
64
65
66
67
68
69
70
71
72
import asyncio
import asyncio_dgram
import time
from .wizlight import wizlight, PilotBuilder
import logging
import sys
# python3 -m wiz_light.test
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
_LOGGER = logging.getLogger(__name__)
async def testbulb(bulb):
wait_secs=10
state = await bulb.updateState()
if state.get_state(): # check if on
await asyncio.wait_for(bulb.turn_off(), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.lightSwitch(), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_off(), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(brightness = 255)), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(brightness = 50)), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(rgb = (50, 100, 200))), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(colortemp = 4000)), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(colortemp = 6500)), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(scene = 14)), wait_secs)
await asyncio.sleep(0.5)
await asyncio.wait_for(bulb.turn_on(PilotBuilder(scene = 24)), wait_secs)
state = await bulb.updateState()
print(state.get_state())
print(state.get_scene())
print(state.get_scene())
print(state.get_warm_white())
print(state.get_speed())
print(state.get_cold_white())
print(state.get_rgb())
print(state.get_brightness())
print(state.get_colortemp())
async def run_bulb_automation():
loop = asyncio.get_event_loop()
bulb1 = wizlight('192.168.1.58')
bulb2 = wizlight('192.168.1.7')
# await asyncio.gather(testbulb(bulb1), testbulb(bulb2), loop = loop)
state = await bulb1.updateState()
await bulb1.turn_on(PilotBuilder(scene = 14))
state = await bulb1.updateState()
await asyncio.sleep(0.5)
await bulb1.turn_on(PilotBuilder()) #rhythm
state = await bulb1.updateState()
if __name__ == '__main__':
asyncio.run(run_bulb_automation())