-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhue
executable file
·105 lines (90 loc) · 3.16 KB
/
hue
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
from phue import Bridge
import sys, os
import json
from PhilipsHue import *
import argparse
class Hue(Lights, Groups, TimeRules):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def keys(self):
return list(self.conn.get_api().keys())
class main:
def __init__(self, *args, **kwargs):
self.TimeRules = TimeRules()
self.LoadSettings()
self.LoadArgs()
self.UpdateLights()
self.UpdateColor()
self()
def __call__(self, *args, **kwargs):
if self.color:
hue.SetColor(int(self.color), *self.lights)
elif self.on:
hue.LightsOn(*self.lights)
elif self.off:
hue.LightsOff(*self.lights)
elif self.switch:
hue.SwitchLight(*self.lights)
elif self.get_temperature:
print(*self.lights)
# Prints brightness of given light.
elif self.get_brightness:
for light in self.lights:
try:
print(f"{light}: {hue.GetBrightness(light)}")
except KeyError:
pass
elif self.dim:
hue.DimBrightness(self.dim, *self.lights)
elif self.increase:
hue.IncreaseBrightness(self.increase, *self.lights)
elif self.list:
for key, value in self.areas.items():
print(f"{key}: {value}")
else:
self.Auto()
def __setitem__(self, key, value):
if key in self.__dict__.keys():
print(f"{key} is a duplicate")
self.__dict__[key] = value
def Auto(self):
"""
Automatic rules based on TimeRules class in checktime.py.
Allows to execute main program with no arguments for estimated values of color temperature and brightness.
"""
for area, lights in self.areas.items():
for light in lights:
if self.TimeRules.brightness:
hue.LightsOn(light)
hue.SetColor(self.TimeRules.temperature, light)
hue.SetBrightness(self.TimeRules.brightness, light)
else:
hue.LightsOff(light)
def LoadSettings(self):
global hue
settingsfile = os.path.dirname(__file__) + "/PhilipsHue/settings.json"
settings = json.load(open(settingsfile, "r"))
for key, value in settings.items():
self[key] = value
hue = Hue(**settings)
def LoadArgs(self):
args = Arguments()
for key, value in args.data.items():
self[key] = value
def UpdateLights(self):
new = []
if "all" in self.__dict__.keys() and self.all:
for key, value in self.areas.items():
new.extend(value)
else:
if self.lights:
for i in range(len(self.lights)):
if self.lights[i] in self.areas.keys():
new.extend(self.areas[self.lights[i]])
self.lights = new
def UpdateColor(self):
if self.color in self.colors.keys():
self.color = self.colors[self.color]
if __name__ == "__main__":
main()