Explorar el Código

bug-fix for brightness_choose_n_action

tags/v1.0.0
Dirk Alders hace 2 años
padre
commit
8ba63349fb
Se han modificado 5 ficheros con 27 adiciones y 51 borrados
  1. 0
    24
      devices/__init__.py
  2. 4
    4
      function/__init__.py
  3. 2
    2
      function/first_floor_east.py
  4. 3
    3
      function/ground_floor_west.py
  5. 18
    18
      function/modules.py

+ 0
- 24
devices/__init__.py Ver fichero

@@ -215,12 +215,6 @@ class shelly(base):
215 215
     def __init__(self, mqtt_client, topic):
216 216
         super().__init__(mqtt_client, topic)
217 217
 
218
-    def add_on_off_callback_0(self, callback):
219
-        self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
220
-
221
-    def add_on_off_callback_1(self, callback):
222
-        self.add_callback(self.KEY_OUTPUT_1, None, callback, True)
223
-
224 218
     #
225 219
     # WARNING CALL
226 220
     #
@@ -313,9 +307,6 @@ class silvercrest_powerplug(base):
313 307
     def __init__(self, mqtt_client, topic):
314 308
         super().__init__(mqtt_client, topic)
315 309
 
316
-    def add_default_on_off_callback(self, callback):
317
-        self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
318
-
319 310
     #
320 311
     # RX
321 312
     #
@@ -389,18 +380,6 @@ class my_powerplug(base):
389 380
     def __init__(self, mqtt_client, topic):
390 381
         super().__init__(mqtt_client, topic)
391 382
 
392
-    def add_on_off_callback_0(self, callback):
393
-        self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
394
-
395
-    def add_on_off_callback_1(self, callback):
396
-        self.add_callback(self.KEY_OUTPUT_1, None, callback, True)
397
-
398
-    def add_on_off_callback_2(self, callback):
399
-        self.add_callback(self.KEY_OUTPUT_2, None, callback, True)
400
-
401
-    def add_on_off_callback_3(self, callback):
402
-        self.add_callback(self.KEY_OUTPUT_3, None, callback, True)
403
-
404 383
     #
405 384
     # RX
406 385
     #
@@ -511,9 +490,6 @@ class tradfri_light(base):
511 490
     def __init__(self, mqtt_client, topic):
512 491
         super().__init__(mqtt_client, topic)
513 492
 
514
-    def add_on_off_callback_0(self, callback):
515
-        self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
516
-
517 493
     def unpack_filter(self, key):
518 494
         if key == self.KEY_BRIGHTNESS:
519 495
             self[key] = (self[key] - 1) * 100 / 254

+ 4
- 4
function/__init__.py Ver fichero

@@ -59,10 +59,10 @@ class all_functions(object):
59 59
 
60 60
     def init_off_functionality(self):
61 61
         # Off Buttons
62
-        self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/all/common/off/button")
63
-        self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/gfw/common/off/button")
64
-        self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/ffw/common/off/button")
65
-        self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/ffe/common/off/button")
62
+        self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
63
+        self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
64
+        self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffw/common/off/button")
65
+        self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffe/common/off/button")
66 66
         #
67 67
         self.gui_button_all_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.all_off)
68 68
         self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)

+ 2
- 2
function/first_floor_east.py Ver fichero

@@ -63,8 +63,8 @@ class first_floor_east_sleep(room_shelly_tradfri_light):
63 63
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
64 64
         #
65 65
         self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
66
-        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly.add_on_off_callback_0)
67
-        self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri.add_on_off_callback_0)
66
+        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
67
+        self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
68 68
         #
69 69
         # Callback initialisation
70 70
         #

+ 3
- 3
function/ground_floor_west.py Ver fichero

@@ -77,9 +77,9 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
77 77
         self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
78 78
         #
79 79
         self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
80
-        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly.add_on_off_callback_0)
81
-        self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common.add_on_off_callback_1)
82
-        self.brightness_functions.add(self.remote_amplifier, self.powerplug_common.add_on_off_callback_0)
80
+        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
81
+        self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
82
+        self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
83 83
         #
84 84
         self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
85 85
         self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)

+ 18
- 18
function/modules.py Ver fichero

@@ -28,46 +28,46 @@ class brightness_choose_n_action(object):
28 28
         button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
29 29
         button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
30 30
         #
31
-        self.device_list = []
31
+        self.brightness_device_list = []
32 32
         self.callback_device_list = []
33 33
         self.device_states = []
34 34
         self.active_device_state = None
35 35
         self.update_active_device_led()
36 36
 
37
-    def add(self, device, add_callback):
37
+    def add(self, brightness_device, callback_device, callback_key):
38 38
         """
39
-        device: A device for brightness function needs to have the following methods:
39
+        brightness_device: A device for brightness function needs to have the following methods:
40 40
         * .default_inc()
41 41
         * .default_dec()
42 42
         * .default_stop()
43
-        add_callback: A on/off callback which tages the <function_to_be_executed> as argument and
44
-            - which calls the callback only on changes
45
-            - which calls with the following arguments: device, key, data
43
+        callback_device: A device for installing callback which are executed, when the device is switched on or off. It needs the following method:
44
+        * .add_callback(key, data or None, callback, on_changes_only)
46 45
         """
47
-        if len(self.device_list) >= len(devices.nodered_gui_leds.RX_KEYS):
46
+        if len(self.brightness_device_list) >= len(devices.nodered_gui_leds.RX_KEYS):
48 47
             raise ValueError("Number of devices is limited by number of leds in devices.nodered_gui_leds.")
49
-        self.device_list.append(device)
50
-        self.callback_device_list.append(add_callback.__self__)
48
+        self.brightness_device_list.append(brightness_device)
49
+        self.callback_device_list.append((callback_device, callback_key))
51 50
         self.device_states.append(False)
52
-        add_callback(self.device_state_action)
51
+        callback_device.add_callback(callback_key, True, self.device_state_action, True)
52
+        callback_device.add_callback(callback_key, False, self.device_state_action, True)
53 53
 
54 54
     def device_state_action(self, device, key, data):
55
-        self.device_states[self.callback_device_list.index(device)] = data
55
+        self.device_states[self.callback_device_list.index((device, key))] = data
56 56
         if data is True:
57
-            self.active_device_state = self.callback_device_list.index(device)
57
+            self.active_device_state = self.callback_device_list.index((device, key))
58 58
             self.update_active_device_led()
59 59
         else:
60 60
             self.choose_next_device()
61 61
 
62 62
     def update_active_device_led(self):
63
-        for i in range(0, len(self.device_list)):
63
+        for i in range(0, len(self.brightness_device_list)):
64 64
             self.gui_led_active_device.set_led(devices.nodered_gui_leds.RX_KEYS[i], self.active_device_state == i)
65 65
 
66 66
     def choose_prev_device(self, device=None, key=None, data=None):
67 67
         if self.active_device_state is not None:
68 68
             start_value = self.active_device_state
69
-            for i in range(0, len(self.device_list)):
70
-                target_state = (start_value - i - 1) % (len(self.device_list))
69
+            for i in range(0, len(self.brightness_device_list)):
70
+                target_state = (start_value - i - 1) % (len(self.brightness_device_list))
71 71
                 if self.device_states[target_state]:
72 72
                     self.active_device_state = target_state
73 73
                     self.update_active_device_led()
@@ -78,8 +78,8 @@ class brightness_choose_n_action(object):
78 78
     def choose_next_device(self, device=None, key=None, data=None):
79 79
         if self.active_device_state is not None:
80 80
             start_value = self.active_device_state
81
-            for i in range(0, len(self.device_list)):
82
-                target_state = (start_value + i + 1) % (len(self.device_list))
81
+            for i in range(0, len(self.brightness_device_list)):
82
+                target_state = (start_value + i + 1) % (len(self.brightness_device_list))
83 83
                 if self.device_states[target_state]:
84 84
                     self.active_device_state = target_state
85 85
                     self.update_active_device_led()
@@ -89,7 +89,7 @@ class brightness_choose_n_action(object):
89 89
 
90 90
     def brightness_action(self, device, key, data):
91 91
         if self.active_device_state is not None:
92
-            target = self.device_list[self.active_device_state]
92
+            target = self.brightness_device_list[self.active_device_state]
93 93
             if data == devices.tradfri_button.ACTION_BRIGHTNESS_UP_LONG:
94 94
                 logger.info("Increasing \"%s\" - %s", type(self).__name__, target.topic)
95 95
                 target.default_inc()

Loading…
Cancelar
Guardar