#!/usr/bin/env python # -*- coding: utf-8 -*- # import config import devices from function.modules import brightness_choose_n_action, timer_on_activation, heating_function import logging from function.rooms import room from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate 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): def __init__(self, mqtt_client): # # Device initialisation # # http://shelly1l-3C6105E4E629 self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY) super().__init__(mqtt_client) ##### TEMPORARY ################################################################################################################### self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb) ##### TEMPORARY ################################################################################################################### # # Virtual Device Interface # self.main_light = videv_switching( mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0 ) class first_floor_east_kitchen(room): def __init__(self, mqtt_client): # # Device initialisation # # http://shelly1l-8CAAB5616C01 self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY) # http://shelly1-e89f6d85a466/ self.circulation_pump_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY) super().__init__(mqtt_client) # # Functionality initialisation # self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60) ##### TEMPORARY ################################################################################################################### self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb) self.gui_circulation_pump = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI) self.gui_circulation_pump.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.circulation_pump_shelly.set_output_0_mcb) self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_circulation_pump.set_state_mcb) self.circulation_pump.add_callback(timer_on_activation.KEY_TIMER, None, self.gui_circulation_pump.set_timer_mcb, True) ##### TEMPORARY ################################################################################################################### # # Virtual Device Interface # self.main_light_videv = videv_switching( mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0 ) self.circulation_pump_videv = videv_switching_timer( mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV, self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, self.circulation_pump, timer_on_activation.KEY_TIMER ) def all_off(self, device=None, key=None, data=None): self.circulation_pump_shelly.set_output_0(False) self.circulation_pump_shelly.set_output_1(False) return super().all_off(device, key, data) class first_floor_east_dining(room): def __init__(self, mqtt_client): # # Device initialisation # # http://shelly1l-84CCA8ADD055 self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY) self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG) if config.CHRISTMAS: self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG) super().__init__(mqtt_client) ##### TEMPORARY ################################################################################################################### self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb) self.gui_floorlamp = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI) self.gui_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.floorlamp_powerplug.set_output_0_mcb) self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb) ##### TEMPORARY ################################################################################################################### # # Functionality initialisation # self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True) # # Virtual Device Interface # self.main_light_videv = videv_switching( mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0 ) self.floorlamp_videv = videv_switching( mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV, self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0 ) if config.CHRISTMAS: self.garland_videv = videv_switching( mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV, self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0 ) def all_off(self, device=None, key=None, data=None): super().all_off(device, key, data) self.floorlamp_powerplug.set_output_0(False) if config.CHRISTMAS: self.garland_powerplug.set_output_0(False) class first_floor_east_sleep(room): def __init__(self, mqtt_client): # # Device initialisation # # http://shelly1l-E8DB84A254C7 self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY) self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE) self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE) self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG) self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE) self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE) super().__init__(mqtt_client) # # Functionality initialisation # # button / brightness function self.brightness_functions = brightness_choose_n_action(self.button_tradfri) self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0) self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0) # button / main light self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE, self.main_light_shelly.toggle_output_0_mcb) # button / bed light self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT, self.bed_light_di_tradfri.toggle_output_0_mcb) self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG, self.bed_light_ma_powerplug.toggle_output_0_mcb) # heating function self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_FFE_SLEEP) ##### TEMPORARY ################################################################################################################### # main light self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb) self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb) self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb) # bed light self.gui_bed_light_di = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI) self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.bed_light_di_tradfri.set_output_0_mcb) self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_state_mcb) self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb) self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.bed_light_di_tradfri.set_brightness_mcb) self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb) self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_bed_light_di.set_brightness_mcb) self.gui_bed_light_ma = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_GUI) self.gui_bed_light_ma.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.bed_light_ma_powerplug.set_output_0_mcb) self.bed_light_ma_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_bed_light_ma.set_state_mcb) # heating self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_GUI) self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_temperature_mcb, True) def set_heating_setpoint(device, key, data): self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint) self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True) def boost(device, key, data): self.heating_function.set(heating_function.KEY_START_BOOST, data) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost) def setpoint_to_default(device, key, data): self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default) def away_mode(device, key, data): self.heating_function.set(heating_function.KEY_AWAY_MODE, data) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode) self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb) def summer_mode(device, key, data): self.heating_function.set(heating_function.KEY_SUMMER_MODE, data) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode) self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb) self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb) # active device led self.gui_led_active_device = devices.nodered_gui_leds(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED) def update_active_device_led(device, key, data): for i in range(0, len(self.brightness_functions.brightness_device_list)): self.gui_led_active_device.set_led(devices.nodered_gui_leds.KEY_LED_LIST[i], data == i) self.brightness_functions.add_callback(brightness_choose_n_action.KEY_ACTIVE_DEVICE, None, update_active_device_led, True) ##### TEMPORARY ################################################################################################################### # # Virtual Device Interface # self.main_light_videv = videv_switch_brightness_color_temp( mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0, self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS, self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP ) self.bed_light_di_videv = videv_switch_brightness( mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0, self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS, ) self.bed_light_ma_videv = videv_switching( mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0 ) self.heating_function_videv = videv_heating( mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV, self.heating_function ) self.brightness_functions_device_videv = videv_multistate( mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV, brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2 ) def all_off(self, device=None, key=None, data=None): super().all_off(device, key, data) self.bed_light_di_tradfri.set_output_0(False) self.bed_light_ma_powerplug.set_output_0(False) class first_floor_east_living(room): def __init__(self, mqtt_client): # # Device initialisation # # http://shelly1l-3C6105E3F910 self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY) self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE) self.floorlamp_tradfri = devices.group( *[devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i) for i in range(1, 7)]) if config.CHRISTMAS: self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG) self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG) super().__init__(mqtt_client) # # Functionality initialisation # # floor lamp synchronisation with main_light self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True) ##### TEMPORARY ################################################################################################################### # main light self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb) self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb) self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb) self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb) self.gui_floorlamp = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI) self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.floorlamp_tradfri.set_output_0_mcb) self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.floorlamp_tradfri.set_brightness_mcb) self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.floorlamp_tradfri.set_color_temp_mcb) self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb) self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_enable_mcb) self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_floorlamp.set_brightness_mcb) self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_floorlamp.set_color_temp_mcb) if config.CHRISTMAS: self.gui_xmas_tree = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI) self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb) self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_xmas_tree.set_state_mcb) self.gui_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb) ##### TEMPORARY ################################################################################################################### # # Virtual Device Interface # self.main_light_videv = videv_switch_brightness_color_temp( mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0, self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS, self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP ) self.floorlamp_videv = videv_switch_brightness_color_temp( mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV, self.floorlamp_tradfri, devices.tradfri_light.KEY_OUTPUT_0, self.floorlamp_tradfri, devices.tradfri_light.KEY_BRIGHTNESS, self.floorlamp_tradfri, devices.tradfri_light.KEY_COLOR_TEMP ) if config.CHRISTMAS: self.xmas_tree_videv = videv_switching( mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV, self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0 ) def all_off(self, device=None, key=None, data=None): super().all_off(device, key, data) self.floorlamp_tradfri.set_output_0(False) if config.CHRISTMAS: self.powerplug_xmas_tree.set_output_0(False) self.powerplug_xmas_star.set_output_0(False)