#!/usr/bin/env python # -*- coding: utf-8 -*- # import config import devices from function.modules import brightness_choose_n_action, timer_on_activation, heating_function from function.rooms import room, room_collection from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate 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 first_floor_east(room_collection): def __init__(self, mqtt_client): super().__init__(mqtt_client) self.dining = first_floor_east_dining(mqtt_client) self.floor = first_floor_east_floor(mqtt_client) self.kitchen = first_floor_east_kitchen(mqtt_client) self.livingroom = first_floor_east_living(mqtt_client) self.sleep = first_floor_east_sleep(mqtt_client) 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) # # 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) self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True) # # 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 ) 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) # # 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 ) 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) # # 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 ) 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) # # 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 )