-
Notifications
You must be signed in to change notification settings - Fork 0
/
lights_london_tom.py
61 lines (45 loc) · 1.71 KB
/
lights_london_tom.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
from bind import *
from settable_controller import SettableController
# from daylight_controller import DaylightController
from aggregator import Aggregator
from timer_controller import TimerController
from shet.path import join
from shet.client import ShetClient, shet_action
from twisted.internet import reactor
TimerController("/lights/override", 10*60, None).install()
# DaylightController("/lights/daylight", 53.46171, -2.217164).install()
Aggregator("/tom/light/backend", ["alarm", "override", "/lights/daylight", "timer"]).install()
SettableController("/tom/light/backend/override").install()
TimerController("/tom/light/backend/timer", 300, False).install()
TimerController("/tom/light/backend/alarm", 60 * 30, None).install()
EventToAction("/tom/arduino/pir", "/tom/light/backend/timer/on").install()
class Frontend(ShetClient):
root = "/tom/light"
def __init__(self):
ShetClient.__init__(self)
self.watch_event("backend/state_change", self.on_state_change)
self.set("/tom/arduino/light/fade_speed", 10)
def on_state_change(self, state):
self.call("/tom/arduino/light/fade", {False: 0, True: 255, None: 0}[state])
@shet_action
def on(self):
return self.call("backend/override/set_state", True)
@shet_action
def off(self):
return self.call("backend/override/set_state", False)
@shet_action
def auto(self):
return self.call("backend/override/set_state", None)
@shet_action
def leave(self):
self.call("backend/alarm/finish")
self.call("backend/override/set_state", None)
self.call("backend/timer/finish")
@shet_action
def wake_up(self):
return self.call("backend/alarm/on")
@shet_action
def end_alarm(self):
return self.call("backend/alarm/finish")
Frontend().install()
reactor.run()