|
@@ -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))
|