-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
63 lines (59 loc) · 2.3 KB
/
app.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
from time import sleep
from utils.window_util import *
from utils.hue_util import *
from utils.config_util import parseconfig
def monitorAndMakeRed(ip, lightsToChange, window):
print("Monitoring")
redSettings = {'hue': 64949\
,'saturation': 254\
,'brightness': 254\
,'on': True}
isRed = False
while True:
programOpen = findWindow(window.encode('utf8'))
if programOpen and not isRed:
print("Connecting to Hue...")
b, lights = collectHueLights(ip)
print("Connected!")
lightAttributes = [getLightAttributes(lights[light]) for light in lightsToChange]
isRed = True
for light in lightAttributes:
changeLightColor(light = light['light'], **redSettings)
elif isRed and not programOpen:
for light in lightAttributes:
changeLightColor(**light)
isRed = False
sleep(5)
def testItWithoutHue(ip, lightsToChange, window):
print("Could not connect to Hue Bridge; proceeding to test without Hue")
redSettings = {'hue': 64949\
,'saturation': 254\
,'brightness': 254\
,'on': True}
isRed = False
while True:
programOpen = findWindow(windowToMonitor)
if programOpen and not isRed:
# b, lights = collectHueLights(ip)
# lightAttributes = [getLightAttributes(lights[light]) for light in lightsToChange]
isRed = True
# for light in lightAttributes:
# changeLightColor(light = light['light'], **redSettings)
print("It's red now")
elif isRed and not programOpen:
# for light in lightAttributes:
# changeLightColor(**light)
isRed = False
print("It's back to normal")
sleep(5)
if __name__ == "__main__":
print("Starting up....")
config = parseconfig('config.ini')
windowToMonitor = config['OS']['window']
bridgeIP = config['HUE']['ip']
lightsToChange = config['HUE']['lightsToChange'].split(",")
try:
monitorAndMakeRed(bridgeIP, lightsToChange, windowToMonitor)
except Exception as e:
print(e)
testItWithoutHue(bridgeIP, lightsToChange, windowToMonitor)