-
Notifications
You must be signed in to change notification settings - Fork 1
/
SetBulbXY.py
61 lines (53 loc) · 2.49 KB
/
SetBulbXY.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
def main():
from phue import Bridge
import argparse
# user-specific settings
lights_in_play = [
'Office Lamp 1A'
# 'Front Porch',
# 'Entryway', 'Foyer',
# 'TV', 'Ledge 1', 'Ledge 2', 'Ledge 3', 'Ledge 4',
# 'Office', 'Office Lamp 1A', 'Office Lamp 1B', 'Office Lamp 2A', 'Office Lamp 2B',
# 'Bedroom 1', 'Bedroom 2'
]
print('SetBulbXY')
# command-line argument parser
parser = argparse.ArgumentParser(
prog = 'SetBulbXY',
prefix_chars = '-/',
description = """This program assigns settings to a list of bulbs (list is currently coded into the .py file).""")
parser.add_argument('-v', '--verbose', help='Increase output verbosity', action="store_true")
parser.add_argument('-xy', help='An XY pair to define the bulb color (0.0-1.0, 0.0-1.0)', type=float, nargs=2, default=[0.5, 0.5])
parser.add_argument('-t', '--timing', help='Set bulb transition time (seconds)', type=float, default=0)
parser.add_argument('-b', '--brightness', help='Set bulb brightness (0 - 254)', type=int, default=254)
# TODO: add option to specify bulb names
# TODO: add option to specify light IDs
# TODO: add option to print list of bulb name/ID combos
# TODO: add option to print list of 'legal' named colors (green, red, energize)
# TODO: add option to specify colors as names
# TODO: add option to specify bridge IP
args = parser.parse_args()
x, y = args.xy[0], args.xy[1]
transitiontime = int(args.timing * 10) # API uses 10ths of seconds
bri = args.brightness
b = Bridge()
lights = b.get_light_objects('name')
light_ids_in_play = []
for name in lights_in_play:
light_ids_in_play.append(int(b.get_light_id_by_name(name)))
if args.verbose:
print('Verbosity set to ON')
print('Bulbs to be set: ' + str(light_ids_in_play))
print('XY color set to X = {0}, Y = {0}'.format(x, y))
print('Transition speed set to ' + str(abs(args.timing)) + ' seconds.')
print('Brightness set to ' + str(args.brightness))
# issue commands via the hub
command = {'on' : True, 'transitiontime' : transitiontime, 'xy' : [x, y], 'bri' : bri}
result = b.set_light(light_ids_in_play, command)
print('-- lights set, exiting program --')
# debug
# import pdb
# pdb.set_trace()
# debug
if __name__ == '__main__':
main()