-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
71 lines (57 loc) · 1.67 KB
/
run.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
import time
from devicesdef import WifiBulbConfig, WifiBulb
from discover import Discover
from music import MusicServer
import logger
# Discover a device
Discoverer = Discover(WifiBulbConfig)
Devices = Discoverer.discover()
if Devices:
# Pick the first one
Device = next(iter(Devices.values()))
# Turn on the first device
Device.set_power('on')
# Set the first device to white, 5400k colortemp
Device.set_ct_abx(5400)
# Set the first device to red
Device.set_rgb(255,0,0)
# Set the first device to blue
Device.set_rgb(0,0,255)
# Start a color flow
flow = [
{
'duration':500,
'mode':'rgb',
'red':255,
'green':0,
'blue':0,
'brightness':100
},{
'duration':500,
'mode':'rgb',
'red':0,
'green':0,
'blue':255,
'brightness':100
}
]
Device.start_cf(10,0,flow)
# Wait for the color flow to finish
time.sleep(5)
# Before music mode, need to start the server
Server = MusicServer(port = 10800)
Server.launch()
# Now, tell the device to connect
Device.set_music(1,'192.168.20.4', 10800)
# Then, at the server side, we need to get the connected device
MusicControlSocket = Server.next_device(Device)
# Try something with music mode
import random
for x in range(10):
MusicControlSocket.set_rgb(random.randint(1,255),random.randint(1,255),random.randint(1,255))
# Stop music mode
Device.set_music(0)
# Toggle the device (which should turn it off)
Device.toggle()
else:
logger.info('No device found!')