-
Notifications
You must be signed in to change notification settings - Fork 1
/
hue_on_off.py
executable file
·82 lines (63 loc) · 2.05 KB
/
hue_on_off.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
#!/usr/bin/env python3
"""Switches Hue Lamp(s) on or off."""
from termcolor import colored
from hue_class import HueLamp
from hue_config import lamp_dict
for a, n in lamp_dict.items():
globals()[n] = HueLamp(a, n)
print("\n###### Switches Hue Lamp(s) on or off. ######\n")
for lamp in lamp_dict.values():
hl_obj = globals()[lamp]
if hl_obj.on_off_state() == "on":
print("%s is %s." % (colored(hl_obj.name, 'yellow'), colored(hl_obj.on_off_state(), 'green')))
elif hl_obj.on_off_state() == "off":
print("%s is %s." % (colored(hl_obj.name, 'yellow'), colored(hl_obj.on_off_state(), 'red')))
print()
while True:
x = input("on/off : ")
print()
if x == 'on':
switch = 1
break
elif x == 'off':
switch = 0
break
else:
print("Please just input on or off.\n")
# create a dynamic string:
s = "Where to send ? "
for name in lamp_dict.values():
y = name[5:]
s = s + "%s " % y.replace(y[0], "(%s)" % y[0], 1)
if len(lamp_dict) > 1:
s = s + "or (a)ll : "
else:
s = s + " : "
while True:
kbd_inp = input(s)
print()
first_letter_list = [y[5] for y in lamp_dict.values()]
if kbd_inp in first_letter_list:
k = [y for y in lamp_dict.values() if kbd_inp == y[5]]
globals()[k[0]].on_off_switch(switch)
break
elif kbd_inp == "a":
for lamp in lamp_dict.values():
globals()[lamp].on_off_switch(switch)
break
else:
s = "Please just input "
for name in lamp_dict.values():
s = s + "(%s) " % name[5]
if len(lamp_dict) > 1:
s = s + "or (a) : "
else:
s = s + " : "
for lamp in lamp_dict.values():
hl_obj = globals()[lamp]
if hl_obj.on_off_state() == "on":
print("%s is %s." % (colored(hl_obj.name, 'yellow'), colored(hl_obj.on_off_state(), 'green')))
elif hl_obj.on_off_state() == "off":
print("%s is %s." % (colored(hl_obj.name, 'yellow'), colored(hl_obj.on_off_state(), 'red')))
hl_obj.prop_chg_notify.kill()
print()