Przeglądaj źródła

videv implementation for lights

tags/v1.0.0
Dirk Alders 1 rok temu
rodzic
commit
9233468a49

+ 45
- 0
base.py Wyświetl plik

@@ -0,0 +1,45 @@
1
+import logging
2
+
3
+try:
4
+    from config import APP_NAME as ROOT_LOGGER_NAME
5
+except ImportError:
6
+    ROOT_LOGGER_NAME = 'root'
7
+
8
+
9
+class common_base(dict):
10
+    DEFAULT_VALUES = {}
11
+
12
+    def __init__(self):
13
+        super().__init__(self.DEFAULT_VALUES)
14
+        self['__type__'] = self.__class__.__name__
15
+        #
16
+        self.__callback_list__ = []
17
+        self.logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
18
+
19
+    def add_callback(self, key, data, callback, on_change_only=True):
20
+        """
21
+        key: key or None for all keys
22
+        data: data or None for all data
23
+        """
24
+        cb_tup = (key, data, callback, on_change_only)
25
+        if cb_tup not in self.__callback_list__:
26
+            self.__callback_list__.append(cb_tup)
27
+
28
+    def set(self, key, data):
29
+        value_changed = self[key] != data
30
+        self[key] = data
31
+        for cb_key, cb_data, callback, on_change_only in self.__callback_list__:
32
+            if cb_key is None or key == cb_key:                 # key fits to callback definition
33
+                if cb_data is None or cb_data == self[key]:     # data fits to callback definition
34
+                    if value_changed or not on_change_only:     # change status fits to callback definition
35
+                        callback(self, key, self[key])
36
+
37
+
38
+class mqtt_base(common_base):
39
+    def __init__(self, mqtt_client, topic):
40
+        super().__init__()
41
+        #
42
+        self.mqtt_client = mqtt_client
43
+        self.topic = topic
44
+        for entry in self.topic.split('/'):
45
+            self.logger = self.logger.getChild(entry)

+ 5
- 0
devices/__init__.py Wyświetl plik

@@ -26,6 +26,8 @@ devices (DEVICES)
26 26
 
27 27
 """
28 28
 
29
+# TODO: Usage of mqtt_base for all devices
30
+
29 31
 __DEPENDENCIES__ = []
30 32
 
31 33
 import json
@@ -506,6 +508,9 @@ class tradfri_light(base):
506 508
         else:
507 509
             return super().pack_filter(key, data)
508 510
 
511
+    def request_data(self):
512
+        self.mqtt_client.send(self.topic + "/get", '{%s: ""}' % self.KEY_OUTPUT_0)
513
+
509 514
     #
510 515
     # RX
511 516
     #

+ 58
- 0
function/first_floor_east.py Wyświetl plik

@@ -7,6 +7,7 @@ import devices
7 7
 from function.modules import brightness_choose_n_action, circulation_pump, radiator_function
8 8
 import logging
9 9
 from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
10
+from function.videv import videv_switching, videv_switch_brightness, videv_switch_brightness_color_temp
10 11
 try:
11 12
     from config import APP_NAME as ROOT_LOGGER_NAME
12 13
 except ImportError:
@@ -18,6 +19,11 @@ class first_floor_east_floor(room_shelly):
18 19
     def __init__(self, mqtt_client):
19 20
         # http://shelly1l-3C6105E4E629
20 21
         super().__init__(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI)
22
+        #
23
+        self.main_light = videv_switching(
24
+            mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
25
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
26
+        )
21 27
 
22 28
 
23 29
 class first_floor_east_kitchen(room_shelly):
@@ -27,6 +33,15 @@ class first_floor_east_kitchen(room_shelly):
27 33
         #
28 34
         self.circulation_pump = circulation_pump(mqtt_client)
29 35
         self.circulation_pump.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.flash_main_light)
36
+        #
37
+        self.main_light_videv = videv_switching(
38
+            mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
39
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
40
+        )
41
+        self.circulation_pump_videv = videv_switching(
42
+            mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
43
+            self.circulation_pump.main_light_shelly, devices.shelly.KEY_OUTPUT_0
44
+        )
30 45
 
31 46
     def all_off(self, device=None, key=None, data=None):
32 47
         self.circulation_pump.all_off(device, key, data)
@@ -48,6 +63,15 @@ class first_floor_east_dining(room_shelly):
48 63
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
49 64
         self.gui_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.floorlamp_powerplug.set_output_0_mcb)
50 65
         self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
66
+        #
67
+        self.main_light_videv = videv_switching(
68
+            mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
69
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
70
+        )
71
+        self.floorlamp_videv = videv_switching(
72
+            mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
73
+            self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
74
+        )
51 75
 
52 76
     def all_off(self, device=None, key=None, data=None):
53 77
         super().all_off(device, key, data)
@@ -96,6 +120,22 @@ class first_floor_east_sleep(room_shelly_tradfri_light):
96 120
         self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.bed_light_di_tradfri.set_brightness_mcb)
97 121
         self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
98 122
         self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_bed_light_di.set_brightness_mcb)
123
+        #
124
+        self.main_light_videv = videv_switch_brightness_color_temp(
125
+            mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
126
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
127
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
128
+            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
129
+        )
130
+        self.bed_light_di_videv = videv_switch_brightness(
131
+            mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
132
+            self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
133
+            self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
134
+        )
135
+        self.bed_light_ma_videv = videv_switching(
136
+            mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
137
+            self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
138
+        )
99 139
 
100 140
     def all_off(self, device=None, key=None, data=None):
101 141
         super().all_off(device, key, data)
@@ -139,6 +179,24 @@ class first_floor_east_living(room_shelly_tradfri_light):
139 179
             self.gui_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
140 180
             #
141 181
             self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
182
+        #
183
+        self.main_light_videv = videv_switch_brightness_color_temp(
184
+            mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
185
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
186
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
187
+            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
188
+        )
189
+        self.floorlamp_videv = videv_switch_brightness_color_temp(
190
+            mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
191
+            self.floorlamp_tradfri_1, devices.tradfri_light.KEY_OUTPUT_0,
192
+            self.floorlamp_tradfri_1, devices.tradfri_light.KEY_BRIGHTNESS,
193
+            self.floorlamp_tradfri_1, devices.tradfri_light.KEY_COLOR_TEMP
194
+        )
195
+        if config.CHRISTMAS:
196
+            self.xmas_tree_videv = videv_switching(
197
+                mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
198
+                self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
199
+            )
142 200
 
143 201
     def all_off(self, device=None, key=None, data=None):
144 202
         super().all_off(device, key, data)

+ 23
- 0
function/first_floor_west.py Wyświetl plik

@@ -3,9 +3,11 @@
3 3
 #
4 4
 
5 5
 import config
6
+import devices
6 7
 import logging
7 8
 from function.modules import radiator_function
8 9
 from function.rooms import room_shelly, room_shelly_tradfri_light
10
+from function.videv import videv_switch_brightness, videv_switch_brightness_color_temp
9 11
 
10 12
 
11 13
 try:
@@ -19,6 +21,13 @@ class first_floor_west_julian(room_shelly_tradfri_light):
19 21
     # http://shelly1l-3C6105E43452
20 22
     def __init__(self, mqtt_client):
21 23
         super().__init__(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)
24
+        #
25
+        self.main_light_videv = videv_switch_brightness_color_temp(
26
+            mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV,
27
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
28
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
29
+            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
30
+        )
22 31
 
23 32
 
24 33
 class first_floor_west_bath(object):
@@ -26,6 +35,7 @@ class first_floor_west_bath(object):
26 35
         # radiator valve
27 36
         self.radiator_function = radiator_function(mqtt_client, config.TOPIC_FFW_BATH_RADIATOR_VALVE_ZIGBEE,
28 37
                                                    config.TOPIC_FFW_BATH_RADIATOR_VALVE_GUI, config.DEFAULT_TEMPERATURE_FFW_BATH)
38
+
29 39
     def all_off(self):
30 40
         pass
31 41
 
@@ -35,9 +45,22 @@ class first_floor_west_living(room_shelly_tradfri_light):
35 45
     def __init__(self, mqtt_client):
36 46
         super().__init__(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY,
37 47
                          config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
48
+        #
49
+        self.main_light_videv = videv_switch_brightness_color_temp(
50
+            mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV,
51
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
52
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
53
+            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
54
+        )
38 55
 
39 56
 
40 57
 class first_floor_west_sleep(room_shelly_tradfri_light):
41 58
     # http://shelly1-3494546A51F2
42 59
     def __init__(self, mqtt_client):
43 60
         super().__init__(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_GUI, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)
61
+        #
62
+        self.main_light_videv = videv_switch_brightness(
63
+            mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV,
64
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
65
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS
66
+        )

+ 39
- 1
function/ground_floor_west.py Wyświetl plik

@@ -7,6 +7,7 @@ import devices
7 7
 from function.modules import brightness_choose_n_action, radiator_function
8 8
 import logging
9 9
 from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
10
+from function.videv import videv_switching, videv_switch_brightness_color_temp
10 11
 import task
11 12
 
12 13
 try:
@@ -26,10 +27,17 @@ class ground_floor_west_floor(room_shelly_silvercrest_light):
26 27
         self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_2_ZIGBEE)
27 28
         self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.main_light_tradfri_2.set_brightness_mcb)
28 29
         self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.main_light_tradfri_2.set_color_temp_mcb)
30
+        #
31
+        self.main_light_videv = videv_switch_brightness_color_temp(
32
+            mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV,
33
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
34
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
35
+            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
36
+        )
29 37
 
30 38
     def send_init_message_main_light(self):
31 39
         super().send_init_message_main_light()
32
-        self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}')
40
+        self.main_light_tradfri_2.request_data()
33 41
 
34 42
 
35 43
 class ground_floor_west_marion(room_shelly):
@@ -39,6 +47,11 @@ class ground_floor_west_marion(room_shelly):
39 47
         # radiator valve
40 48
         self.radiator_function = radiator_function(mqtt_client, config.TOPIC_GFW_MARION_RADIATOR_VALVE_ZIGBEE,
41 49
                                                    config.TOPIC_GFW_MARION_RADIATOR_VALVE_GUI, config.DEFAULT_TEMPERATURE_GFW_MARION)
50
+        #
51
+        self.main_light_videv = videv_switching(
52
+            mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV,
53
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
54
+        )
42 55
 
43 56
 
44 57
 class ground_floor_west_dirk(room_shelly_tradfri_light):
@@ -136,6 +149,31 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
136 149
                                          self.powerplug_common.toggle_output_3_mcb)
137 150
         self.gui_pc_dock.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_3_mcb)
138 151
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_PC_DOCK, None, self.gui_pc_dock.set_state_mcb)
152
+        #
153
+        self.main_light_videv = videv_switch_brightness_color_temp(
154
+            mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV,
155
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
156
+            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
157
+            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
158
+        )
159
+        self.desk_light_videv = videv_switch_brightness_color_temp(
160
+            mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV,
161
+            self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT,
162
+            self.desk_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
163
+            self.desk_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
164
+        )
165
+        self.amplifier_videv = videv_switching(
166
+            mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV,
167
+            self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER
168
+        )
169
+        self.cd_player_videv = videv_switching(
170
+            mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV,
171
+            self.powerplug_common, self.KEY_POWERPLUG_CD_PLAYER
172
+        )
173
+        self.pc_dock_videv = videv_switching(
174
+            mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV,
175
+            self.powerplug_common, self.KEY_POWERPLUG_PC_DOCK
176
+        )
139 177
 
140 178
     def all_off(self, device=None, key=None, data=None):
141 179
         super().all_off(device, key, data)

+ 17
- 0
function/modules.py Wyświetl plik

@@ -1,6 +1,15 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: utf-8 -*-
3 3
 #
4
+"""
5
+Functional Modules
6
+
7
+Targets:
8
+  * Device like structure to be compatible with videv
9
+    - KEY_* as part of the class for all parameters which needs to be accessed from videv
10
+    - Method *.set(key, data) to pass data from videv to Module
11
+    - Method .add_calback(key, data, callback, on_change_only=False) to register videv actualisation on changes
12
+"""
4 13
 
5 14
 import config
6 15
 import devices
@@ -16,6 +25,14 @@ except ImportError:
16 25
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
17 26
 
18 27
 
28
+class base(object):
29
+    def set(key, data):
30
+        pass
31
+
32
+    def add_calback(self, key, data, callback, on_change_only=False):
33
+        pass
34
+
35
+
19 36
 class brightness_choose_n_action(object):
20 37
     def __init__(self, mqtt_client, button_tradfri, topic_led):
21 38
         self.gui_led_active_device = devices.nodered_gui_leds(mqtt_client, topic_led)

+ 1
- 1
function/rooms.py Wyświetl plik

@@ -145,4 +145,4 @@ class room_shelly_silvercrest_light(room_shelly_tradfri_light):
145 145
         self.main_light_shelly_last = data
146 146
 
147 147
     def send_init_message_main_light(self):
148
-        self.main_light_tradfri.mqtt_client.send(self.main_light_tradfri.topic + "/get", '{"state": ""}')
148
+        self.main_light_tradfri.request_data()

+ 8
- 0
function/stairway.py Wyświetl plik

@@ -3,9 +3,12 @@
3 3
 #
4 4
 
5 5
 import config
6
+import devices
6 7
 from function.modules import brightness_choose_n_action
7 8
 import logging
8 9
 from function.rooms import room_shelly_motion_sensor
10
+from function.videv import videv_switching
11
+
9 12
 try:
10 13
     from config import APP_NAME as ROOT_LOGGER_NAME
11 14
 except ImportError:
@@ -19,3 +22,8 @@ class stairway(room_shelly_motion_sensor):
19 22
         super().__init__(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI,
20 23
                          config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF,
21 24
                          timer_value=config.USER_ON_TIME_STAIRWAYS)
25
+        #
26
+        self.main_light_videv = videv_switching(
27
+            mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV,
28
+            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
29
+        )

+ 146
- 0
function/videv.py Wyświetl plik

@@ -0,0 +1,146 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+"""
5
+Virtual Device(s)
6
+
7
+Targets:
8
+  * MQTT-Interface to control joined devices as one virtual device.
9
+  * Primary signal routing 
10
+  * No functionality should be implemented here
11
+"""
12
+
13
+from base import mqtt_base
14
+import devices
15
+import json
16
+import logging
17
+
18
+BASETOPIC = "videv"
19
+
20
+
21
+try:
22
+    from config import APP_NAME as ROOT_LOGGER_NAME
23
+except ImportError:
24
+    ROOT_LOGGER_NAME = 'root'
25
+
26
+
27
+class base(mqtt_base):
28
+    DEFAULT_VALUES = {}
29
+
30
+    def __init__(self, mqtt_client, topic, *args):
31
+        super().__init__(mqtt_client, topic)
32
+        self.__device_list__ = {}
33
+        for videv_key, device in [reduced[:2] for reduced in args]:
34
+            self.__device_list__[videv_key] = device
35
+        # send initial state
36
+        for key in self.keys():
37
+            self.__tx__(key, self[key])
38
+        # add receive topics
39
+        mqtt_client.add_callback(self.topic + "/#", self.__rx__)
40
+
41
+    def __tx__(self, key, data):
42
+        if type(data) not in (str, ):
43
+            data = json.dumps(data)
44
+        if key in self.keys():
45
+            self.mqtt_client.send(self.topic + '/' + key, data)
46
+        else:
47
+            self.logger.warning("Ignoring send request for key %s (not available for this class)", key)
48
+
49
+    def __rx__(self, client, userdata, message):
50
+        key = message.topic.split('/')[-1]
51
+        if key in self.keys():
52
+            try:
53
+                data = json.loads(message.payload)
54
+            except json.decoder.JSONDecodeError:
55
+                data = message.payload
56
+            if data != self[key]:
57
+                self.__rx_functionality__(key, data)
58
+            self.set(key, data)
59
+        else:
60
+            self.logger.info("Ignoring rx message with topic %s", message.topic)
61
+
62
+    def __rx_functionality__(self, key, data):
63
+        raise NotImplemented("Method __rx_functionality__ needs to be implemented in child class")
64
+
65
+    def __device_data__(self, device, key, data):
66
+        raise NotImplemented("Method __device_data__ needs to be implemented in child class")
67
+
68
+
69
+class base_routing(base):
70
+    def __init__(self, mqtt_client, topic, *args):
71
+        super().__init__(mqtt_client, topic, *args)
72
+        #
73
+        self.__device_key__ = {}
74
+        index = 0
75
+        for videv_key, device, device_key in args:
76
+            if self.__device_list__[videv_key] != device:
77
+                raise ReferenceError("Parent class generated a deviating device list")
78
+            self.__device_key__[videv_key] = device_key
79
+            index += 1
80
+        # add callbacks
81
+        for key in self.__device_list__:
82
+            self.__device_list__[key].add_callback(self.__device_key__[key], None, self.__device_data__, True)
83
+
84
+    def __rx_functionality__(self, key, data):
85
+        try:
86
+            self.__device_list__[key].set(self.__device_key__[key], data)
87
+        except KeyError:
88
+            self.logger.warning("RX passthrough not possible for key %s", key)
89
+
90
+    def __device_data__(self, device, key, data):
91
+        l1 = [k for k, v in self.__device_list__.items() if v == device]
92
+        l2 = [k for k, v in self.__device_key__.items() if v == key]
93
+        try:
94
+            videv_key = [k for k in l1 if k in l2][0]
95
+        except IndexError:
96
+            self.logger.warning("videv_key not available for %s::%s", device.__class__.__name__, device.topic)
97
+        else:
98
+            self.set(videv_key, data)
99
+            self.__tx__(videv_key, data)
100
+
101
+
102
+class videv_switching(base_routing):
103
+    KEY_STATE = 'state'
104
+    #
105
+    DEFAULT_VALUES = {
106
+        KEY_STATE: False,
107
+    }
108
+
109
+    def __init__(self, mqtt_client, topic, sw_device, sw_key):
110
+        #
111
+        super().__init__(mqtt_client, topic, (self.KEY_STATE, sw_device, sw_key))
112
+
113
+
114
+class videv_switch_brightness(base_routing):
115
+    KEY_STATE = 'state'
116
+    KEY_BRIGHTNESS = 'brightness'
117
+    #
118
+    DEFAULT_VALUES = {
119
+        KEY_STATE: False,
120
+        KEY_BRIGHTNESS: 0
121
+    }
122
+
123
+    def __init__(self, mqtt_client, topic, sw_device, sw_key, br_device, br_key):
124
+        #
125
+        super().__init__(mqtt_client, topic, (self.KEY_STATE, sw_device, sw_key), (self.KEY_BRIGHTNESS, br_device, br_key))
126
+
127
+
128
+class videv_switch_brightness_color_temp(base_routing):
129
+    KEY_STATE = 'state'
130
+    KEY_BRIGHTNESS = 'brightness'
131
+    KEY_COLOR_TEMP = 'color_temp'
132
+    #
133
+    DEFAULT_VALUES = {
134
+        KEY_STATE: False,
135
+        KEY_BRIGHTNESS: 0,
136
+        KEY_COLOR_TEMP: 0,
137
+    }
138
+
139
+    def __init__(self, mqtt_client, topic, sw_device, sw_key, br_device, br_key, ct_device, ct_key):
140
+        #
141
+        super().__init__(
142
+            mqtt_client, topic,
143
+            (self.KEY_STATE, sw_device, sw_key),
144
+            (self.KEY_BRIGHTNESS, br_device, br_key),
145
+            (self.KEY_COLOR_TEMP, ct_device, ct_key)
146
+        )

Ładowanie…
Anuluj
Zapisz