-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
54 lines (42 loc) · 1.66 KB
/
test.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
#!/usr/bin/env python3
import sys
import logging
import argparse
import asyncio
import json
import pyeverlights
async def cmd_status():
print(json.dumps(await el.get_status(), sort_keys=True, indent=4))
async def cmd_color():
await el.set_pattern(args.zone, [args.red*0x10000+args.green*0x100+args.blue])
async def cmd_pattern():
await el.set_pattern_by_id(args.zone, args.pattern)
def parse_args():
parser = argparse.ArgumentParser("Control an EverLights lighting system.")
parser.add_argument('--ip', required=True)
parser.add_argument('-v', '--verbose',
action='store_const', const=logging.DEBUG, default=logging.WARN)
subparsers = parser.add_subparsers()
parser_status = subparsers.add_parser('status', help='Get control box status.')
parser_status.set_defaults(func=cmd_status)
parser_color = subparsers.add_parser('color', help='Set all lights to a single color.')
parser_color.add_argument('red', type=int)
parser_color.add_argument('green', type=int)
parser_color.add_argument('blue', type=int)
parser_color.add_argument('--zone', default=pyeverlights.ZONE_1)
parser_color.set_defaults(func=cmd_color)
parser_pattern = subparsers.add_parser('pattern', help='Start a saved pattern.')
parser_pattern.add_argument('pattern')
parser_pattern.add_argument('--zone', default=pyeverlights.ZONE_1)
parser_pattern.set_defaults(func=cmd_pattern)
return parser.parse_args()
async def main():
global el, args
args = parse_args()
logging.basicConfig(level=args.verbose)
el = pyeverlights.EverLights(args.ip)
await args.func()
await el.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
print("Done")