-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflux_master.py
93 lines (75 loc) · 1.9 KB
/
flux_master.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from subprocess import call
import re
import random
import os
import webcolors
def turnOff():
call(["python", "%s/FluxScripts/flux_led.py" % os.getcwd(), "10.0.1.4", "--off"])
def changeColor(color):
rgb = re.sub('[() ]', '', str(webcolors.name_to_rgb(color)))
call(["python", "%s/FluxScripts/flux_led.py" % os.getcwd(), "10.0.1.4", "-c", rgb])
def turnOn():
call(["python", "%s/FluxScripts/flux_led.py" % os.getcwd(), "10.0.1.4", "--on"])
def party():
rgbs = ["255,0,0", "0,0,255", "0,255,0", "255,100,0", "255,0,255", "0,255,255"]
rgb =""
random.shuffle(rgbs)
for i in range(len(rgbs)):
rgb+= rgbs[i]
rgb+= " "
#for i in range(random.randint(4,12)):
# color = []
# for x in range(3):
# z = random.randint(0,255)
# color.append(random.randint(0,255))
# rgb += str(z) + ","
# rgb += " "
rgb = rgb[0:len(rgb)-1]
print rgb
call(["python", "%s/FluxScripts/flux_led.py" % os.getcwd(), "10.0.1.4", "-C", "strobe", "99", rgb])
def strobe(color="white"):
if color != "white":
rgb = re.sub('[() ]', '', str(webcolors.name_to_rgb(color)))
else:
rgb = "255,255,255"
call(["python", "%s/FluxScripts/flux_led.py" % os.getcwd(), "10.0.1.4", "-C", "strobe", "100", rgb])
def bulbmaster(i):
txt = open("bulbstate.txt", "r+")
statelist = txt.readlines()
state = re.sub('[\n]', '', statelist[0])
if state == "0":
bulbstate = False
elif state == "1":
bulbstate = True
else:
print("unexpected bulb state (not 1 or 0)")
if i == "off":
turnOff()
bulbstate = False
elif i == "on":
turnOn()
bulbstate = True
elif "strobe" in i:
print 'strobe'
if bulbstate == False:
turnOn()
bulbstate = True
strobe()
elif "party" in i:
if bulbstate == False:
turnOn()
bulbstate = True
party()
else:
if bulbstate == False:
turnOn()
bulbstate = True
changeColor(i)
if bulbstate:
txt.seek(0)
txt.write("1")
else:
txt.seek(0)
txt.write("0")
txt.close()
bulbmaster('off')