-
Notifications
You must be signed in to change notification settings - Fork 0
/
colour_setter_old.py
executable file
·65 lines (43 loc) · 1.67 KB
/
colour_setter_old.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
#!/usr/bin/env python3
import lifx
# first step is to always ensure all bulbs are on (we do not switch them off, we just set brightness to 0 if we do not want any light)
lifx.set_power(lifx.BCAST, True)
def light_set_colour(light, hue, saturation, brightness):
hue = int(hue)
saturation = int(saturation)
brightness = int(brightness)
# pre-scale hue, TODO integrate into checks..
hue = hue / 355 * 100
if hue > 100 or saturation > 100 or brightness > 100 \
or hue < 0 or saturation < 0 or brightness < 0:
raise Exception("Only accepting percentages between 0 and 100")
scaling_coef = 65535/100
cnvt = lambda val: int(val * scaling_coef)
# set colour
params = map(cnvt, [hue, saturation, brightness])
paramsTest = list(params) + [3500, 50]
print(paramsTest)
light.set_color(*paramsTest)
if __name__ == "__main__":
import sys
lights = lifx.get_lights()
packets = sys.argv[1].split(".")
control_lights = {}
for packet in packets:
print(packet)
try:
light_addr, hue, saturation, brightness = packet.split(",")
control_lights[light_addr] = hue, saturation, brightness
except ValueError:
print("Invalid packet: {}".format(packet))
print(light_addr)
for light in lights:
cur_addr = light.get_addr()
if cur_addr in control_lights.keys():
light_set_colour(light, *control_lights[cur_addr])
"""
office: d073d500072c
living room: d073d5010fe5
./colour_setter.py d073d500072c 355 100 100
./colour_setter.py d073d5010fe5 355 100 0
"""