Просмотр исходного кода

minor changes - esthetic

tags/v1.0.0
Dirk Alders 2 лет назад
Родитель
Сommit
3ebfe2f3a5
3 измененных файлов: 41 добавлений и 25 удалений
  1. 13
    0
      devices/__init__.py
  2. 4
    4
      function/first_floor_east.py
  3. 24
    21
      function/ground_floor_west.py

+ 13
- 0
devices/__init__.py Просмотреть файл

@@ -78,6 +78,8 @@ class base(dict):
78 78
         #
79 79
         self.callback_list = []
80 80
         self.warning_callback = None
81
+        #
82
+        self.__previous__ = {}
81 83
 
82 84
     def receive_callback(self, client, userdata, message):
83 85
         self.unpack(message)
@@ -93,6 +95,7 @@ class base(dict):
93 95
         prev_value = self.get(key)
94 96
         if key in self.RX_KEYS:
95 97
             self[key] = data
98
+            self.__previous__[key] = prev_value
96 99
             # Filter, if needed
97 100
             self.unpack_filter(key)
98 101
             if prev_value != self.get(key):
@@ -186,6 +189,9 @@ class base(dict):
186 189
     def warning_text(self, data):
187 190
         return "default warning text - replace parent warning_text function"
188 191
 
192
+    def previous_value(self, key):
193
+        self.__previous__.get(key)
194
+
189 195
 
190 196
 class shelly(base):
191 197
     KEY_OUTPUT_0 = "relay/0"
@@ -317,6 +323,7 @@ class my_powerplug(base):
317 323
     KEY_OUTPUT_2 = "output/3"
318 324
     KEY_OUTPUT_3 = "output/4"
319 325
     KEY_OUTPUT_ALL = "output/all"
326
+    KEY_OUTPUT_LIST = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
320 327
     #
321 328
     TX_TOPIC = 'set'
322 329
     TX_TYPE = base.TX_VALUE
@@ -352,6 +359,12 @@ class my_powerplug(base):
352 359
     #
353 360
     # TX
354 361
     #
362
+    def set_output(self, key, state):
363
+        if key in self.KEY_OUTPUT_LIST:
364
+            self.pack(key, state)
365
+        else:
366
+            logging.error("Unknown key to set the output!")
367
+
355 368
     def set_output_0(self, state):
356 369
         """state: [True, False, 'toggle']"""
357 370
         self.pack(self.KEY_OUTPUT_0, state)

+ 4
- 4
function/first_floor_east.py Просмотреть файл

@@ -52,8 +52,8 @@ class first_floor_east_dining(room_shelly):
52 52
         self.floorlamp_powerplug.set_output_0(False)
53 53
 
54 54
     def floorlamp_synchronisation(self, device, key, data):
55
-        if self.cvi.changed_here(device.topic, key, data):
56
-            logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
55
+        if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
56
+            logger.info("Syncing \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
57 57
             self.floorlamp_powerplug.set_output_0(data)
58 58
 
59 59
     def gui_switch_command_floorlamp(self, device, key, data):
@@ -218,8 +218,8 @@ class first_floor_east_living(room_shelly_tradfri_light):
218 218
         return rv
219 219
 
220 220
     def floorlamp_synchronisation(self, device, key, data):
221
-        if self.cvi.changed_here(device.topic, key, data):
222
-            logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
221
+        if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
222
+            logger.info("Syncing \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
223 223
             for device in self.__floorlamp_devices__():
224 224
                 device.set_output_0(data)
225 225
 

+ 24
- 21
function/ground_floor_west.py Просмотреть файл

@@ -161,23 +161,23 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
161 161
             self.gui_switch_pc_dock.set_feedback(data)
162 162
 
163 163
     def cd_amplifier_synchronisation(self, device, key, data):
164
-        if device == self.powerplug_common:
165
-            if self.cvi.changed_here(device.topic, key, data):
166
-                logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
167
-                self.powerplug_common.set_output_0(data)
164
+        if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
165
+            logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
166
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
168 167
 
169 168
     def raspi_amplifier_synchronisation(self, device, key, data):
170
-        if self.cvi.changed_here(device.topic, key, data):
171
-            logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
172
-            self.powerplug_common.set_output_0(data)
169
+        if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
170
+            logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
171
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
173 172
 
174 173
     def desk_light_switch_action(self, device, key, data):
175 174
         if device == self.button_tradfri:
176
-            logger.info("Toggeling \"%s\" desk light to %s", type(self).__name__, not self.powerplug_common.output_1)
177
-            self.powerplug_common.set_output_1("toggle")
175
+            logger.info("Toggeling \"%s\" desk light to %s", type(
176
+                self).__name__, not self.get(self.KEY_POWERPLUG_AMPLIFIER))
177
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, "toggle")
178 178
         else:
179 179
             logger.info("Setting \"%s\" desk light: %s", type(self).__name__, data)
180
-            self.powerplug_common.set_output_1(data)
180
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_DESK_LIGHT, data)
181 181
 
182 182
     def desk_light_set_gui_params_action(self, device, key, data):
183 183
         if key == devices.nodered_gui.KEY_BRIGHTNESS:
@@ -195,27 +195,30 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
195 195
 
196 196
     def amplifier_switch_action(self, device, key, data):
197 197
         if device == self.button_tradfri:
198
-            logger.info("Toggeling \"%s\" amplifier to %s", type(self).__name__, not self.powerplug_common.output_0)
199
-            self.powerplug_common.set_output_0("toggle")
198
+            logger.info("Toggeling \"%s\" amplifier to %s", type(self).__name__,
199
+                        not self.powerplug_common.get(self.KEY_POWERPLUG_AMPLIFIER))
200
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, "toggle")
200 201
         else:
201 202
             logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
202
-            self.powerplug_common.set_output_0(data)
203
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
203 204
 
204 205
     def cd_player_switch_action(self, device, key, data):
205 206
         if device == self.button_tradfri:
206
-            logger.info("Toggeling \"%s\" cd_player to %s", type(self).__name__, not self.powerplug_common.output_2)
207
-            self.powerplug_common.set_output_2("toggle")
207
+            logger.info("Toggeling \"%s\" cd_player to %s", type(self).__name__,
208
+                        not self.powerplug_common.get(self.KEY_POWERPLUG_CD_PLAYER))
209
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_CD_PLAYER, "toggle")
208 210
         else:
209 211
             logger.info("Setting \"%s\" cd_player: %s", type(self).__name__, data)
210
-            self.powerplug_common.set_output_2(data)
212
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_CD_PLAYER, data)
211 213
 
212 214
     def pc_dock_switch_action(self, device, key, data):
213 215
         if device == self.button_tradfri:
214
-            logger.info("Toggeling \"%s\" pc_dock to %s", type(self).__name__, not self.powerplug_common.output_3)
215
-            self.powerplug_common.set_output_3("toggle")
216
+            logger.info("Toggeling \"%s\" pc_dock to %s", type(self).__name__,
217
+                        not self.powerplug_common.get(self.KEY_POWERPLUG_PC_DOCK))
218
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_PC_DOCK, "toggle")
216 219
         else:
217 220
             logger.info("Setting \"%s\" pc_dock: %s", type(self).__name__, data)
218
-            self.powerplug_common.set_output_3(data)
221
+            self.powerplug_common.set_output(self.KEY_POWERPLUG_PC_DOCK, data)
219 222
 
220 223
     def device_chooser_action(self, device, key, data):
221 224
         if device == self.main_light_shelly:
@@ -243,9 +246,9 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
243 246
         if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
244 247
             return self.main_light_shelly.output_0
245 248
         elif state == self.STATE_ACTIVE_DEVICE_DESK_LIGHT:
246
-            return self.powerplug_common.output_1
249
+            return self.powerplug_common.get(self.KEY_POWERPLUG_DESK_LIGHT)
247 250
         elif state == self.STATE_ACTIVE_DEVICE_AMPLIFIER:
248
-            return self.powerplug_common.output_0
251
+            return self.powerplug_common.get(self.KEY_POWERPLUG_AMPLIFIER)
249 252
 
250 253
     def choose_next_device(self, device=None, key=None, data=None):
251 254
         if self.active_device_state is not None:

Загрузка…
Отмена
Сохранить