123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
-
- import config
- import devdi.props as props
- from devices import group
- from function.db import get_radiator_data, set_radiator_data
- from function.helpers import day_event
- 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__)
-
- loc = props.LOC_FFE
-
-
- class first_floor_east(room_collection):
- def __init__(self, mqtt_client, pd, vd):
- super().__init__(mqtt_client, pd, vd)
- self.dining = first_floor_east_dining(mqtt_client, pd, vd)
- self.floor = first_floor_east_floor(mqtt_client, pd, vd)
- self.kitchen = first_floor_east_kitchen(mqtt_client, pd, vd)
- self.livingroom = first_floor_east_living(mqtt_client, pd, vd)
- self.sleep = first_floor_east_sleep(mqtt_client, pd, vd)
-
-
- class first_floor_east_floor(room):
- def __init__(self, mqtt_client, pd, vd):
- roo = props.ROO_FLO
- #
- # Device initialisation
- #
- # http://shelly1l-3C6105E4E629
- # main light
- self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
- super().__init__(mqtt_client, pd, vd)
-
- #
- # Virtual Device Interface
- #
- # main light
- self.main_light = videv_switching(
- mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
- self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
- )
-
-
- class first_floor_east_kitchen(room):
- def __init__(self, mqtt_client, pd, vd):
- roo = props.ROO_KIT
- #
- # Device initialisation
- #
- # http://shelly1l-8CAAB5616C01
- # main light
- self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
- # http://shelly1-e89f6d85a466
- # circulation pump
- self.circulation_pump_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR)
- # heating function
- self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
-
- super().__init__(mqtt_client, pd, vd)
-
- #
- # Functionality initialisation
- #
- # circulation pump
- self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, self.circulation_pump_shelly.KEY_OUTPUT_0, 10*60)
- self.circulation_pump_shelly.add_callback(self.circulation_pump_shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
- # heating function
- self.heating_function = heating_function(
- self.heating_valve,
- config.DEFAULT_TEMPERATURE,
- **get_radiator_data(self.heating_valve.topic)
- )
- self.heating_function.add_callback(None, None, set_radiator_data, True)
-
- #
- # Virtual Device Interface
- #
- # main light
- self.main_light_videv = videv_switching(
- mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
- self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
- )
- # circulation pump
- self.circulation_pump_videv = videv_switching_timer(
- mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
- self.circulation_pump_shelly, self.circulation_pump_shelly.KEY_OUTPUT_0,
- self.circulation_pump, timer_on_activation.KEY_TIMER
- )
- # heating function
- self.heating_function_videv = videv_heating(
- mqtt_client, config.TOPIC_FFE_KITCHEN_HEATING_VALVE_VIDEV,
- self.heating_function
- )
-
-
- class first_floor_east_dining(room):
- def __init__(self, mqtt_client, pd, vd):
- roo = props.ROO_DIN
- #
- # Device initialisation
- #
- self.day_events = day_event((6, 0), (22, 0), 30, -30)
-
- # http://shelly1l-84CCA8ADD055
- # main light
- self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
- # floor lamp
- self.floorlamp_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL)
- # heating function
- self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
- # garland
- if config.CHRISTMAS:
- self.garland_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_GAR)
- super().__init__(mqtt_client, pd, vd)
-
- #
- # Functionality initialisation
- #
- self.day_events.add_callback(None, True, self.__day_events__, True)
-
- # main light
- self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
-
- # heating function
- self.heating_function = heating_function(
- self.heating_valve,
- config.DEFAULT_TEMPERATURE,
- **get_radiator_data(self.heating_valve.topic)
- )
- self.heating_function.add_callback(None, None, set_radiator_data, True)
-
- #
- # Virtual Device Interface
- #
- # main light
- self.main_light_videv = videv_switching(
- mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
- self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
- )
- # floor lamp
- self.floorlamp_videv = videv_switching(
- mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
- self.floorlamp_powerplug, self.floorlamp_powerplug.KEY_OUTPUT_0
- )
- # heating function
- self.heating_function_videv = videv_heating(
- mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV,
- self.heating_function
- )
- # garland
- if config.CHRISTMAS:
- self.garland_videv = videv_switching(
- mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
- self.garland_powerplug, self.garland_powerplug.KEY_OUTPUT_0
- )
-
- def __day_events__(self, device, key, data):
- if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
- if config.CHRISTMAS:
- self.garland_powerplug.set_output_0(True)
- elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
- if config.CHRISTMAS:
- self.garland_powerplug.set_output_0(False)
-
-
- class first_floor_east_sleep(room):
- def __init__(self, mqtt_client, pd, vd):
- roo = props.ROO_SLP
- #
- # Device initialisation
- #
- # http://shelly1l-E8DB84A254C7
- # main light
- self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
- self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
- # bed light
- self.bed_light_di_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLD)
- self.bed_light_ma_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLM)
- # heating function
- self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
- # button
- self.button_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_INP)
-
- super().__init__(mqtt_client, pd, vd)
-
- #
- # 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, self.main_light_shelly.KEY_OUTPUT_0)
- self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0)
- # button / main light
- self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_TOGGLE,
- self.main_light_shelly.toggle_output_0_mcb)
- # button / bed light
- self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT,
- self.bed_light_di_tradfri.toggle_output_0_mcb)
- self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.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,
- **get_radiator_data(self.heating_valve.topic)
- )
- self.heating_function.add_callback(None, None, set_radiator_data, True)
-
- #
- # Virtual Device Interface
- #
- # main light
- self.main_light_videv = videv_switch_brightness_color_temp(
- mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
- self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
- self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
- self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
- )
- # bed light
- self.bed_light_di_videv = videv_switch_brightness(
- mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
- self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0,
- self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_BRIGHTNESS,
- )
- self.bed_light_ma_videv = videv_switching(
- mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
- self.bed_light_ma_powerplug, self.bed_light_ma_powerplug.KEY_OUTPUT_0
- )
- # heating function
- self.heating_function_videv = videv_heating(
- mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV,
- self.heating_function
- )
- # button
- 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, pd, vd):
- roo = props.ROO_LIV
- #
- # Device initialisation
- #
- # http://shelly1l-3C6105E3F910
- # main light
- self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
- self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
- # floor lamp
- self.floorlamp_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL)
- # heating function
- self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
- # xmas tree
- if config.CHRISTMAS:
- self.powerplug_xmas_tree = pd.get(props.STG_ZFE, loc, roo, props.FUN_XTR)
- self.powerplug_xmas_star = pd.get(props.STG_ZFE, loc, roo, props.FUN_XST)
-
- super().__init__(mqtt_client, pd, vd)
-
- #
- # Functionality initialisation
- #
- # floor lamp synchronisation with main_light
- self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
- # heating function
- self.heating_function = heating_function(
- self.heating_valve,
- config.DEFAULT_TEMPERATURE,
- **get_radiator_data(self.heating_valve.topic)
- )
- self.heating_function.add_callback(None, None, set_radiator_data, True)
-
- #
- # Virtual Device Interface
- #
- # main light
- self.main_light_videv = videv_switch_brightness_color_temp(
- mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
- self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
- self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
- self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
- )
- # floor lamp
- self.floorlamp_videv = videv_switch_brightness_color_temp(
- mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
- self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_OUTPUT_0,
- self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_BRIGHTNESS,
- self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_COLOR_TEMP
- )
- # heating function
- self.heating_function_videv = videv_heating(
- mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV,
- self.heating_function
- )
- # xmas tree
- if config.CHRISTMAS:
- self.xmas_tree_videv = videv_switching(
- mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
- self.powerplug_xmas_tree, self.powerplug_xmas_tree.KEY_OUTPUT_0
- )
|