-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_hue.py
34 lines (31 loc) · 1.23 KB
/
target_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
import qhue
import sys
def add_args(parser):
parser.add_argument('--hue-username', metavar='USERNAME', dest='hue_username', type=str,
help='the username to use when connecting to the bridge')
parser.add_argument('--hue-lights', metavar='ARRAY', dest='hue_lights', type=str, default="1",
help='the light(s) to change')
def get_target(args):
if not args.hue_username and args.hue:
print("Need to create the username")
from qhue import create_new_username
username = create_new_username(args.hue)
print("Add '--hue-username %s' to the command line and restart" % username)
sys.exit(0)
print("Will control Philips Hue @ %s" % args.hue)
b = qhue.Bridge(args.hue, args.hue_username)
lights = list(map(int, args.hue_lights.split(',')))
def set_lights(state):
if state == "blue":
hue = 46920
elif state == "green":
hue = 25500
elif state == "mix":
hue = (46920 + 25500) // 2
else:
hue = 0
for light in lights:
b.lights[light].state(bri=127, hue=hue)
for light in lights:
b.lights[light].state(bri=255, hue=hue)
return set_lights