Browse Source

fading sleep madi for last activated device

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
e870dd11e2
2 changed files with 31 additions and 9 deletions
  1. 1
    2
      function/__init__.py
  2. 30
    7
      function/first_floor_east.py

+ 1
- 2
function/__init__.py View File

7
 from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep_madi, first_floor_east_living
7
 from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep_madi, first_floor_east_living
8
 import inspect
8
 import inspect
9
 
9
 
10
-# TODO: implement bed light dirk fading by input device
11
 # TODO: implement heating function sleep_madi
10
 # TODO: implement heating function sleep_madi
12
 # TODO: implement circulation pump
11
 # TODO: implement circulation pump
13
 # TODO: implement switch off functionality (except of switch off button transportation)
12
 # TODO: implement switch off functionality (except of switch off button transportation)
56
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "arrow_right_click",
55
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "arrow_right_click",
57
                                                    self.ffe_floor.toggle_main_light)
56
                                                    self.ffe_floor.toggle_main_light)
58
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, None,
57
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, None,
59
-                                                   self.ffe_sleep_madi.fade_bed_light)
58
+                                                   self.ffe_sleep_madi.fade_light)
60
 
59
 
61
     def devicelist(self):
60
     def devicelist(self):
62
         if self.__devices__ is None:
61
         if self.__devices__ is None:

+ 30
- 7
function/first_floor_east.py View File

87
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
87
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
88
         self.gui_brightness_bed_light_di.add_callback(
88
         self.gui_brightness_bed_light_di.add_callback(
89
             devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
89
             devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
90
+        #
91
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
92
+        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
93
+                                               None, self.state_machine_last_activated_device)
94
+        #
95
+        self.last_activated_device = None
90
 
96
 
91
     def toggle_main_light(self, device, key, data):
97
     def toggle_main_light(self, device, key, data):
92
         logger.info("Toggeling \"%s\" main light", type(self).__name__)
98
         logger.info("Toggeling \"%s\" main light", type(self).__name__)
93
         self.main_light_shelly.set_output_0("toggle")
99
         self.main_light_shelly.set_output_0("toggle")
94
 
100
 
95
-    def fade_bed_light(self, device, topic, data):
101
+    def state_machine_last_activated_device(self, device, topic, data):
102
+        if data is True:
103
+            self.last_activated_device = device.topic
104
+        elif data is False:
105
+            if device.topic == self.main_light_shelly.topic and self.bed_light_di_tradfri.output_0:
106
+                self.last_activated_device = self.bed_light_di_tradfri.topic
107
+            elif device.topic == self.bed_light_di_tradfri.topic and self.main_light_shelly.output_0:
108
+                self.last_activated_device = self.main_light_shelly.topic
109
+            else:
110
+                self.last_activated_device = None
111
+
112
+    def fade_light(self, device, topic, data):
113
+        if self.last_activated_device == self.main_light_shelly.topic:
114
+            target = self.main_light_tradfri
115
+        elif self.last_activated_device == self.bed_light_di_tradfri.topic:
116
+            target = self.bed_light_di_tradfri
117
+        else:
118
+            return
96
         if (data == 'brightness_up_hold'):
119
         if (data == 'brightness_up_hold'):
97
-            logger.info("Increasing brightness \"%s\" bed light dirk", type(self).__name__)
98
-            self.bed_light_di_tradfri.brightness_inc()
120
+            logger.info("Increasing brightness \"%s\" %s", type(self).__name__, target.topic)
121
+            target.brightness_inc()
99
         elif (data == 'brightness_down_hold'):
122
         elif (data == 'brightness_down_hold'):
100
-            logger.info("Decreasing brightness \"%s\" bed light dirk", type(self).__name__)
101
-            self.bed_light_di_tradfri.brightness_dec()
123
+            logger.info("Decreasing brightness \"%s\" %s", type(self).__name__, target.topic)
124
+            target.brightness_dec()
102
         elif (data.startswith('brightness') and data.endswith('release')):
125
         elif (data.startswith('brightness') and data.endswith('release')):
103
-            logger.info("Stoping brightness change \"%s\" bed light dirk", type(self).__name__)
104
-            self.bed_light_di_tradfri.brightness_stop()
126
+            logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
127
+            target.brightness_stop()
105
 
128
 
106
     def gui_switch_command_bed_light_di(self, device, key, data):
129
     def gui_switch_command_bed_light_di(self, device, key, data):
107
         logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
130
         logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))

Loading…
Cancel
Save