fading sleep madi for last activated device

This commit is contained in:
Dirk Alders 2022-12-20 20:58:55 +01:00
parent 3a151bc68b
commit e870dd11e2
2 changed files with 31 additions and 9 deletions

View File

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

View File

@ -87,21 +87,44 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di) devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
self.gui_brightness_bed_light_di.add_callback( self.gui_brightness_bed_light_di.add_callback(
devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di) devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
#
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
None, self.state_machine_last_activated_device)
#
self.last_activated_device = None
def toggle_main_light(self, device, key, data): def toggle_main_light(self, device, key, data):
logger.info("Toggeling \"%s\" main light", type(self).__name__) logger.info("Toggeling \"%s\" main light", type(self).__name__)
self.main_light_shelly.set_output_0("toggle") self.main_light_shelly.set_output_0("toggle")
def fade_bed_light(self, device, topic, data): def state_machine_last_activated_device(self, device, topic, data):
if data is True:
self.last_activated_device = device.topic
elif data is False:
if device.topic == self.main_light_shelly.topic and self.bed_light_di_tradfri.output_0:
self.last_activated_device = self.bed_light_di_tradfri.topic
elif device.topic == self.bed_light_di_tradfri.topic and self.main_light_shelly.output_0:
self.last_activated_device = self.main_light_shelly.topic
else:
self.last_activated_device = None
def fade_light(self, device, topic, data):
if self.last_activated_device == self.main_light_shelly.topic:
target = self.main_light_tradfri
elif self.last_activated_device == self.bed_light_di_tradfri.topic:
target = self.bed_light_di_tradfri
else:
return
if (data == 'brightness_up_hold'): if (data == 'brightness_up_hold'):
logger.info("Increasing brightness \"%s\" bed light dirk", type(self).__name__) logger.info("Increasing brightness \"%s\" %s", type(self).__name__, target.topic)
self.bed_light_di_tradfri.brightness_inc() target.brightness_inc()
elif (data == 'brightness_down_hold'): elif (data == 'brightness_down_hold'):
logger.info("Decreasing brightness \"%s\" bed light dirk", type(self).__name__) logger.info("Decreasing brightness \"%s\" %s", type(self).__name__, target.topic)
self.bed_light_di_tradfri.brightness_dec() target.brightness_dec()
elif (data.startswith('brightness') and data.endswith('release')): elif (data.startswith('brightness') and data.endswith('release')):
logger.info("Stoping brightness change \"%s\" bed light dirk", type(self).__name__) logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
self.bed_light_di_tradfri.brightness_stop() target.brightness_stop()
def gui_switch_command_bed_light_di(self, device, key, data): def gui_switch_command_bed_light_di(self, device, key, data):
logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data)) logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))