Преглед на файлове

User feedback (flash) implemented in new structure

tags/v1.0.0
Dirk Alders преди 1 година
родител
ревизия
43308d858e
променени са 4 файла, в които са добавени 86 реда и са изтрити 61 реда
  1. 47
    3
      devices/__init__.py
  2. 34
    20
      function/__init__.py
  3. 1
    0
      function/first_floor_east.py
  4. 4
    38
      function/rooms.py

+ 47
- 3
devices/__init__.py Целия файл

@@ -26,15 +26,13 @@ devices (DEVICES)
26 26
 
27 27
 """
28 28
 
29
-# TODO: Usage of mqtt_base for all devices
30
-#
31
-# TODO: brennenstuhl_heatingvalve: always send "{"preset": "manual", "system_mode": "heat"}" with any information
32 29
 # TODO: usage of base.mqtt as parent for class base
33 30
 
34 31
 __DEPENDENCIES__ = []
35 32
 
36 33
 import json
37 34
 import logging
35
+import task
38 36
 
39 37
 try:
40 38
     from config import APP_NAME as ROOT_LOGGER_NAME
@@ -265,6 +263,26 @@ class shelly(base):
265 263
 
266 264
     def __init__(self, mqtt_client, topic):
267 265
         super().__init__(mqtt_client, topic)
266
+        #
267
+        self.output_key_delayed = None
268
+        self.delayed_flash_task = task.delayed(0.3, self.flash_task)
269
+        self.delayed_off_task = task.delayed(0.3, self.off_task)
270
+        #
271
+        self.all_off_requested = False
272
+
273
+    def flash_task(self, *args):
274
+        if self.flash_active:
275
+            self.pack(self.output_key_delayed, not self.get(self.output_key_delayed))
276
+            self.output_key_delayed = None
277
+            if self.all_off_requested:
278
+                self.delayed_off_task.run()
279
+
280
+    def off_task(self, *args):
281
+        self.all_off()
282
+
283
+    @property
284
+    def flash_active(self):
285
+        return self.output_key_delayed is not None
268 286
 
269 287
     #
270 288
     # WARNING CALL
@@ -344,6 +362,23 @@ class shelly(base):
344 362
         self.logger.info("Toggeling output 1")
345 363
         self.set_output_1('toggle')
346 364
 
365
+    def flash_0_mcb(self, device, key, data):
366
+        self.output_key_delayed = self.KEY_OUTPUT_0
367
+        self.toggle_output_0_mcb(device, key, data)
368
+        self.delayed_flash_task.run()
369
+
370
+    def flash_1_mcb(self, device, key, data):
371
+        self.output_key_delayed = self.KEY_OUTPUT_1
372
+        self.toggle_output_1_mcb(device, key, data)
373
+        self.delayed_flash_task.run()
374
+
375
+    def all_off(self):
376
+        if self.flash_active:
377
+            self.all_off_requested = True
378
+        else:
379
+            self.set_output_0(False)
380
+            self.set_output_1(False)
381
+
347 382
 
348 383
 class silvercrest_powerplug(base):
349 384
     KEY_LINKQUALITY = "linkquality"
@@ -386,6 +421,9 @@ class silvercrest_powerplug(base):
386 421
         self.logger.info("Toggeling output 0")
387 422
         self.set_output_0('toggle')
388 423
 
424
+    def all_off(self):
425
+        self.set_output_0(False)
426
+
389 427
 
390 428
 class silvercrest_motion_sensor(base):
391 429
     KEY_BATTERY = "battery"
@@ -523,6 +561,9 @@ class my_powerplug(base):
523 561
         self.logger.info("Toggeling all outputs")
524 562
         self.set_output_0('toggle')
525 563
 
564
+    def all_off(self):
565
+        self.set_output_all(False)
566
+
526 567
 
527 568
 class tradfri_light(base):
528 569
     KEY_LINKQUALITY = "linkquality"
@@ -623,6 +664,9 @@ class tradfri_light(base):
623 664
         self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
624 665
         self.set_color_temp(data)
625 666
 
667
+    def all_off(self):
668
+        self.set_output_0(False)
669
+
626 670
 
627 671
 class tradfri_button(base):
628 672
     ACTION_TOGGLE = "toggle"

+ 34
- 20
function/__init__.py Целия файл

@@ -24,6 +24,9 @@ class all_functions(object):
24 24
         self.mqtt_client = mqtt_client
25 25
         #
26 26
         self.__devices__ = None
27
+        #
28
+        # Rooms
29
+        #
27 30
         # stairway
28 31
         self.stw_stairway = stairway(self.mqtt_client)
29 32
         # ground floor west
@@ -49,7 +52,16 @@ class all_functions(object):
49 52
         # Off Buttons
50 53
         self.init_off_functionality()
51 54
 
55
+    def init_cross_room_interactions(self):
56
+        # shelly dirk input 1
57
+        self.last_gfw_dirk_input_1 = None
58
+        self.gfw_dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
59
+        # tradfri button ffe_sleep right click
60
+        self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
61
+                                                   devices.tradfri_button.ACTION_RIGHT, self.ffe_floor.main_light_shelly.toggle_output_0_mcb)
62
+
52 63
     def init_off_functionality(self):
64
+        ##### TEMPORARY ###################################################################################################################
53 65
         # Off Buttons
54 66
         self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
55 67
         self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
@@ -60,15 +72,25 @@ class all_functions(object):
60 72
         self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
61 73
         self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
62 74
         self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
63
-        # Long push ffe_floor
64
-        self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.all_off_feedback)
65
-        self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
66
-        # Long push stairway
67
-        self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw_stairway.all_off_feedback)
75
+        ##### TEMPORARY ###################################################################################################################
76
+
77
+        # ALL OFF - Long push stairway
78
+        self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw_stairway.main_light_shelly.flash_0_mcb)
68 79
         self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
69
-        # Long push input device
80
+
81
+        # FFE ALL OFF - Long push ffe_floor
82
+        self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.main_light_shelly.flash_0_mcb)
83
+        self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
84
+
85
+        # FFE ALL OFF - Long push input device
70 86
         self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe_off)
71 87
 
88
+    def gfw_dirk_input_1(self, device, key, data):
89
+        if self.last_gfw_dirk_input_1 is not None:
90
+            if self.last_gfw_dirk_input_1 != data:
91
+                self.gfw_floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
92
+        self.last_gfw_dirk_input_1 = data
93
+
72 94
     def getmembers(self, prefix):
73 95
         rv = []
74 96
         for name, obj in inspect.getmembers(self):
@@ -96,25 +118,17 @@ class all_functions(object):
96 118
         for ffe in self.getmembers('ffe'):
97 119
             ffe.all_off()
98 120
 
121
+    def stw_off(self, device=None, key=None, data=None):
122
+        logger.info("Switching \"stairway\" off.")
123
+        for stw in self.getmembers('stw'):
124
+            stw.all_off()
125
+
99 126
     def all_off(self, device=None, key=None, data=None):
100 127
         self.common_off(device, key, data)
101 128
         self.gfw_off(device, key, data)
102 129
         self.ffw_off(device, key, data)
103 130
         self.ffe_off(device, key, data)
104
-
105
-    def init_cross_room_interactions(self):
106
-        # shelly dirk input 1
107
-        self.last_gfw_dirk_input_1 = None
108
-        self.gfw_dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
109
-        # tradfri button ffe_sleep right click
110
-        self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
111
-                                                   devices.tradfri_button.ACTION_RIGHT, self.ffe_floor.main_light_shelly.toggle_output_0_mcb)
112
-
113
-    def gfw_dirk_input_1(self, device, key, data):
114
-        if self.last_gfw_dirk_input_1 is not None:
115
-            if self.last_gfw_dirk_input_1 != data:
116
-                self.gfw_floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
117
-        self.last_gfw_dirk_input_1 = data
131
+        self.stw_off(device, key, data)
118 132
 
119 133
     def devicelist(self):
120 134
         if self.__devices__ is None:

+ 1
- 0
function/first_floor_east.py Целия файл

@@ -55,6 +55,7 @@ class first_floor_east_kitchen(room):
55 55
         # Functionality initialisation
56 56
         #
57 57
         self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
58
+        self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
58 59
 
59 60
         ##### TEMPORARY ###################################################################################################################
60 61
         self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)

+ 4
- 38
function/rooms.py Целия файл

@@ -20,44 +20,10 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
20 20
 class room(object):
21 21
     def __init__(self, mqtt_client):
22 22
         self.mqtt_client = mqtt_client
23
-        #
24
-        self.block_all_off = False
25
-        self.last_flash_data = None
23
+
24
+    def all_off(self, device=None, key=None, data=None):
25
+        logger.info("Switching all off \"%s\"", type(self).__name__)
26 26
         try:
27
-            self.delayed_task = task.delayed(.25, self.main_light_shelly.toggle_output_0_mcb, None, None, None)
27
+            self.main_light_shelly.all_off()
28 28
         except AttributeError:
29 29
             logger.exception("Device self.main_light does not exist!")
30
-            self.delayed_task = task.delayed(.25, self.__delayed_task_dummy__, None, None, None)
31
-
32
-    def __delayed_task_dummy__(self, device, key, data):
33
-        logger.exception("Device self.main_light does not exist!")
34
-
35
-    def all_off(self, device=None, key=None, data=None):
36
-        if not self.block_all_off:
37
-            logger.info("Switching all off \"%s\"", type(self).__name__)
38
-            try:
39
-                self.main_light_shelly.set_output_0(False)
40
-                self.main_light_shelly.set_output_1(False)
41
-            except AttributeError:
42
-                logger.exception("Device self.main_light does not exist!")
43
-        self.block_all_off = False
44
-
45
-    def all_off_feedback(self, device=None, key=None, data=None):
46
-        logger.info("Flashing \"%s\" main light", type(self).__name__)
47
-        if self.main_light_shelly.output_0 is False:
48
-            try:
49
-                self.main_light_shelly.set_output_0(True)
50
-            except AttributeError:
51
-                logger.exception("Device self.main_light does not exist!")
52
-            self.block_all_off = True
53
-            self.delayed_task.run()
54
-
55
-    def flash_main_light(self, device, key, data):
56
-        if self.last_flash_data != data and data is True:
57
-            logger.info("Flashing \"%s\" main light", type(self).__name__)
58
-            try:
59
-                self.main_light_shelly.toggle_output_0_mcb(device, key, data)
60
-            except AttributeError:
61
-                logger.exception("Device self.main_light does not exist!")
62
-            self.delayed_task.run()
63
-        self.last_flash_data = data

Loading…
Отказ
Запис