Browse Source

clean up

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

+ 3
- 5
function/common.py View File

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

+ 0
- 3
function/first_floor_east.py View File

7
 import json
7
 import json
8
 import logging
8
 import logging
9
 from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
9
 from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
10
-from function.helpers import changed_value_indicator
11
 try:
10
 try:
12
     from config import APP_NAME as ROOT_LOGGER_NAME
11
     from config import APP_NAME as ROOT_LOGGER_NAME
13
 except ImportError:
12
 except ImportError:
163
             self.gui_switch_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
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
             self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
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
     def all_off(self, device=None, key=None, data=None):
166
     def all_off(self, device=None, key=None, data=None):
170
         super().all_off(device, key, data)
167
         super().all_off(device, key, data)

+ 1
- 1
function/first_floor_west.py View File

3
 #
3
 #
4
 
4
 
5
 import logging
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
 try:
8
 try:
9
     from config import APP_NAME as ROOT_LOGGER_NAME
9
     from config import APP_NAME as ROOT_LOGGER_NAME

+ 34
- 45
function/ground_floor_west.py View File

5
 import devices
5
 import devices
6
 import logging
6
 import logging
7
 from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
7
 from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
8
-from function.helpers import changed_value_indicator
9
 import task
8
 import task
10
 
9
 
11
 try:
10
 try:
80
         #
79
         #
81
         self.delayed_task = task.delayed(1.0, self.send_audio_source)
80
         self.delayed_task = task.delayed(1.0, self.send_audio_source)
82
         #
81
         #
83
-        self.cvi = changed_value_indicator()
84
-        #
85
         # Callback initialisation
82
         # Callback initialisation
86
         #
83
         #
87
 
84
 
110
         self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
107
         self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
111
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
108
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
112
         # amplifier auto on
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
         # audio source
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
         self.audio_source = self.AUDIO_SOURCE_PC
118
         self.audio_source = self.AUDIO_SOURCE_PC
122
 
119
 
123
         # cd player
120
         # cd player
134
 
131
 
135
         # brightness
132
         # brightness
136
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, None, self.brightness_action)
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
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
136
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
140
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
137
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
141
         self.active_device_state = None
138
         self.active_device_state = None
146
         self.powerplug_common.set_output_all(False)
143
         self.powerplug_common.set_output_all(False)
147
 
144
 
148
     def cd_amplifier_synchronisation(self, device, key, data):
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
     def raspi_amplifier_synchronisation(self, device, key, data):
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
     def device_chooser_action(self, device, key, data):
153
     def device_chooser_action(self, device, key, data):
159
         if device == self.main_light_shelly:
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
         elif device == self.powerplug_common and key == self.KEY_POWERPLUG_DESK_LIGHT:
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
         elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
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
     def get_activity_state(self, state):
173
     def get_activity_state(self, state):
182
         if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
174
         if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
237
 
229
 
238
     def audio_source_selector(self, device, key, data):
230
     def audio_source_selector(self, device, key, data):
239
         if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
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
         elif device in [self.spotify_state, self.mpd_state]:
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
         elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
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
     def send_audio_source(self):
241
     def send_audio_source(self):
253
         if self.audio_source == self.AUDIO_SOURCE_PC:
242
         if self.audio_source == self.AUDIO_SOURCE_PC:

+ 0
- 13
function/helpers.py View File

7
 import time
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
 def now():
10
 def now():
24
     return time.mktime(time.localtime())
11
     return time.mktime(time.localtime())
25
 
12
 

Loading…
Cancel
Save