Browse Source

minor changes - esthetic

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
3ebfe2f3a5
3 changed files with 41 additions and 25 deletions
  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 View File

78
         #
78
         #
79
         self.callback_list = []
79
         self.callback_list = []
80
         self.warning_callback = None
80
         self.warning_callback = None
81
+        #
82
+        self.__previous__ = {}
81
 
83
 
82
     def receive_callback(self, client, userdata, message):
84
     def receive_callback(self, client, userdata, message):
83
         self.unpack(message)
85
         self.unpack(message)
93
         prev_value = self.get(key)
95
         prev_value = self.get(key)
94
         if key in self.RX_KEYS:
96
         if key in self.RX_KEYS:
95
             self[key] = data
97
             self[key] = data
98
+            self.__previous__[key] = prev_value
96
             # Filter, if needed
99
             # Filter, if needed
97
             self.unpack_filter(key)
100
             self.unpack_filter(key)
98
             if prev_value != self.get(key):
101
             if prev_value != self.get(key):
186
     def warning_text(self, data):
189
     def warning_text(self, data):
187
         return "default warning text - replace parent warning_text function"
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
 class shelly(base):
196
 class shelly(base):
191
     KEY_OUTPUT_0 = "relay/0"
197
     KEY_OUTPUT_0 = "relay/0"
317
     KEY_OUTPUT_2 = "output/3"
323
     KEY_OUTPUT_2 = "output/3"
318
     KEY_OUTPUT_3 = "output/4"
324
     KEY_OUTPUT_3 = "output/4"
319
     KEY_OUTPUT_ALL = "output/all"
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
     TX_TOPIC = 'set'
328
     TX_TOPIC = 'set'
322
     TX_TYPE = base.TX_VALUE
329
     TX_TYPE = base.TX_VALUE
352
     #
359
     #
353
     # TX
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
     def set_output_0(self, state):
368
     def set_output_0(self, state):
356
         """state: [True, False, 'toggle']"""
369
         """state: [True, False, 'toggle']"""
357
         self.pack(self.KEY_OUTPUT_0, state)
370
         self.pack(self.KEY_OUTPUT_0, state)

+ 4
- 4
function/first_floor_east.py View File

52
         self.floorlamp_powerplug.set_output_0(False)
52
         self.floorlamp_powerplug.set_output_0(False)
53
 
53
 
54
     def floorlamp_synchronisation(self, device, key, data):
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
             self.floorlamp_powerplug.set_output_0(data)
57
             self.floorlamp_powerplug.set_output_0(data)
58
 
58
 
59
     def gui_switch_command_floorlamp(self, device, key, data):
59
     def gui_switch_command_floorlamp(self, device, key, data):
218
         return rv
218
         return rv
219
 
219
 
220
     def floorlamp_synchronisation(self, device, key, data):
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
             for device in self.__floorlamp_devices__():
223
             for device in self.__floorlamp_devices__():
224
                 device.set_output_0(data)
224
                 device.set_output_0(data)
225
 
225
 

+ 24
- 21
function/ground_floor_west.py View File

161
             self.gui_switch_pc_dock.set_feedback(data)
161
             self.gui_switch_pc_dock.set_feedback(data)
162
 
162
 
163
     def cd_amplifier_synchronisation(self, device, key, data):
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
     def raspi_amplifier_synchronisation(self, device, key, data):
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
     def desk_light_switch_action(self, device, key, data):
173
     def desk_light_switch_action(self, device, key, data):
175
         if device == self.button_tradfri:
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
         else:
178
         else:
179
             logger.info("Setting \"%s\" desk light: %s", type(self).__name__, data)
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
     def desk_light_set_gui_params_action(self, device, key, data):
182
     def desk_light_set_gui_params_action(self, device, key, data):
183
         if key == devices.nodered_gui.KEY_BRIGHTNESS:
183
         if key == devices.nodered_gui.KEY_BRIGHTNESS:
195
 
195
 
196
     def amplifier_switch_action(self, device, key, data):
196
     def amplifier_switch_action(self, device, key, data):
197
         if device == self.button_tradfri:
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
         else:
201
         else:
201
             logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
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
     def cd_player_switch_action(self, device, key, data):
205
     def cd_player_switch_action(self, device, key, data):
205
         if device == self.button_tradfri:
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
         else:
210
         else:
209
             logger.info("Setting \"%s\" cd_player: %s", type(self).__name__, data)
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
     def pc_dock_switch_action(self, device, key, data):
214
     def pc_dock_switch_action(self, device, key, data):
213
         if device == self.button_tradfri:
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
         else:
219
         else:
217
             logger.info("Setting \"%s\" pc_dock: %s", type(self).__name__, data)
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
     def device_chooser_action(self, device, key, data):
223
     def device_chooser_action(self, device, key, data):
221
         if device == self.main_light_shelly:
224
         if device == self.main_light_shelly:
243
         if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
246
         if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
244
             return self.main_light_shelly.output_0
247
             return self.main_light_shelly.output_0
245
         elif state == self.STATE_ACTIVE_DEVICE_DESK_LIGHT:
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
         elif state == self.STATE_ACTIVE_DEVICE_AMPLIFIER:
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
     def choose_next_device(self, device=None, key=None, data=None):
253
     def choose_next_device(self, device=None, key=None, data=None):
251
         if self.active_device_state is not None:
254
         if self.active_device_state is not None:

Loading…
Cancel
Save