-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.py
49 lines (40 loc) · 1.41 KB
/
control.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
#!/usr/bin/env python3
import argparse
import json
import sys
import remote
import record
lights = ['tao', 'tx', 'hana']
modules = {}
for l in lights:
try:
modules[l] = __import__('light.' + l, fromlist=[None])
except ImportError:
print('Error importing ' + l)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Control stateful lights')
parser.add_argument('--light', help='tao, tx, or hana')
parser.add_argument(
'--part', help='default, tao: top, down', default='default')
parser.add_argument('--on', action='store_true')
parser.set_defaults(power=True)
parser.add_argument('--off', dest='power', action='store_false')
parser.add_argument('--brightness', type=int, default=-1)
parser.add_argument('--sync', action='store_true')
parser.add_argument('--status', action='store_true')
args = parser.parse_args()
if args.light in lights:
if args.status:
sys.stdout.write(json.dumps(record.get(args.light)))
elif args.sync:
sys.stdout.write(json.dumps(record.save(
args.light, modules[args.light].sync())))
else:
current = record.get(args.light)
target = (args.power, args.brightness, args.part)
final, clicks = modules[args.light].clicks(current, target)
for c in clicks:
remote.click(*c)
sys.stdout.write(json.dumps(record.save(args.light, final)))
else:
print('Light is what? ' + str(args.light))