Browse Source

User feedback (flash) implemented in new structure

tags/v1.0.0
Dirk Alders 1 year ago
parent
commit
43308d858e
4 changed files with 86 additions and 61 deletions
  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 View File

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
 # TODO: usage of base.mqtt as parent for class base
29
 # TODO: usage of base.mqtt as parent for class base
33
 
30
 
34
 __DEPENDENCIES__ = []
31
 __DEPENDENCIES__ = []
35
 
32
 
36
 import json
33
 import json
37
 import logging
34
 import logging
35
+import task
38
 
36
 
39
 try:
37
 try:
40
     from config import APP_NAME as ROOT_LOGGER_NAME
38
     from config import APP_NAME as ROOT_LOGGER_NAME
265
 
263
 
266
     def __init__(self, mqtt_client, topic):
264
     def __init__(self, mqtt_client, topic):
267
         super().__init__(mqtt_client, topic)
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
     # WARNING CALL
288
     # WARNING CALL
344
         self.logger.info("Toggeling output 1")
362
         self.logger.info("Toggeling output 1")
345
         self.set_output_1('toggle')
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
 class silvercrest_powerplug(base):
383
 class silvercrest_powerplug(base):
349
     KEY_LINKQUALITY = "linkquality"
384
     KEY_LINKQUALITY = "linkquality"
386
         self.logger.info("Toggeling output 0")
421
         self.logger.info("Toggeling output 0")
387
         self.set_output_0('toggle')
422
         self.set_output_0('toggle')
388
 
423
 
424
+    def all_off(self):
425
+        self.set_output_0(False)
426
+
389
 
427
 
390
 class silvercrest_motion_sensor(base):
428
 class silvercrest_motion_sensor(base):
391
     KEY_BATTERY = "battery"
429
     KEY_BATTERY = "battery"
523
         self.logger.info("Toggeling all outputs")
561
         self.logger.info("Toggeling all outputs")
524
         self.set_output_0('toggle')
562
         self.set_output_0('toggle')
525
 
563
 
564
+    def all_off(self):
565
+        self.set_output_all(False)
566
+
526
 
567
 
527
 class tradfri_light(base):
568
 class tradfri_light(base):
528
     KEY_LINKQUALITY = "linkquality"
569
     KEY_LINKQUALITY = "linkquality"
623
         self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
664
         self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
624
         self.set_color_temp(data)
665
         self.set_color_temp(data)
625
 
666
 
667
+    def all_off(self):
668
+        self.set_output_0(False)
669
+
626
 
670
 
627
 class tradfri_button(base):
671
 class tradfri_button(base):
628
     ACTION_TOGGLE = "toggle"
672
     ACTION_TOGGLE = "toggle"

+ 34
- 20
function/__init__.py View File

24
         self.mqtt_client = mqtt_client
24
         self.mqtt_client = mqtt_client
25
         #
25
         #
26
         self.__devices__ = None
26
         self.__devices__ = None
27
+        #
28
+        # Rooms
29
+        #
27
         # stairway
30
         # stairway
28
         self.stw_stairway = stairway(self.mqtt_client)
31
         self.stw_stairway = stairway(self.mqtt_client)
29
         # ground floor west
32
         # ground floor west
49
         # Off Buttons
52
         # Off Buttons
50
         self.init_off_functionality()
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
     def init_off_functionality(self):
63
     def init_off_functionality(self):
64
+        ##### TEMPORARY ###################################################################################################################
53
         # Off Buttons
65
         # Off Buttons
54
         self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
66
         self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
55
         self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
67
         self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
60
         self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
72
         self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
61
         self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
73
         self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
62
         self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
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
         self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
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
         self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe_off)
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
     def getmembers(self, prefix):
94
     def getmembers(self, prefix):
73
         rv = []
95
         rv = []
74
         for name, obj in inspect.getmembers(self):
96
         for name, obj in inspect.getmembers(self):
96
         for ffe in self.getmembers('ffe'):
118
         for ffe in self.getmembers('ffe'):
97
             ffe.all_off()
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
     def all_off(self, device=None, key=None, data=None):
126
     def all_off(self, device=None, key=None, data=None):
100
         self.common_off(device, key, data)
127
         self.common_off(device, key, data)
101
         self.gfw_off(device, key, data)
128
         self.gfw_off(device, key, data)
102
         self.ffw_off(device, key, data)
129
         self.ffw_off(device, key, data)
103
         self.ffe_off(device, key, data)
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
     def devicelist(self):
133
     def devicelist(self):
120
         if self.__devices__ is None:
134
         if self.__devices__ is None:

+ 1
- 0
function/first_floor_east.py View File

55
         # Functionality initialisation
55
         # Functionality initialisation
56
         #
56
         #
57
         self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
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
         ##### TEMPORARY ###################################################################################################################
60
         ##### TEMPORARY ###################################################################################################################
60
         self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)
61
         self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)

+ 4
- 38
function/rooms.py View File

20
 class room(object):
20
 class room(object):
21
     def __init__(self, mqtt_client):
21
     def __init__(self, mqtt_client):
22
         self.mqtt_client = mqtt_client
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
         try:
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
         except AttributeError:
28
         except AttributeError:
29
             logger.exception("Device self.main_light does not exist!")
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…
Cancel
Save