Преглед на файлове

function module restructured

tags/v1.0.0
Dirk Alders преди 2 години
родител
ревизия
3f5ecdeb64
променени са 5 файла, в които са добавени 381 реда и са изтрити 335 реда
  1. 3
    335
      function/__init__.py
  2. 196
    0
      function/first_floor_east.py
  3. 25
    0
      function/first_floor_west.py
  4. 51
    0
      function/ground_floor_west.py
  5. 106
    0
      function/rooms.py

+ 3
- 335
function/__init__.py Целия файл

@@ -1,10 +1,10 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: utf-8 -*-
3 3
 #
4
-import config
5 4
 import devices
6
-import inspect
7
-import logging
5
+from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk
6
+from function.first_floor_west import first_floor_west_julian, first_floor_west_living
7
+from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep_madi, first_floor_east_living
8 8
 
9 9
 # TODO: implement bed light dirk fading by input device
10 10
 # TODO: implement heating function sleep_madi
@@ -14,12 +14,6 @@ import logging
14 14
 # TODO: implement existing nodered functionality "dirk" (ground floor west)
15 15
 # TODO: implement warning message (incl. fixing all_functions.devicelist
16 16
 
17
-try:
18
-    from config import APP_NAME as ROOT_LOGGER_NAME
19
-except ImportError:
20
-    ROOT_LOGGER_NAME = 'root'
21
-logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
22
-
23 17
 
24 18
 class all_functions(object):
25 19
     def __init__(self, mqtt_client):
@@ -67,329 +61,3 @@ class all_functions(object):
67 61
                     if type(obj) in devices.DEVICE_TYPE_LIST():
68 62
                         self.__devices__.append(obj)
69 63
         return self.__devices__
70
-
71
-
72
-class room(object):
73
-    def gui_switch_feedback(self, device, key, data):
74
-        self.gui_switch_main_light.set_feedback(data)
75
-
76
-
77
-class room_shelly(room):
78
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
79
-        self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
80
-        #
81
-        self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
82
-        #
83
-        # Callback initialisation
84
-        #
85
-        self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
86
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_feedback)
87
-
88
-    def all_off(self):
89
-        self.main_light_shelly.set_output_0(False)
90
-        self.main_light_shelly.set_output_1(False)
91
-
92
-    def gui_switch_command(self, device, key, data):
93
-        logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
94
-        self.main_light_shelly.set_output_0(data)
95
-
96
-
97
-class room_shelly_tradfri_light(room_shelly):
98
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
99
-        super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
100
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic=topic_tradfri_light)
101
-        #
102
-        self.gui_brightness_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_brightness)
103
-        self.gui_brightness_main_light.enable(False)
104
-        self.gui_brightness_main_light.set_feedback(0)
105
-        self.gui_color_temp_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_color_temp)
106
-        self.gui_color_temp_main_light.enable(False)
107
-        self.gui_color_temp_main_light.set_feedback(0)
108
-        #
109
-        # Callback initialisation
110
-        #
111
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.enable_brightness_n_colortemp)
112
-        self.main_light_tradfri.add_callback(
113
-            devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_main_light)
114
-        self.main_light_tradfri.add_callback(
115
-            devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_main_light)
116
-        self.gui_brightness_main_light.add_callback(
117
-            devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_main_light)
118
-        self.gui_color_temp_main_light.add_callback(
119
-            devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_main_light)
120
-
121
-    def enable_brightness_n_colortemp(self, devive, key, data):
122
-        self.gui_brightness_main_light.enable(data)
123
-        self.gui_color_temp_main_light.enable(data)
124
-        if data is False:
125
-            self.gui_brightness_main_light.set_feedback(0)
126
-            self.gui_color_temp_main_light.set_feedback(0)
127
-        else:
128
-            self.gui_brightness_main_light.set_feedback(self.main_light_tradfri.brightness)
129
-            self.gui_color_temp_main_light.set_feedback(self.main_light_tradfri.color_temp / 10)
130
-
131
-    def set_gui_brightness_main_light(self, device, key, data):
132
-        self.gui_brightness_main_light.set_feedback(data)
133
-
134
-    def set_gui_color_temp_main_light(self, device, key, data):
135
-        self.gui_color_temp_main_light.set_feedback(data / 10)
136
-
137
-    def set_brightness_main_light(self, device, key, data):
138
-        logger.info("Setting brightness \"%s\" main light: %.1f", type(self).__name__, data)
139
-        self.main_light_tradfri.set_brightness(data)
140
-
141
-    def set_color_temp_main_light(self, device, key, data):
142
-        logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data)
143
-        self.main_light_tradfri.set_color_temp(data * 10)
144
-
145
-
146
-class room_shelly_silvercrest_light(room_shelly_tradfri_light):
147
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
148
-        super().__init__(mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp)
149
-        #
150
-        # Callback initialisation
151
-        #
152
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.get_initial_main_light_data)
153
-        #
154
-        self.main_light_shelly_last = None
155
-
156
-    def get_initial_main_light_data(self, device, key, data):
157
-        if data is True and self.main_light_shelly_last is not True:
158
-            self.send_init_message_main_light()
159
-        self.main_light_shelly_last = data
160
-
161
-    def send_init_message_main_light(self):
162
-        self.main_light_tradfri.mqtt_client.send(self.main_light_tradfri.topic + "/get", '{"state": ""}')
163
-
164
-
165
-class ground_floor_west_floor(room_shelly_silvercrest_light):
166
-    # https://shelly1l-84CCA8AD1148
167
-    def __init__(self, mqtt_client):
168
-        super().__init__(mqtt_client, "shellies/floor_eg_w", "gui/gfw_sw_floor",
169
-                         "zigbee_eg_w/light/floor_eg_w/a", "gui/gfw_br_floor", "gui/gfw_ct_floor")
170
-        #
171
-        # Callback initialisation
172
-        #
173
-        self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/floor_eg_w/b")
174
-        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS,
175
-                                             None, self.sync_brightness_main_light)
176
-        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP,
177
-                                             None, self.sync_color_temp_main_light)
178
-
179
-    def send_init_message_main_light(self):
180
-        return super().send_init_message_main_light()
181
-        self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}')
182
-
183
-    def sync_brightness_main_light(self, device, key, data):
184
-        self.main_light_tradfri_2.set_brightness(data)
185
-
186
-    def sync_color_temp_main_light(self, device, key, data):
187
-        self.main_light_tradfri_2.set_color_temp(data)
188
-
189
-
190
-class ground_floor_west_marion(room_shelly):
191
-    # https://shelly1l-E8DB84A1E067
192
-    def __init__(self, mqtt_client):
193
-        super().__init__(mqtt_client, "shellies/marion", "gui/gfw_sw_marion")
194
-
195
-
196
-class ground_floor_west_dirk(room_shelly_tradfri_light):
197
-    # https://shelly1l-3C6105E44F27
198
-    def __init__(self, mqtt_client):
199
-        super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_dirk",
200
-                         "zigbee_eg_w/light/dirk", "gui/gfw_br_dirk", "gui/gfw_ct_dirk")
201
-
202
-
203
-class first_floor_west_julian(room_shelly_tradfri_light):
204
-    # http://shelly1l-3C6105E43452
205
-    def __init__(self, mqtt_client):
206
-        super().__init__(mqtt_client, "shellies/julian", "gui/ffw_sw_julian",
207
-                         "zigbee_og_e/light/julian", "gui/ffw_br_julian", "gui/ffw_ct_julian")
208
-
209
-
210
-class first_floor_west_living(room_shelly):
211
-    # http://shelly1l-84CCA8ACE6A1
212
-    def __init__(self, mqtt_client):
213
-        super().__init__(mqtt_client, "shellies/living_mika", "gui/ffw_sw_living")
214
-
215
-
216
-class first_floor_east_floor(room_shelly):
217
-    def __init__(self, mqtt_client):
218
-        # http://shelly1l-3C6105E4E629
219
-        super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
220
-
221
-    def toggle_main_light(self, device, key, data):
222
-        logger.info("Toggeling \"%s\" main light", type(self).__name__)
223
-        self.main_light_shelly.set_output_0("toggle")
224
-
225
-
226
-class first_floor_east_kitchen(room_shelly):
227
-    # TODO: add circulation pump (switch, time)
228
-    def __init__(self, mqtt_client):
229
-        # http://shelly1l-8CAAB5616C01
230
-        super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_sw_kitchen")
231
-
232
-
233
-class first_floor_east_dining(room_shelly):
234
-    def __init__(self, mqtt_client):
235
-        # http://shelly1l-84CCA8ADD055
236
-        super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_sw_diningroom")
237
-        self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp")
238
-        if config.CHRISTMAS:
239
-            self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux")
240
-        #
241
-        self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_dining_floorlamp")
242
-        #
243
-        # Callback initialisation
244
-        #
245
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
246
-        self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
247
-        self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0,
248
-                                              None, self.gui_switch_feedback_floorlamp)
249
-        #
250
-        self.main_light_shelly_last = None
251
-
252
-    def floorlamp_synchronisation(self, device, key, data):
253
-        if data != self.main_light_shelly_last:
254
-            logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
255
-            self.floorlamp_powerplug.set_output_0(data)
256
-        self.main_light_shelly_last = data
257
-
258
-    def gui_switch_command_floorlamp(self, device, key, data):
259
-        logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
260
-        self.floorlamp_powerplug.set_output_0(data)
261
-
262
-    def gui_switch_feedback_floorlamp(self, device, key, data):
263
-        self.gui_switch_floorlamp.set_feedback(data)
264
-
265
-
266
-class first_floor_east_sleep_madi(room_shelly_tradfri_light):
267
-    def __init__(self, mqtt_client):
268
-        # http://shelly1l-E8DB84A254C7
269
-        super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sw_sleep_madi",
270
-                         "zigbee_og_e/light/sleep_madi", "gui/ffe_br_sleep_madi", "gui/ffe_ct_sleep_madi")
271
-        #
272
-        self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di")
273
-        #
274
-        self.gui_switch_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_sw_bed_light_di")
275
-        self.gui_brightness_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_br_bed_light_di")
276
-        self.gui_brightness_bed_light_di.enable(False)
277
-        self.gui_brightness_bed_light_di.set_feedback(0)
278
-        #
279
-        # Callback initialisation
280
-        #
281
-        self.gui_switch_bed_light_di.add_callback(
282
-            devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
283
-        self.bed_light_di_tradfri.add_callback(
284
-            devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_bed_light_di)
285
-        self.bed_light_di_tradfri.add_callback(
286
-            devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
287
-        self.gui_brightness_bed_light_di.add_callback(
288
-            devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
289
-
290
-    def toggle_main_light(self, device, key, data):
291
-        logger.info("Toggeling \"%s\" main light", type(self).__name__)
292
-        self.main_light_shelly.set_output_0("toggle")
293
-
294
-    def gui_switch_command_bed_light_di(self, device, key, data):
295
-        logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
296
-        self.bed_light_di_tradfri.set_output_0(data)
297
-
298
-    def gui_switch_feedback_bed_light_di(self, device, key, data):
299
-        self.gui_switch_bed_light_di.set_feedback(data)
300
-        self.gui_brightness_bed_light_di.enable(data)
301
-        if data is False:
302
-            self.gui_brightness_bed_light_di.set_feedback(0)
303
-        else:
304
-            self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
305
-
306
-    def set_gui_brightness_bed_light_di(self, device, key, data):
307
-        self.gui_brightness_bed_light_di.set_feedback(data)
308
-
309
-    def set_brightness_bed_light_di(self, device, key, data):
310
-        logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
311
-        self.bed_light_di_tradfri.set_brightness(data)
312
-
313
-    def toggle_bed_light_di(self, device, key, data):
314
-        logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
315
-        self.bed_light_di_tradfri.set_output_0("toggle")
316
-
317
-
318
-class first_floor_east_living(room_shelly_tradfri_light):
319
-    def __init__(self, mqtt_client):
320
-        # http://shelly1l-3C6105E3F910
321
-        super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_sw_livingroom",
322
-                         "zigbee_og_e/light/livingroom", "gui/ffe_br_livingroom", "gui/ffe_ct_livingroom")
323
-        for i in range(1, 7):
324
-            setattr(self, 'floorlamp_tradfri_%d' % i,
325
-                    devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i))
326
-        #
327
-        self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_living_floorlamp")
328
-        self.gui_brightness_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_br_livingroom_floorlamp")
329
-        self.gui_brightness_floorlamp.enable(False)
330
-        self.gui_brightness_floorlamp.set_feedback(0)
331
-        self.gui_color_temp_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_ct_livingroom_floorlamp")
332
-        self.gui_color_temp_floorlamp.enable(False)
333
-        self.gui_color_temp_floorlamp.set_feedback(0)
334
-        #
335
-        # Callback initialisation
336
-        #
337
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
338
-        self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
339
-        self.floorlamp_tradfri_1.add_callback(
340
-            devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_floorlamp)
341
-        self.floorlamp_tradfri_1.add_callback(
342
-            devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_floorlamp)
343
-        self.floorlamp_tradfri_1.add_callback(
344
-            devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_floorlamp)
345
-        self.gui_brightness_floorlamp.add_callback(
346
-            devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_floorlamp)
347
-        self.gui_color_temp_floorlamp.add_callback(
348
-            devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp)
349
-        #
350
-        self.main_light_shelly_last = None
351
-
352
-    def __floorlamp_devices__(self):
353
-        rv = []
354
-        for i in range(1, 7):
355
-            rv.append(getattr(self, 'floorlamp_tradfri_%d' % i))
356
-        return rv
357
-
358
-    def floorlamp_synchronisation(self, device, key, data):
359
-        if data != self.main_light_shelly_last:
360
-            logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
361
-            for device in self.__floorlamp_devices__():
362
-                device.set_output_0(data)
363
-        self.main_light_shelly_last = data
364
-
365
-    def gui_switch_command_floorlamp(self, device, key, data):
366
-        logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
367
-        for device in self.__floorlamp_devices__():
368
-            device.set_output_0(data)
369
-
370
-    def gui_switch_feedback_floorlamp(self, device, key, data):
371
-        self.gui_switch_floorlamp.set_feedback(data)
372
-        self.gui_brightness_floorlamp.enable(data)
373
-        self.gui_color_temp_floorlamp.enable(data)
374
-        if data is False:
375
-            self.gui_brightness_floorlamp.set_feedback(0)
376
-            self.gui_color_temp_floorlamp.set_feedback(0)
377
-        else:
378
-            self.gui_brightness_floorlamp.set_feedback(self.floorlamp_tradfri_1.brightness)
379
-            self.gui_color_temp_floorlamp.set_feedback(self.floorlamp_tradfri_1.color_temp / 10)
380
-
381
-    def set_gui_brightness_floorlamp(self, device, key, data):
382
-        self.gui_brightness_floorlamp.set_feedback(data)
383
-
384
-    def set_gui_color_temp_floorlamp(self, device, key, data):
385
-        self.gui_color_temp_floorlamp.set_feedback(data / 10)
386
-
387
-    def set_brightness_floorlamp(self, device, key, data):
388
-        logger.info("Setting brightness \"%s\" floorlamp: %.1f", type(self).__name__, data)
389
-        for device in self.__floorlamp_devices__():
390
-            device.set_brightness(data)
391
-
392
-    def set_color_temp_floorlamp(self, device, key, data):
393
-        logger.info("Setting color_temp \"%s\" floorlamp: %.1f", type(self).__name__, data)
394
-        for device in self.__floorlamp_devices__():
395
-            device.set_color_temp(data * 10)

+ 196
- 0
function/first_floor_east.py Целия файл

@@ -0,0 +1,196 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+
5
+import config
6
+import devices
7
+import logging
8
+from function.rooms import room_shelly, room_shelly_tradfri_light
9
+
10
+try:
11
+    from config import APP_NAME as ROOT_LOGGER_NAME
12
+except ImportError:
13
+    ROOT_LOGGER_NAME = 'root'
14
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
15
+
16
+
17
+class first_floor_east_floor(room_shelly):
18
+    def __init__(self, mqtt_client):
19
+        # http://shelly1l-3C6105E4E629
20
+        super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
21
+
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
+
27
+class first_floor_east_kitchen(room_shelly):
28
+    # TODO: add circulation pump (switch, time)
29
+    def __init__(self, mqtt_client):
30
+        # http://shelly1l-8CAAB5616C01
31
+        super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_sw_kitchen")
32
+
33
+
34
+class first_floor_east_dining(room_shelly):
35
+    def __init__(self, mqtt_client):
36
+        # http://shelly1l-84CCA8ADD055
37
+        super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_sw_diningroom")
38
+        self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp")
39
+        if config.CHRISTMAS:
40
+            self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux")
41
+        #
42
+        self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_dining_floorlamp")
43
+        #
44
+        # Callback initialisation
45
+        #
46
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
47
+        self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
48
+        self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0,
49
+                                              None, self.gui_switch_feedback_floorlamp)
50
+        #
51
+        self.main_light_shelly_last = None
52
+
53
+    def floorlamp_synchronisation(self, device, key, data):
54
+        if data != self.main_light_shelly_last:
55
+            logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
56
+            self.floorlamp_powerplug.set_output_0(data)
57
+        self.main_light_shelly_last = data
58
+
59
+    def gui_switch_command_floorlamp(self, device, key, data):
60
+        logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
61
+        self.floorlamp_powerplug.set_output_0(data)
62
+
63
+    def gui_switch_feedback_floorlamp(self, device, key, data):
64
+        self.gui_switch_floorlamp.set_feedback(data)
65
+
66
+
67
+class first_floor_east_sleep_madi(room_shelly_tradfri_light):
68
+    def __init__(self, mqtt_client):
69
+        # http://shelly1l-E8DB84A254C7
70
+        super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sw_sleep_madi",
71
+                         "zigbee_og_e/light/sleep_madi", "gui/ffe_br_sleep_madi", "gui/ffe_ct_sleep_madi")
72
+        #
73
+        self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di")
74
+        #
75
+        self.gui_switch_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_sw_bed_light_di")
76
+        self.gui_brightness_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_br_bed_light_di")
77
+        self.gui_brightness_bed_light_di.enable(False)
78
+        self.gui_brightness_bed_light_di.set_feedback(0)
79
+        #
80
+        # Callback initialisation
81
+        #
82
+        self.gui_switch_bed_light_di.add_callback(
83
+            devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
84
+        self.bed_light_di_tradfri.add_callback(
85
+            devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_bed_light_di)
86
+        self.bed_light_di_tradfri.add_callback(
87
+            devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
88
+        self.gui_brightness_bed_light_di.add_callback(
89
+            devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
90
+
91
+    def toggle_main_light(self, device, key, data):
92
+        logger.info("Toggeling \"%s\" main light", type(self).__name__)
93
+        self.main_light_shelly.set_output_0("toggle")
94
+
95
+    def gui_switch_command_bed_light_di(self, device, key, data):
96
+        logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
97
+        self.bed_light_di_tradfri.set_output_0(data)
98
+
99
+    def gui_switch_feedback_bed_light_di(self, device, key, data):
100
+        self.gui_switch_bed_light_di.set_feedback(data)
101
+        self.gui_brightness_bed_light_di.enable(data)
102
+        if data is False:
103
+            self.gui_brightness_bed_light_di.set_feedback(0)
104
+        else:
105
+            self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
106
+
107
+    def set_gui_brightness_bed_light_di(self, device, key, data):
108
+        self.gui_brightness_bed_light_di.set_feedback(data)
109
+
110
+    def set_brightness_bed_light_di(self, device, key, data):
111
+        logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
112
+        self.bed_light_di_tradfri.set_brightness(data)
113
+
114
+    def toggle_bed_light_di(self, device, key, data):
115
+        logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
116
+        self.bed_light_di_tradfri.set_output_0("toggle")
117
+
118
+
119
+class first_floor_east_living(room_shelly_tradfri_light):
120
+    def __init__(self, mqtt_client):
121
+        # http://shelly1l-3C6105E3F910
122
+        super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_sw_livingroom",
123
+                         "zigbee_og_e/light/livingroom", "gui/ffe_br_livingroom", "gui/ffe_ct_livingroom")
124
+        for i in range(1, 7):
125
+            setattr(self, 'floorlamp_tradfri_%d' % i,
126
+                    devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i))
127
+        #
128
+        self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_living_floorlamp")
129
+        self.gui_brightness_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_br_livingroom_floorlamp")
130
+        self.gui_brightness_floorlamp.enable(False)
131
+        self.gui_brightness_floorlamp.set_feedback(0)
132
+        self.gui_color_temp_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_ct_livingroom_floorlamp")
133
+        self.gui_color_temp_floorlamp.enable(False)
134
+        self.gui_color_temp_floorlamp.set_feedback(0)
135
+        #
136
+        # Callback initialisation
137
+        #
138
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
139
+        self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
140
+        self.floorlamp_tradfri_1.add_callback(
141
+            devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_floorlamp)
142
+        self.floorlamp_tradfri_1.add_callback(
143
+            devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_floorlamp)
144
+        self.floorlamp_tradfri_1.add_callback(
145
+            devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_floorlamp)
146
+        self.gui_brightness_floorlamp.add_callback(
147
+            devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_floorlamp)
148
+        self.gui_color_temp_floorlamp.add_callback(
149
+            devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp)
150
+        #
151
+        self.main_light_shelly_last = None
152
+
153
+    def __floorlamp_devices__(self):
154
+        rv = []
155
+        for i in range(1, 7):
156
+            rv.append(getattr(self, 'floorlamp_tradfri_%d' % i))
157
+        return rv
158
+
159
+    def floorlamp_synchronisation(self, device, key, data):
160
+        if data != self.main_light_shelly_last:
161
+            logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
162
+            for device in self.__floorlamp_devices__():
163
+                device.set_output_0(data)
164
+        self.main_light_shelly_last = data
165
+
166
+    def gui_switch_command_floorlamp(self, device, key, data):
167
+        logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
168
+        for device in self.__floorlamp_devices__():
169
+            device.set_output_0(data)
170
+
171
+    def gui_switch_feedback_floorlamp(self, device, key, data):
172
+        self.gui_switch_floorlamp.set_feedback(data)
173
+        self.gui_brightness_floorlamp.enable(data)
174
+        self.gui_color_temp_floorlamp.enable(data)
175
+        if data is False:
176
+            self.gui_brightness_floorlamp.set_feedback(0)
177
+            self.gui_color_temp_floorlamp.set_feedback(0)
178
+        else:
179
+            self.gui_brightness_floorlamp.set_feedback(self.floorlamp_tradfri_1.brightness)
180
+            self.gui_color_temp_floorlamp.set_feedback(self.floorlamp_tradfri_1.color_temp / 10)
181
+
182
+    def set_gui_brightness_floorlamp(self, device, key, data):
183
+        self.gui_brightness_floorlamp.set_feedback(data)
184
+
185
+    def set_gui_color_temp_floorlamp(self, device, key, data):
186
+        self.gui_color_temp_floorlamp.set_feedback(data / 10)
187
+
188
+    def set_brightness_floorlamp(self, device, key, data):
189
+        logger.info("Setting brightness \"%s\" floorlamp: %.1f", type(self).__name__, data)
190
+        for device in self.__floorlamp_devices__():
191
+            device.set_brightness(data)
192
+
193
+    def set_color_temp_floorlamp(self, device, key, data):
194
+        logger.info("Setting color_temp \"%s\" floorlamp: %.1f", type(self).__name__, data)
195
+        for device in self.__floorlamp_devices__():
196
+            device.set_color_temp(data * 10)

+ 25
- 0
function/first_floor_west.py Целия файл

@@ -0,0 +1,25 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+
5
+import logging
6
+from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
7
+
8
+try:
9
+    from config import APP_NAME as ROOT_LOGGER_NAME
10
+except ImportError:
11
+    ROOT_LOGGER_NAME = 'root'
12
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
13
+
14
+
15
+class first_floor_west_julian(room_shelly_tradfri_light):
16
+    # http://shelly1l-3C6105E43452
17
+    def __init__(self, mqtt_client):
18
+        super().__init__(mqtt_client, "shellies/julian", "gui/ffw_sw_julian",
19
+                         "zigbee_og_e/light/julian", "gui/ffw_br_julian", "gui/ffw_ct_julian")
20
+
21
+
22
+class first_floor_west_living(room_shelly):
23
+    # http://shelly1l-84CCA8ACE6A1
24
+    def __init__(self, mqtt_client):
25
+        super().__init__(mqtt_client, "shellies/living_mika", "gui/ffw_sw_living")

+ 51
- 0
function/ground_floor_west.py Целия файл

@@ -0,0 +1,51 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+
5
+import devices
6
+import logging
7
+from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
8
+
9
+try:
10
+    from config import APP_NAME as ROOT_LOGGER_NAME
11
+except ImportError:
12
+    ROOT_LOGGER_NAME = 'root'
13
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
14
+
15
+
16
+class ground_floor_west_floor(room_shelly_silvercrest_light):
17
+    # https://shelly1l-84CCA8AD1148
18
+    def __init__(self, mqtt_client):
19
+        super().__init__(mqtt_client, "shellies/floor_eg_w", "gui/gfw_sw_floor",
20
+                         "zigbee_eg_w/light/floor_eg_w/a", "gui/gfw_br_floor", "gui/gfw_ct_floor")
21
+        #
22
+        # Callback initialisation
23
+        #
24
+        self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/floor_eg_w/b")
25
+        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS,
26
+                                             None, self.sync_brightness_main_light)
27
+        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP,
28
+                                             None, self.sync_color_temp_main_light)
29
+
30
+    def send_init_message_main_light(self):
31
+        return super().send_init_message_main_light()
32
+        self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}')
33
+
34
+    def sync_brightness_main_light(self, device, key, data):
35
+        self.main_light_tradfri_2.set_brightness(data)
36
+
37
+    def sync_color_temp_main_light(self, device, key, data):
38
+        self.main_light_tradfri_2.set_color_temp(data)
39
+
40
+
41
+class ground_floor_west_marion(room_shelly):
42
+    # https://shelly1l-E8DB84A1E067
43
+    def __init__(self, mqtt_client):
44
+        super().__init__(mqtt_client, "shellies/marion", "gui/gfw_sw_marion")
45
+
46
+
47
+class ground_floor_west_dirk(room_shelly_tradfri_light):
48
+    # https://shelly1l-3C6105E44F27
49
+    def __init__(self, mqtt_client):
50
+        super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_dirk",
51
+                         "zigbee_eg_w/light/dirk", "gui/gfw_br_dirk", "gui/gfw_ct_dirk")

+ 106
- 0
function/rooms.py Целия файл

@@ -0,0 +1,106 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+
5
+import config
6
+import devices
7
+import logging
8
+
9
+try:
10
+    from config import APP_NAME as ROOT_LOGGER_NAME
11
+except ImportError:
12
+    ROOT_LOGGER_NAME = 'root'
13
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
14
+
15
+
16
+class room(object):
17
+    def gui_switch_feedback(self, device, key, data):
18
+        self.gui_switch_main_light.set_feedback(data)
19
+
20
+
21
+class room_shelly(room):
22
+    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
23
+        self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
24
+        #
25
+        self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
26
+        #
27
+        # Callback initialisation
28
+        #
29
+        self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
30
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_feedback)
31
+
32
+    def all_off(self):
33
+        self.main_light_shelly.set_output_0(False)
34
+        self.main_light_shelly.set_output_1(False)
35
+
36
+    def gui_switch_command(self, device, key, data):
37
+        logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
38
+        self.main_light_shelly.set_output_0(data)
39
+
40
+
41
+class room_shelly_tradfri_light(room_shelly):
42
+    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
43
+        super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
44
+        self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic=topic_tradfri_light)
45
+        #
46
+        self.gui_brightness_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_brightness)
47
+        self.gui_brightness_main_light.enable(False)
48
+        self.gui_brightness_main_light.set_feedback(0)
49
+        self.gui_color_temp_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_color_temp)
50
+        self.gui_color_temp_main_light.enable(False)
51
+        self.gui_color_temp_main_light.set_feedback(0)
52
+        #
53
+        # Callback initialisation
54
+        #
55
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.enable_brightness_n_colortemp)
56
+        self.main_light_tradfri.add_callback(
57
+            devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_main_light)
58
+        self.main_light_tradfri.add_callback(
59
+            devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_main_light)
60
+        self.gui_brightness_main_light.add_callback(
61
+            devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_main_light)
62
+        self.gui_color_temp_main_light.add_callback(
63
+            devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_main_light)
64
+
65
+    def enable_brightness_n_colortemp(self, devive, key, data):
66
+        self.gui_brightness_main_light.enable(data)
67
+        self.gui_color_temp_main_light.enable(data)
68
+        if data is False:
69
+            self.gui_brightness_main_light.set_feedback(0)
70
+            self.gui_color_temp_main_light.set_feedback(0)
71
+        else:
72
+            self.gui_brightness_main_light.set_feedback(self.main_light_tradfri.brightness)
73
+            self.gui_color_temp_main_light.set_feedback(self.main_light_tradfri.color_temp / 10)
74
+
75
+    def set_gui_brightness_main_light(self, device, key, data):
76
+        self.gui_brightness_main_light.set_feedback(data)
77
+
78
+    def set_gui_color_temp_main_light(self, device, key, data):
79
+        self.gui_color_temp_main_light.set_feedback(data / 10)
80
+
81
+    def set_brightness_main_light(self, device, key, data):
82
+        logger.info("Setting brightness \"%s\" main light: %.1f", type(self).__name__, data)
83
+        self.main_light_tradfri.set_brightness(data)
84
+
85
+    def set_color_temp_main_light(self, device, key, data):
86
+        logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data)
87
+        self.main_light_tradfri.set_color_temp(data * 10)
88
+
89
+
90
+class room_shelly_silvercrest_light(room_shelly_tradfri_light):
91
+    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
92
+        super().__init__(mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp)
93
+        #
94
+        # Callback initialisation
95
+        #
96
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.get_initial_main_light_data)
97
+        #
98
+        self.main_light_shelly_last = None
99
+
100
+    def get_initial_main_light_data(self, device, key, data):
101
+        if data is True and self.main_light_shelly_last is not True:
102
+            self.send_init_message_main_light()
103
+        self.main_light_shelly_last = data
104
+
105
+    def send_init_message_main_light(self):
106
+        self.main_light_tradfri.mqtt_client.send(self.main_light_tradfri.topic + "/get", '{"state": ""}')

Loading…
Отказ
Запис