diff --git a/function/__init__.py b/function/__init__.py index ad4321b..75f3d53 100644 --- a/function/__init__.py +++ b/function/__init__.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -import config import devices -import inspect -import logging +from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk +from function.first_floor_west import first_floor_west_julian, first_floor_west_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 # TODO: implement bed light dirk fading by input device # TODO: implement heating function sleep_madi @@ -14,12 +14,6 @@ import logging # TODO: implement existing nodered functionality "dirk" (ground floor west) # TODO: implement warning message (incl. fixing all_functions.devicelist -try: - from config import APP_NAME as ROOT_LOGGER_NAME -except ImportError: - ROOT_LOGGER_NAME = 'root' -logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) - class all_functions(object): def __init__(self, mqtt_client): @@ -67,329 +61,3 @@ class all_functions(object): if type(obj) in devices.DEVICE_TYPE_LIST(): self.__devices__.append(obj) return self.__devices__ - - -class room(object): - 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): - 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) - # - # Callback initialisation - # - 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): - self.main_light_shelly.set_output_0(False) - self.main_light_shelly.set_output_1(False) - - def gui_switch_command(self, device, key, data): - logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data)) - self.main_light_shelly.set_output_0(data) - - -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): - super().__init__(mqtt_client, topic_shelly, topic_gui_switch) - self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic=topic_tradfri_light) - # - self.gui_brightness_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_brightness) - self.gui_brightness_main_light.enable(False) - self.gui_brightness_main_light.set_feedback(0) - self.gui_color_temp_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_color_temp) - self.gui_color_temp_main_light.enable(False) - self.gui_color_temp_main_light.set_feedback(0) - # - # Callback initialisation - # - self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.enable_brightness_n_colortemp) - self.main_light_tradfri.add_callback( - devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_main_light) - self.main_light_tradfri.add_callback( - devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_main_light) - self.gui_brightness_main_light.add_callback( - devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_main_light) - self.gui_color_temp_main_light.add_callback( - devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_main_light) - - def enable_brightness_n_colortemp(self, devive, key, data): - self.gui_brightness_main_light.enable(data) - self.gui_color_temp_main_light.enable(data) - if data is False: - self.gui_brightness_main_light.set_feedback(0) - self.gui_color_temp_main_light.set_feedback(0) - else: - self.gui_brightness_main_light.set_feedback(self.main_light_tradfri.brightness) - self.gui_color_temp_main_light.set_feedback(self.main_light_tradfri.color_temp / 10) - - def set_gui_brightness_main_light(self, device, key, data): - self.gui_brightness_main_light.set_feedback(data) - - def set_gui_color_temp_main_light(self, device, key, data): - self.gui_color_temp_main_light.set_feedback(data / 10) - - def set_brightness_main_light(self, device, key, data): - logger.info("Setting brightness \"%s\" main light: %.1f", type(self).__name__, data) - self.main_light_tradfri.set_brightness(data) - - def set_color_temp_main_light(self, device, key, data): - logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data) - self.main_light_tradfri.set_color_temp(data * 10) - - -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): - super().__init__(mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp) - # - # Callback initialisation - # - self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.get_initial_main_light_data) - # - self.main_light_shelly_last = None - - def get_initial_main_light_data(self, device, key, data): - if data is True and self.main_light_shelly_last is not True: - self.send_init_message_main_light() - self.main_light_shelly_last = data - - def send_init_message_main_light(self): - self.main_light_tradfri.mqtt_client.send(self.main_light_tradfri.topic + "/get", '{"state": ""}') - - -class ground_floor_west_floor(room_shelly_silvercrest_light): - # https://shelly1l-84CCA8AD1148 - def __init__(self, mqtt_client): - super().__init__(mqtt_client, "shellies/floor_eg_w", "gui/gfw_sw_floor", - "zigbee_eg_w/light/floor_eg_w/a", "gui/gfw_br_floor", "gui/gfw_ct_floor") - # - # Callback initialisation - # - self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/floor_eg_w/b") - self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, - None, self.sync_brightness_main_light) - self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, - None, self.sync_color_temp_main_light) - - def send_init_message_main_light(self): - return super().send_init_message_main_light() - self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}') - - def sync_brightness_main_light(self, device, key, data): - self.main_light_tradfri_2.set_brightness(data) - - def sync_color_temp_main_light(self, device, key, data): - self.main_light_tradfri_2.set_color_temp(data) - - -class ground_floor_west_marion(room_shelly): - # https://shelly1l-E8DB84A1E067 - def __init__(self, mqtt_client): - super().__init__(mqtt_client, "shellies/marion", "gui/gfw_sw_marion") - - -class ground_floor_west_dirk(room_shelly_tradfri_light): - # https://shelly1l-3C6105E44F27 - def __init__(self, mqtt_client): - super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_dirk", - "zigbee_eg_w/light/dirk", "gui/gfw_br_dirk", "gui/gfw_ct_dirk") - - -class first_floor_west_julian(room_shelly_tradfri_light): - # http://shelly1l-3C6105E43452 - def __init__(self, mqtt_client): - super().__init__(mqtt_client, "shellies/julian", "gui/ffw_sw_julian", - "zigbee_og_e/light/julian", "gui/ffw_br_julian", "gui/ffw_ct_julian") - - -class first_floor_west_living(room_shelly): - # http://shelly1l-84CCA8ACE6A1 - def __init__(self, mqtt_client): - super().__init__(mqtt_client, "shellies/living_mika", "gui/ffw_sw_living") - - -class first_floor_east_floor(room_shelly): - def __init__(self, mqtt_client): - # 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) - def __init__(self, mqtt_client): - # http://shelly1l-8CAAB5616C01 - super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_sw_kitchen") - - -class first_floor_east_dining(room_shelly): - def __init__(self, mqtt_client): - # http://shelly1l-84CCA8ADD055 - super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_sw_diningroom") - self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp") - if config.CHRISTMAS: - self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux") - # - self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_dining_floorlamp") - # - # Callback initialisation - # - self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation) - self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp) - self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, - None, self.gui_switch_feedback_floorlamp) - # - self.main_light_shelly_last = None - - def floorlamp_synchronisation(self, device, key, data): - if data != self.main_light_shelly_last: - logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data)) - self.floorlamp_powerplug.set_output_0(data) - self.main_light_shelly_last = data - - def gui_switch_command_floorlamp(self, device, key, data): - logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data)) - self.floorlamp_powerplug.set_output_0(data) - - def gui_switch_feedback_floorlamp(self, device, key, data): - self.gui_switch_floorlamp.set_feedback(data) - - -class first_floor_east_sleep_madi(room_shelly_tradfri_light): - def __init__(self, mqtt_client): - # http://shelly1l-E8DB84A254C7 - super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sw_sleep_madi", - "zigbee_og_e/light/sleep_madi", "gui/ffe_br_sleep_madi", "gui/ffe_ct_sleep_madi") - # - self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di") - # - self.gui_switch_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_sw_bed_light_di") - self.gui_brightness_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_br_bed_light_di") - self.gui_brightness_bed_light_di.enable(False) - self.gui_brightness_bed_light_di.set_feedback(0) - # - # Callback initialisation - # - 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( - devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_bed_light_di) - self.bed_light_di_tradfri.add_callback( - 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) - - 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 gui_switch_command_bed_light_di(self, device, key, data): - logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data)) - self.bed_light_di_tradfri.set_output_0(data) - - def gui_switch_feedback_bed_light_di(self, device, key, data): - self.gui_switch_bed_light_di.set_feedback(data) - self.gui_brightness_bed_light_di.enable(data) - if data is False: - self.gui_brightness_bed_light_di.set_feedback(0) - else: - self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness) - - def set_gui_brightness_bed_light_di(self, device, key, data): - self.gui_brightness_bed_light_di.set_feedback(data) - - def set_brightness_bed_light_di(self, device, key, data): - logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data) - self.bed_light_di_tradfri.set_brightness(data) - - def toggle_bed_light_di(self, device, key, data): - logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__) - self.bed_light_di_tradfri.set_output_0("toggle") - - -class first_floor_east_living(room_shelly_tradfri_light): - def __init__(self, mqtt_client): - # http://shelly1l-3C6105E3F910 - super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_sw_livingroom", - "zigbee_og_e/light/livingroom", "gui/ffe_br_livingroom", "gui/ffe_ct_livingroom") - for i in range(1, 7): - setattr(self, 'floorlamp_tradfri_%d' % i, - devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i)) - # - self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_living_floorlamp") - self.gui_brightness_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_br_livingroom_floorlamp") - self.gui_brightness_floorlamp.enable(False) - self.gui_brightness_floorlamp.set_feedback(0) - self.gui_color_temp_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_ct_livingroom_floorlamp") - self.gui_color_temp_floorlamp.enable(False) - self.gui_color_temp_floorlamp.set_feedback(0) - # - # Callback initialisation - # - self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation) - self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp) - self.floorlamp_tradfri_1.add_callback( - devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_floorlamp) - self.floorlamp_tradfri_1.add_callback( - devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_floorlamp) - self.floorlamp_tradfri_1.add_callback( - devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_floorlamp) - self.gui_brightness_floorlamp.add_callback( - devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_floorlamp) - self.gui_color_temp_floorlamp.add_callback( - devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp) - # - self.main_light_shelly_last = None - - def __floorlamp_devices__(self): - rv = [] - for i in range(1, 7): - rv.append(getattr(self, 'floorlamp_tradfri_%d' % i)) - return rv - - def floorlamp_synchronisation(self, device, key, data): - if data != self.main_light_shelly_last: - logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data)) - for device in self.__floorlamp_devices__(): - device.set_output_0(data) - self.main_light_shelly_last = data - - def gui_switch_command_floorlamp(self, device, key, data): - logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data)) - for device in self.__floorlamp_devices__(): - device.set_output_0(data) - - def gui_switch_feedback_floorlamp(self, device, key, data): - self.gui_switch_floorlamp.set_feedback(data) - self.gui_brightness_floorlamp.enable(data) - self.gui_color_temp_floorlamp.enable(data) - if data is False: - self.gui_brightness_floorlamp.set_feedback(0) - self.gui_color_temp_floorlamp.set_feedback(0) - else: - self.gui_brightness_floorlamp.set_feedback(self.floorlamp_tradfri_1.brightness) - self.gui_color_temp_floorlamp.set_feedback(self.floorlamp_tradfri_1.color_temp / 10) - - def set_gui_brightness_floorlamp(self, device, key, data): - self.gui_brightness_floorlamp.set_feedback(data) - - def set_gui_color_temp_floorlamp(self, device, key, data): - self.gui_color_temp_floorlamp.set_feedback(data / 10) - - def set_brightness_floorlamp(self, device, key, data): - logger.info("Setting brightness \"%s\" floorlamp: %.1f", type(self).__name__, data) - for device in self.__floorlamp_devices__(): - device.set_brightness(data) - - def set_color_temp_floorlamp(self, device, key, data): - logger.info("Setting color_temp \"%s\" floorlamp: %.1f", type(self).__name__, data) - for device in self.__floorlamp_devices__(): - device.set_color_temp(data * 10) diff --git a/function/first_floor_east.py b/function/first_floor_east.py new file mode 100644 index 0000000..3831181 --- /dev/null +++ b/function/first_floor_east.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# + +import config +import devices +import logging +from function.rooms import room_shelly, room_shelly_tradfri_light + +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' +logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) + + +class first_floor_east_floor(room_shelly): + def __init__(self, mqtt_client): + # 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) + def __init__(self, mqtt_client): + # http://shelly1l-8CAAB5616C01 + super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_sw_kitchen") + + +class first_floor_east_dining(room_shelly): + def __init__(self, mqtt_client): + # http://shelly1l-84CCA8ADD055 + super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_sw_diningroom") + self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp") + if config.CHRISTMAS: + self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux") + # + self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_dining_floorlamp") + # + # Callback initialisation + # + self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation) + self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp) + self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, + None, self.gui_switch_feedback_floorlamp) + # + self.main_light_shelly_last = None + + def floorlamp_synchronisation(self, device, key, data): + if data != self.main_light_shelly_last: + logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data)) + self.floorlamp_powerplug.set_output_0(data) + self.main_light_shelly_last = data + + def gui_switch_command_floorlamp(self, device, key, data): + logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data)) + self.floorlamp_powerplug.set_output_0(data) + + def gui_switch_feedback_floorlamp(self, device, key, data): + self.gui_switch_floorlamp.set_feedback(data) + + +class first_floor_east_sleep_madi(room_shelly_tradfri_light): + def __init__(self, mqtt_client): + # http://shelly1l-E8DB84A254C7 + super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sw_sleep_madi", + "zigbee_og_e/light/sleep_madi", "gui/ffe_br_sleep_madi", "gui/ffe_ct_sleep_madi") + # + self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di") + # + self.gui_switch_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_sw_bed_light_di") + self.gui_brightness_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_br_bed_light_di") + self.gui_brightness_bed_light_di.enable(False) + self.gui_brightness_bed_light_di.set_feedback(0) + # + # Callback initialisation + # + 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( + devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_bed_light_di) + self.bed_light_di_tradfri.add_callback( + 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) + + 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 gui_switch_command_bed_light_di(self, device, key, data): + logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data)) + self.bed_light_di_tradfri.set_output_0(data) + + def gui_switch_feedback_bed_light_di(self, device, key, data): + self.gui_switch_bed_light_di.set_feedback(data) + self.gui_brightness_bed_light_di.enable(data) + if data is False: + self.gui_brightness_bed_light_di.set_feedback(0) + else: + self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness) + + def set_gui_brightness_bed_light_di(self, device, key, data): + self.gui_brightness_bed_light_di.set_feedback(data) + + def set_brightness_bed_light_di(self, device, key, data): + logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data) + self.bed_light_di_tradfri.set_brightness(data) + + def toggle_bed_light_di(self, device, key, data): + logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__) + self.bed_light_di_tradfri.set_output_0("toggle") + + +class first_floor_east_living(room_shelly_tradfri_light): + def __init__(self, mqtt_client): + # http://shelly1l-3C6105E3F910 + super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_sw_livingroom", + "zigbee_og_e/light/livingroom", "gui/ffe_br_livingroom", "gui/ffe_ct_livingroom") + for i in range(1, 7): + setattr(self, 'floorlamp_tradfri_%d' % i, + devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i)) + # + self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_living_floorlamp") + self.gui_brightness_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_br_livingroom_floorlamp") + self.gui_brightness_floorlamp.enable(False) + self.gui_brightness_floorlamp.set_feedback(0) + self.gui_color_temp_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_ct_livingroom_floorlamp") + self.gui_color_temp_floorlamp.enable(False) + self.gui_color_temp_floorlamp.set_feedback(0) + # + # Callback initialisation + # + self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation) + self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp) + self.floorlamp_tradfri_1.add_callback( + devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_floorlamp) + self.floorlamp_tradfri_1.add_callback( + devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_floorlamp) + self.floorlamp_tradfri_1.add_callback( + devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_floorlamp) + self.gui_brightness_floorlamp.add_callback( + devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_floorlamp) + self.gui_color_temp_floorlamp.add_callback( + devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp) + # + self.main_light_shelly_last = None + + def __floorlamp_devices__(self): + rv = [] + for i in range(1, 7): + rv.append(getattr(self, 'floorlamp_tradfri_%d' % i)) + return rv + + def floorlamp_synchronisation(self, device, key, data): + if data != self.main_light_shelly_last: + logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data)) + for device in self.__floorlamp_devices__(): + device.set_output_0(data) + self.main_light_shelly_last = data + + def gui_switch_command_floorlamp(self, device, key, data): + logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data)) + for device in self.__floorlamp_devices__(): + device.set_output_0(data) + + def gui_switch_feedback_floorlamp(self, device, key, data): + self.gui_switch_floorlamp.set_feedback(data) + self.gui_brightness_floorlamp.enable(data) + self.gui_color_temp_floorlamp.enable(data) + if data is False: + self.gui_brightness_floorlamp.set_feedback(0) + self.gui_color_temp_floorlamp.set_feedback(0) + else: + self.gui_brightness_floorlamp.set_feedback(self.floorlamp_tradfri_1.brightness) + self.gui_color_temp_floorlamp.set_feedback(self.floorlamp_tradfri_1.color_temp / 10) + + def set_gui_brightness_floorlamp(self, device, key, data): + self.gui_brightness_floorlamp.set_feedback(data) + + def set_gui_color_temp_floorlamp(self, device, key, data): + self.gui_color_temp_floorlamp.set_feedback(data / 10) + + def set_brightness_floorlamp(self, device, key, data): + logger.info("Setting brightness \"%s\" floorlamp: %.1f", type(self).__name__, data) + for device in self.__floorlamp_devices__(): + device.set_brightness(data) + + def set_color_temp_floorlamp(self, device, key, data): + logger.info("Setting color_temp \"%s\" floorlamp: %.1f", type(self).__name__, data) + for device in self.__floorlamp_devices__(): + device.set_color_temp(data * 10) diff --git a/function/first_floor_west.py b/function/first_floor_west.py new file mode 100644 index 0000000..0dc4972 --- /dev/null +++ b/function/first_floor_west.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# + +import logging +from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light + +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' +logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) + + +class first_floor_west_julian(room_shelly_tradfri_light): + # http://shelly1l-3C6105E43452 + def __init__(self, mqtt_client): + super().__init__(mqtt_client, "shellies/julian", "gui/ffw_sw_julian", + "zigbee_og_e/light/julian", "gui/ffw_br_julian", "gui/ffw_ct_julian") + + +class first_floor_west_living(room_shelly): + # http://shelly1l-84CCA8ACE6A1 + def __init__(self, mqtt_client): + super().__init__(mqtt_client, "shellies/living_mika", "gui/ffw_sw_living") diff --git a/function/ground_floor_west.py b/function/ground_floor_west.py new file mode 100644 index 0000000..07c919f --- /dev/null +++ b/function/ground_floor_west.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# + +import devices +import logging +from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light + +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' +logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) + + +class ground_floor_west_floor(room_shelly_silvercrest_light): + # https://shelly1l-84CCA8AD1148 + def __init__(self, mqtt_client): + super().__init__(mqtt_client, "shellies/floor_eg_w", "gui/gfw_sw_floor", + "zigbee_eg_w/light/floor_eg_w/a", "gui/gfw_br_floor", "gui/gfw_ct_floor") + # + # Callback initialisation + # + self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/floor_eg_w/b") + self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, + None, self.sync_brightness_main_light) + self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, + None, self.sync_color_temp_main_light) + + def send_init_message_main_light(self): + return super().send_init_message_main_light() + self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}') + + def sync_brightness_main_light(self, device, key, data): + self.main_light_tradfri_2.set_brightness(data) + + def sync_color_temp_main_light(self, device, key, data): + self.main_light_tradfri_2.set_color_temp(data) + + +class ground_floor_west_marion(room_shelly): + # https://shelly1l-E8DB84A1E067 + def __init__(self, mqtt_client): + super().__init__(mqtt_client, "shellies/marion", "gui/gfw_sw_marion") + + +class ground_floor_west_dirk(room_shelly_tradfri_light): + # https://shelly1l-3C6105E44F27 + def __init__(self, mqtt_client): + super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_dirk", + "zigbee_eg_w/light/dirk", "gui/gfw_br_dirk", "gui/gfw_ct_dirk") diff --git a/function/rooms.py b/function/rooms.py new file mode 100644 index 0000000..25d13d2 --- /dev/null +++ b/function/rooms.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# + +import config +import devices +import logging + +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' +logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) + + +class room(object): + 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): + 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) + # + # Callback initialisation + # + 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): + self.main_light_shelly.set_output_0(False) + self.main_light_shelly.set_output_1(False) + + def gui_switch_command(self, device, key, data): + logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data)) + self.main_light_shelly.set_output_0(data) + + +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): + super().__init__(mqtt_client, topic_shelly, topic_gui_switch) + self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic=topic_tradfri_light) + # + self.gui_brightness_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_brightness) + self.gui_brightness_main_light.enable(False) + self.gui_brightness_main_light.set_feedback(0) + self.gui_color_temp_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_color_temp) + self.gui_color_temp_main_light.enable(False) + self.gui_color_temp_main_light.set_feedback(0) + # + # Callback initialisation + # + self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.enable_brightness_n_colortemp) + self.main_light_tradfri.add_callback( + devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_main_light) + self.main_light_tradfri.add_callback( + devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_main_light) + self.gui_brightness_main_light.add_callback( + devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_main_light) + self.gui_color_temp_main_light.add_callback( + devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_main_light) + + def enable_brightness_n_colortemp(self, devive, key, data): + self.gui_brightness_main_light.enable(data) + self.gui_color_temp_main_light.enable(data) + if data is False: + self.gui_brightness_main_light.set_feedback(0) + self.gui_color_temp_main_light.set_feedback(0) + else: + self.gui_brightness_main_light.set_feedback(self.main_light_tradfri.brightness) + self.gui_color_temp_main_light.set_feedback(self.main_light_tradfri.color_temp / 10) + + def set_gui_brightness_main_light(self, device, key, data): + self.gui_brightness_main_light.set_feedback(data) + + def set_gui_color_temp_main_light(self, device, key, data): + self.gui_color_temp_main_light.set_feedback(data / 10) + + def set_brightness_main_light(self, device, key, data): + logger.info("Setting brightness \"%s\" main light: %.1f", type(self).__name__, data) + self.main_light_tradfri.set_brightness(data) + + def set_color_temp_main_light(self, device, key, data): + logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data) + self.main_light_tradfri.set_color_temp(data * 10) + + +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): + super().__init__(mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp) + # + # Callback initialisation + # + self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.get_initial_main_light_data) + # + self.main_light_shelly_last = None + + def get_initial_main_light_data(self, device, key, data): + if data is True and self.main_light_shelly_last is not True: + self.send_init_message_main_light() + self.main_light_shelly_last = data + + def send_init_message_main_light(self): + self.main_light_tradfri.mqtt_client.send(self.main_light_tradfri.topic + "/get", '{"state": ""}')