-
Notifications
You must be signed in to change notification settings - Fork 0
/
hue.py
executable file
·64 lines (48 loc) · 1.45 KB
/
hue.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
#!/usr/bin/python3
import sys
from phue import Bridge
from pprint import pprint
b = Bridge('192.168.87.212')
# If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
b.connect()
def convert_color(hexCode):
R = int(hexCode[:2],16)
G = int(hexCode[2:4],16)
B = int(hexCode[4:6],16)
total = R + G + B
if R == 0:
firstPos = 0
else:
firstPos = R / total
if G == 0:
secondPos = 0
else:
secondPos = G / total
return [firstPos, secondPos]
def is_any_light_on():
lights = b.get_light_objects()
for light in lights:
if "Fugato" in light.name and light.on:
return True
return False
def set_lights_colors(hex_colors):
lights = b.get_light_objects()
num_lights_set = 0
for light in lights:
if "Fugato" in light.name:
hex_color = hex_colors[num_lights_set % len(hex_colors)]
light.on = True
light.xy = convert_color(hex_color)
num_lights_set += 1
def set_lights_color(hex_color):
lights = b.get_light_objects()
for light in lights:
if "Fugato" in light.name:
light.on = True
light.xy = convert_color(hex_color)
if __name__ == "__main__":
if len(sys.argv) >= 2:
hex_color = sys.argv[1]
else:
hex_color = 'ff0000'
set_lights_color(hex_color)