Browse Source

clean up

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
2f673aa283

+ 3
- 5
function/common.py View File

@@ -5,7 +5,6 @@
5 5
 import devices
6 6
 from function.rooms import room_shelly
7 7
 from function.modules import heating_function_brennenstuhl
8
-from function.helpers import changed_value_indicator
9 8
 import logging
10 9
 import task
11 10
 
@@ -21,22 +20,21 @@ class common_circulation_pump(room_shelly):
21 20
         # http://shelly1-E89F6D85A466
22 21
         super().__init__(mqtt_client, "shellies/ffe/kitchen/circulation_pump", "gui/none/common/circulation_pump/switch")
23 22
         #
24
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.circ_pump_actions)
23
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.circ_pump_actions, True)
25 24
         #
26 25
         self.gui_timer_view = devices.nodered_gui_heatvalve(mqtt_client, "gui/ffe_circ_pump_timer")
27 26
         self.gui_timer_view.set_feedback('-')
28 27
         #
29
-        self.cvi = changed_value_indicator()
30 28
         self.ct = task.periodic(6, self.cyclic_task)
31 29
         self.pump_timer = None
32 30
         #
33 31
         self.ct.run()
34 32
 
35 33
     def circ_pump_actions(self, device, key, data):
36
-        if self.cvi.changed_here(device.topic, key, data) and data is True:
34
+        if data is True:
37 35
             self.pump_timer = 10
38 36
             self.gui_timer_view.set_feedback(self.pump_timer)
39
-        elif data is False:
37
+        else:
40 38
             self.pump_timer = None
41 39
             self.gui_timer_view.set_feedback('-')
42 40
 

+ 0
- 3
function/first_floor_east.py View File

@@ -7,7 +7,6 @@ import devices
7 7
 import json
8 8
 import logging
9 9
 from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
10
-from function.helpers import changed_value_indicator
11 10
 try:
12 11
     from config import APP_NAME as ROOT_LOGGER_NAME
13 12
 except ImportError:
@@ -163,8 +162,6 @@ class first_floor_east_living(room_shelly_tradfri_light):
163 162
             self.gui_switch_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
164 163
             #
165 164
             self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
166
-        #
167
-        self.cvi = changed_value_indicator()
168 165
 
169 166
     def all_off(self, device=None, key=None, data=None):
170 167
         super().all_off(device, key, data)

+ 1
- 1
function/first_floor_west.py View File

@@ -3,7 +3,7 @@
3 3
 #
4 4
 
5 5
 import logging
6
-from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
6
+from function.rooms import room_shelly, room_shelly_tradfri_light
7 7
 
8 8
 try:
9 9
     from config import APP_NAME as ROOT_LOGGER_NAME

+ 34
- 45
function/ground_floor_west.py View File

@@ -5,7 +5,6 @@
5 5
 import devices
6 6
 import logging
7 7
 from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
8
-from function.helpers import changed_value_indicator
9 8
 import task
10 9
 
11 10
 try:
@@ -80,8 +79,6 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
80 79
         #
81 80
         self.delayed_task = task.delayed(1.0, self.send_audio_source)
82 81
         #
83
-        self.cvi = changed_value_indicator()
84
-        #
85 82
         # Callback initialisation
86 83
         #
87 84
 
@@ -110,14 +107,14 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
110 107
         self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
111 108
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
112 109
         # amplifier auto on
113
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation)
114
-        self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
115
-        self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
110
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation, True)
111
+        self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
112
+        self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
116 113
         # audio source
117
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.audio_source_selector)
118
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.audio_source_selector)
119
-        self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
120
-        self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
114
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
115
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
116
+        self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
117
+        self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
121 118
         self.audio_source = self.AUDIO_SOURCE_PC
122 119
 
123 120
         # cd player
@@ -134,8 +131,8 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
134 131
 
135 132
         # brightness
136 133
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, None, self.brightness_action)
137
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action)
138
-        self.powerplug_common.add_callback(None, None, self.device_chooser_action)
134
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action, True)
135
+        self.powerplug_common.add_callback(None, None, self.device_chooser_action, True)
139 136
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
140 137
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
141 138
         self.active_device_state = None
@@ -146,37 +143,32 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
146 143
         self.powerplug_common.set_output_all(False)
147 144
 
148 145
     def cd_amplifier_synchronisation(self, device, key, data):
149
-        if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
150
-            logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
151
-            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
146
+        logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
147
+        self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
152 148
 
153 149
     def raspi_amplifier_synchronisation(self, device, key, data):
154
-        if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
155
-            logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
156
-            self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
150
+        logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
151
+        self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
157 152
 
158 153
     def device_chooser_action(self, device, key, data):
159 154
         if device == self.main_light_shelly:
160
-            if self.cvi.changed_here(device.topic, key, data):
161
-                if data is True:
162
-                    self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
163
-                    self.update_active_device_led()
164
-                else:
165
-                    self.choose_next_device()
155
+            if data is True:
156
+                self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
157
+                self.update_active_device_led()
158
+            else:
159
+                self.choose_next_device()
166 160
         elif device == self.powerplug_common and key == self.KEY_POWERPLUG_DESK_LIGHT:
167
-            if self.cvi.changed_here(device.topic, key, data):
168
-                if data is True:
169
-                    self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
170
-                    self.update_active_device_led()
171
-                else:
172
-                    self.choose_next_device()
161
+            if data is True:
162
+                self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
163
+                self.update_active_device_led()
164
+            else:
165
+                self.choose_next_device()
173 166
         elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
174
-            if self.cvi.changed_here(device.topic, key, data):
175
-                if data is True:
176
-                    self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
177
-                    self.update_active_device_led()
178
-                else:
179
-                    self.choose_next_device()
167
+            if data is True:
168
+                self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
169
+                self.update_active_device_led()
170
+            else:
171
+                self.choose_next_device()
180 172
 
181 173
     def get_activity_state(self, state):
182 174
         if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
@@ -237,17 +229,14 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
237 229
 
238 230
     def audio_source_selector(self, device, key, data):
239 231
         if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
240
-            if self.cvi.changed_here(device.topic, key, data) and data is True:
241
-                # switch on of cd player
242
-                self.audio_source = self.AUDIO_SOURCE_CD
232
+            # switch on of cd player
233
+            self.audio_source = self.AUDIO_SOURCE_CD
243 234
         elif device in [self.spotify_state, self.mpd_state]:
244
-            if self.cvi.changed_here(device.topic, key, data) and data is True:
245
-                # switch on raspi-source
246
-                self.audio_source = self.AUDIO_SOURCE_RASPI
235
+            # switch on raspi-source
236
+            self.audio_source = self.AUDIO_SOURCE_RASPI
247 237
         elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
248
-            if self.cvi.changed_here(device.topic, key, data) and data is True:
249
-                # switch on of amplifier -> select source and reset stored source value
250
-                self.delayed_task.run()
238
+            # switch on of amplifier -> select source and reset stored source value
239
+            self.delayed_task.run()
251 240
 
252 241
     def send_audio_source(self):
253 242
         if self.audio_source == self.AUDIO_SOURCE_PC:

+ 0
- 13
function/helpers.py View File

@@ -7,19 +7,6 @@ import inspect
7 7
 import time
8 8
 
9 9
 
10
-class changed_value_indicator(dict):
11
-    def __init__(self):
12
-        super().__init__(self)
13
-
14
-    def changed_here(self, topic, key, value):
15
-        caller_name = inspect.getmodule(inspect.stack()[1][0]).__name__ + '.' + inspect.stack()[1][3]
16
-        key = '::'.join([caller_name, topic, key])
17
-        #
18
-        rv = self.get(key) != value
19
-        self[key] = value
20
-        return rv
21
-
22
-
23 10
 def now():
24 11
     return time.mktime(time.localtime())
25 12
 

Loading…
Cancel
Save