|
@@ -4,6 +4,7 @@
|
4
|
4
|
|
5
|
5
|
import config
|
6
|
6
|
import devices
|
|
7
|
+import json
|
7
|
8
|
import logging
|
8
|
9
|
from function.rooms import room_shelly, room_shelly_tradfri_light
|
9
|
10
|
|
|
@@ -19,10 +20,6 @@ class first_floor_east_floor(room_shelly):
|
19
|
20
|
# http://shelly1l-3C6105E4E629
|
20
|
21
|
super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
|
21
|
22
|
|
22
|
|
- def toggle_main_light(self, device, key, data):
|
23
|
|
- logger.info("Toggeling \"%s\" main light", type(self).__name__)
|
24
|
|
- self.main_light_shelly.set_output_0("toggle")
|
25
|
|
-
|
26
|
23
|
|
27
|
24
|
class first_floor_east_kitchen(room_shelly):
|
28
|
25
|
# TODO: add circulation pump (switch, time)
|
|
@@ -79,6 +76,11 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
|
79
|
76
|
#
|
80
|
77
|
# Callback initialisation
|
81
|
78
|
#
|
|
79
|
+ self.init_bed_light_functions()
|
|
80
|
+ self.init_fade_function()
|
|
81
|
+
|
|
82
|
+ # bed light
|
|
83
|
+ def init_bed_light_functions(self):
|
82
|
84
|
self.gui_switch_bed_light_di.add_callback(
|
83
|
85
|
devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
|
84
|
86
|
self.bed_light_di_tradfri.add_callback(
|
|
@@ -87,17 +89,38 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
|
87
|
89
|
devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
|
88
|
90
|
self.gui_brightness_bed_light_di.add_callback(
|
89
|
91
|
devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
|
90
|
|
- #
|
|
92
|
+
|
|
93
|
+ def gui_switch_command_bed_light_di(self, device, key, data):
|
|
94
|
+ logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
|
|
95
|
+ self.bed_light_di_tradfri.set_output_0(data)
|
|
96
|
+
|
|
97
|
+ def gui_switch_feedback_bed_light_di(self, device, key, data):
|
|
98
|
+ self.gui_switch_bed_light_di.set_feedback(data)
|
|
99
|
+ self.gui_brightness_bed_light_di.enable(data)
|
|
100
|
+ if data is False:
|
|
101
|
+ self.gui_brightness_bed_light_di.set_feedback(0)
|
|
102
|
+ else:
|
|
103
|
+ self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
|
|
104
|
+
|
|
105
|
+ def set_gui_brightness_bed_light_di(self, device, key, data):
|
|
106
|
+ self.gui_brightness_bed_light_di.set_feedback(data)
|
|
107
|
+
|
|
108
|
+ def set_brightness_bed_light_di(self, device, key, data):
|
|
109
|
+ logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
|
|
110
|
+ self.bed_light_di_tradfri.set_brightness(data)
|
|
111
|
+
|
|
112
|
+ def toggle_bed_light_di(self, device, key, data):
|
|
113
|
+ logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
|
|
114
|
+ self.bed_light_di_tradfri.set_output_0("toggle")
|
|
115
|
+
|
|
116
|
+ # fade
|
|
117
|
+ def init_fade_function(self):
|
91
|
118
|
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
|
92
|
119
|
self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
|
93
|
120
|
None, self.state_machine_last_activated_device)
|
94
|
121
|
#
|
95
|
122
|
self.last_activated_device = None
|
96
|
123
|
|
97
|
|
- def toggle_main_light(self, device, key, data):
|
98
|
|
- logger.info("Toggeling \"%s\" main light", type(self).__name__)
|
99
|
|
- self.main_light_shelly.set_output_0("toggle")
|
100
|
|
-
|
101
|
124
|
def state_machine_last_activated_device(self, device, topic, data):
|
102
|
125
|
if data is True:
|
103
|
126
|
self.last_activated_device = device.topic
|
|
@@ -108,6 +131,10 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
|
108
|
131
|
self.last_activated_device = self.main_light_shelly.topic
|
109
|
132
|
else:
|
110
|
133
|
self.last_activated_device = None
|
|
134
|
+ self.mqtt_client.send("gui/ffe_led_main_light_sleep/set",
|
|
135
|
+ json.dumps(self.last_activated_device == self.main_light_shelly.topic))
|
|
136
|
+ self.mqtt_client.send("gui/ffe_led_bed_light_sleep_di/set",
|
|
137
|
+ json.dumps(self.last_activated_device == self.bed_light_di_tradfri.topic))
|
111
|
138
|
|
112
|
139
|
def fade_light(self, device, topic, data):
|
113
|
140
|
if self.last_activated_device == self.main_light_shelly.topic:
|
|
@@ -126,29 +153,6 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
|
126
|
153
|
logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
|
127
|
154
|
target.brightness_stop()
|
128
|
155
|
|
129
|
|
- def gui_switch_command_bed_light_di(self, device, key, data):
|
130
|
|
- logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
|
131
|
|
- self.bed_light_di_tradfri.set_output_0(data)
|
132
|
|
-
|
133
|
|
- def gui_switch_feedback_bed_light_di(self, device, key, data):
|
134
|
|
- self.gui_switch_bed_light_di.set_feedback(data)
|
135
|
|
- self.gui_brightness_bed_light_di.enable(data)
|
136
|
|
- if data is False:
|
137
|
|
- self.gui_brightness_bed_light_di.set_feedback(0)
|
138
|
|
- else:
|
139
|
|
- self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
|
140
|
|
-
|
141
|
|
- def set_gui_brightness_bed_light_di(self, device, key, data):
|
142
|
|
- self.gui_brightness_bed_light_di.set_feedback(data)
|
143
|
|
-
|
144
|
|
- def set_brightness_bed_light_di(self, device, key, data):
|
145
|
|
- logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
|
146
|
|
- self.bed_light_di_tradfri.set_brightness(data)
|
147
|
|
-
|
148
|
|
- def toggle_bed_light_di(self, device, key, data):
|
149
|
|
- logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
|
150
|
|
- self.bed_light_di_tradfri.set_output_0("toggle")
|
151
|
|
-
|
152
|
156
|
|
153
|
157
|
class first_floor_east_living(room_shelly_tradfri_light):
|
154
|
158
|
def __init__(self, mqtt_client):
|