Quellcode durchsuchen

fading sleep madi for last activated device

tags/v1.0.0
Dirk Alders vor 2 Jahren
Ursprung
Commit
e870dd11e2
2 geänderte Dateien mit 31 neuen und 9 gelöschten Zeilen
  1. 1
    2
      function/__init__.py
  2. 30
    7
      function/first_floor_east.py

+ 1
- 2
function/__init__.py Datei anzeigen

@@ -7,7 +7,6 @@ from function.first_floor_west import first_floor_west_julian, first_floor_west_
7 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 8
 import inspect
9 9
 
10
-# TODO: implement bed light dirk fading by input device
11 10
 # TODO: implement heating function sleep_madi
12 11
 # TODO: implement circulation pump
13 12
 # TODO: implement switch off functionality (except of switch off button transportation)
@@ -56,7 +55,7 @@ class all_functions(object):
56 55
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "arrow_right_click",
57 56
                                                    self.ffe_floor.toggle_main_light)
58 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 60
     def devicelist(self):
62 61
         if self.__devices__ is None:

+ 30
- 7
function/first_floor_east.py Datei anzeigen

@@ -87,21 +87,44 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
87 87
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
88 88
         self.gui_brightness_bed_light_di.add_callback(
89 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 97
     def toggle_main_light(self, device, key, data):
92 98
         logger.info("Toggeling \"%s\" main light", type(self).__name__)
93 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 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 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 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 129
     def gui_switch_command_bed_light_di(self, device, key, data):
107 130
         logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))

Laden…
Abbrechen
Speichern