-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.py
executable file
·63 lines (56 loc) · 1.88 KB
/
flow.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
#!/usr/bin/env python3
from bulb_ip import B
from yeelight import Flow, Bulb, flows
from state import get_state
import argparse
def flow(flow, *args):
B.turn_on()
print('flowing', flow)
try:
method = getattr(flows, flow)
flow = method(*args)
except AttributeError as e:
print(e)
exit(1)
B.start_flow(flow)
def list_flows():
l = {}
f_check = lambda x: (
not x.startswith('_')
and x.islower()
and hasattr(getattr(flows, x), '__call__')
)
for f in filter(f_check, dir(flows)):
l[f] = None
return '\n'.join(l.keys())
def show_description(flow):
return '\n'.join(
filter(lambda x: not (':returns' in x or ':rtype' in x),
getattr(flows, flow).__doc__.split('\n')
)
).strip()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--no-replace",
help="don't replace existing flows", action="store_true")
group = parser.add_mutually_exclusive_group()
group.add_argument("flow", nargs='*', help="the flow method", default="random_loop")
group.add_argument("-s", "--stop", help="stop flowing", action="store_true")
group.add_argument("-l", "--list", help="list all flows", action="store_true")
group.add_argument("-d", "--description",
help="show the description of a flow", type=str)
args = parser.parse_args()
if args.no_replace and get_state()['flowing'] == '1':
pass
elif args.list:
print(list_flows())
elif args.stop:
B.stop_flow()
elif args.description:
print(show_description(args.description))
else:
if type(args.flow) == list:
flow_name, args = (args.flow[0], list(map(int, args.flow[1:])))
else:
flow_name, args = (args.flow, [])
flow(flow_name, *args)