-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·73 lines (63 loc) · 2.55 KB
/
main.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
#!/usr/bin/env python3
import argparse
import asyncio
import sys
from govle import govle, color
from govle.logging import logger, logging
from config import *
logging.getLogger('govle').setLevel(logging.DEBUG)
async def main():
parser = argparse.ArgumentParser("description='govle LED strip tool'")
parser.add_argument("device", help="Which device to control", choices=devices.keys())
parser.add_argument('-o', "--operation", help="Operation to perform", default="discover")
parser.add_argument('-l', "--level", help="Brightness level, 0-255", type=int)
parser.add_argument('-r', "--rgb", nargs=3, type=int)
args = parser.parse_args()
if args.operation == "brightness" and args.level is None:
parser.error("brightness operation requires --level parameter")
elif args.operation == "color" and args.rgb is None:
parser.error("color operation requires --rgb parameter")
device_name = args.device
operation = args.operation
level = args.level
rgb = args.rgb
if operation == "discover":
logger.info("Discovering devices...")
await govle.Govle.discover()
return
async with govle.Govle(devices[device_name]) as gle:
if operation == "on":
await gle.set_power(True)
elif operation == "off":
await gle.set_power(False)
elif operation == "gradient-on":
await gle.set_gradient(True)
elif operation == "gradient-off":
await gle.set_gradient(False)
elif operation == "brightness":
await gle.set_brightness(level)
elif operation == "color":
await gle.set_color(rgb)
elif operation == "slide":
forward = True
back, spot = color.get_random_complementary_pair()
for _ in range(5):
await gle.slide(back, spot, hold=0.1, forward=forward)
forward = not forward
elif operation == "diy":
await gle.diy()
elif operation == "all":
await gle.set_power(True)
await gle.set_gradient(True)
await gle.set_gradient(False)
for b in range(10, 251, 10):
await gle.set_brightness(b)
for _ in range(10):
await gle.set_color(color.get_random_color())
back, spot = color.get_random_complementary_pair()
await gle.slide(back, spot, hold=0.1)
await gle.set_power(False)
else:
parser.error(f"unknown operation '{operation}'")
if __name__ == "__main__":
asyncio.run(main())