-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlightctl
82 lines (65 loc) · 2.4 KB
/
lightctl
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
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import os
import sys
import argparse
class LightCTL:
def __init__(self):
self.parser = argparse.ArgumentParser()
commands = self.parser.add_subparsers(dest="command")
brightness_cmd = commands.add_parser("set-brightness")
brightness_cmd.add_argument("brightness_level", type=float, help="set the brightness of the strip to a value from 0 to 255 (Floats between 0 and 1 are also fine)")
setpixel = commands.add_parser("set-pixel")
setpixel.add_argument("zone", type=str, help="name of the zone to set pixel in")
setpixel.add_argument("pos", type=int, help="offset of the pixel to set")
setpixel.add_argument("color", type=str, help="color of the pixel to set")
loadconf = commands.add_parser("load-conf")
loadconf.add_argument("path", help="Path of the conf file to hotload")
reloadconf = commands.add_parser("reload-conf")
deliver = commands.add_parser("deliver")
deliver.add_argument("zone", type=str, help="Name of the zone to pass status info to")
deliver.add_argument("data", type=str, help="Arbitrary data to deliver to a zone")
def get_args(self):
self.args = self.parser.parse_args()
return self.args
def process_command(self):
import dbus, dbus.exceptions
try:
bus = dbus.SessionBus()
self.dbus = bus.get_object("fox.pandora.rgbd", "/fox/pandora/rgbd/lightctl")
except dbus.exceptions.DBusException as e:
print("Unable to initialize dbus connection. Please ensure the daemon is running with < command in the future >")
sys.exit(2)
if (self.args.command == "set-brightness"):
b = self.args.brightness_level
if (0 < b and b < 1):
b = int(b*255)
elif (0 <= b and b < 256):
b = int(b)
else:
print("Invalid brightness given!")
sys.exit(1)
self.dbus.brightness(b)
sys.exit(0)
if (self.args.command == "set-pixel"):
z = self.args.zone
i = self.args.pos
col = self.args.color.lstrip("#")
self.dbus.setpixel(z, i, int(col, 16))
sys.exit(0)
if (self.args.command == "load-conf"):
self.dbus.loadconf(self.args.path)
sys.exit(0)
if (self.args.command == "reload-conf"):
self.dbus.loadconf("")
sys.exit(0)
if (self.args.command == "deliver"):
self.dbus.deliver(self.args.zone, self.args.data)
sys.exit(0)
print(self.args)
self.parser.print_help()
sys.exit(1)
if (__name__ == "__main__"):
"""🦊🍑🍆💦😩"""
lctl = LightCTL()
lctl.get_args()
lctl.process_command()