led indicator added for active fade object sleep madi

This commit is contained in:
Dirk Alders 2022-12-21 07:12:17 +01:00
parent e870dd11e2
commit 4761f0a29e
2 changed files with 67 additions and 43 deletions

View File

@ -4,6 +4,7 @@
import config
import devices
import json
import logging
from function.rooms import room_shelly, room_shelly_tradfri_light
@ -19,10 +20,6 @@ class first_floor_east_floor(room_shelly):
# http://shelly1l-3C6105E4E629
super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
def toggle_main_light(self, device, key, data):
logger.info("Toggeling \"%s\" main light", type(self).__name__)
self.main_light_shelly.set_output_0("toggle")
class first_floor_east_kitchen(room_shelly):
# TODO: add circulation pump (switch, time)
@ -79,6 +76,11 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
#
# Callback initialisation
#
self.init_bed_light_functions()
self.init_fade_function()
# bed light
def init_bed_light_functions(self):
self.gui_switch_bed_light_di.add_callback(
devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
self.bed_light_di_tradfri.add_callback(
@ -87,44 +89,6 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
self.gui_brightness_bed_light_di.add_callback(
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):
logger.info("Toggeling \"%s\" main light", type(self).__name__)
self.main_light_shelly.set_output_0("toggle")
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'):
logger.info("Increasing brightness \"%s\" %s", type(self).__name__, target.topic)
target.brightness_inc()
elif (data == 'brightness_down_hold'):
logger.info("Decreasing brightness \"%s\" %s", type(self).__name__, target.topic)
target.brightness_dec()
elif (data.startswith('brightness') and data.endswith('release')):
logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
target.brightness_stop()
def gui_switch_command_bed_light_di(self, device, key, data):
logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
@ -149,6 +113,46 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
self.bed_light_di_tradfri.set_output_0("toggle")
# fade
def init_fade_function(self):
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 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
self.mqtt_client.send("gui/ffe_led_main_light_sleep/set",
json.dumps(self.last_activated_device == self.main_light_shelly.topic))
self.mqtt_client.send("gui/ffe_led_bed_light_sleep_di/set",
json.dumps(self.last_activated_device == self.bed_light_di_tradfri.topic))
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'):
logger.info("Increasing brightness \"%s\" %s", type(self).__name__, target.topic)
target.brightness_inc()
elif (data == 'brightness_down_hold'):
logger.info("Decreasing brightness \"%s\" %s", type(self).__name__, target.topic)
target.brightness_dec()
elif (data.startswith('brightness') and data.endswith('release')):
logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
target.brightness_stop()
class first_floor_east_living(room_shelly_tradfri_light):
def __init__(self, mqtt_client):

View File

@ -14,12 +14,16 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
class room(object):
def __init__(self, mqtt_client):
self.mqtt_client = mqtt_client
def gui_switch_feedback(self, device, key, data):
self.gui_switch_main_light.set_feedback(data)
class room_shelly(room):
def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
super().__init__(mqtt_client)
self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
#
self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
@ -29,7 +33,8 @@ class room_shelly(room):
self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_feedback)
def all_off(self):
def all_off(self, device=None, key=None, data=None):
logger.info("Switching all off \"%s\"", type(self).__name__)
self.main_light_shelly.set_output_0(False)
self.main_light_shelly.set_output_1(False)
@ -37,6 +42,10 @@ class room_shelly(room):
logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
self.main_light_shelly.set_output_0(data)
def toggle_main_light(self, device, key, data):
logger.info("Toggeling \"%s\" main light", type(self).__name__)
self.main_light_shelly.set_output_0("toggle")
class room_shelly_tradfri_light(room_shelly):
def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
@ -86,6 +95,17 @@ class room_shelly_tradfri_light(room_shelly):
logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data)
self.main_light_tradfri.set_color_temp(data * 10)
def fade_light(self, device, topic, data):
if (data == 'brightness_up_hold'):
logger.info("Increasing brightness \"%s\" main light", type(self).__name__)
self.main_light_tradfri.brightness_inc()
elif (data == 'brightness_down_hold'):
logger.info("Decreasing brightness \"%s\" main light", type(self).__name__)
self.main_light_tradfri.brightness_dec()
elif (data.startswith('brightness') and data.endswith('release')):
logger.info("Stoping brightness change \"%s\" main light", type(self).__name__)
self.main_light_tradfri.brightness_stop()
class room_shelly_silvercrest_light(room_shelly_tradfri_light):
def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):