244 lines
11 KiB
Python
244 lines
11 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
|
|
import config
|
|
from devdi import topic as props
|
|
from devdi import rooms
|
|
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, switched_light
|
|
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):
|
|
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, pd)
|
|
self.livingroom = first_floor_east_living(mqtt_client, pd)
|
|
self.sleep = first_floor_east_sleep(mqtt_client)
|
|
|
|
|
|
class first_floor_east_floor(rooms.ffe_floor, room):
|
|
def __init__(self, mqtt_client):
|
|
super().__init__(mqtt_client)
|
|
room.__init__(self, mqtt_client)
|
|
#
|
|
# connect videv and switch
|
|
self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
|
|
|
|
|
|
class first_floor_east_kitchen(room):
|
|
def __init__(self, mqtt_client, pd):
|
|
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)
|
|
self.main_light_hue = pd.get(props.STG_ZFE, 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)
|
|
|
|
#
|
|
# 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)
|
|
# Request hue data of lead light after power on
|
|
switched_light(self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0, self.main_light_hue)
|
|
# 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_KITCHEN_MAIN_LIGHT_VIDEV,
|
|
self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
|
|
self.main_light_hue, self.main_light_hue.KEY_BRIGHTNESS,
|
|
self.main_light_hue, self.main_light_hue.KEY_COLOR_TEMP
|
|
)
|
|
# 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(rooms.ffe_diningroom, room):
|
|
def __init__(self, mqtt_client):
|
|
super().__init__(mqtt_client)
|
|
room.__init__(self, mqtt_client)
|
|
#
|
|
self.day_events = day_event((6, 0), (22, 0), 30, -30)
|
|
self.day_events.add_callback(None, True, self.__day_events__, True)
|
|
|
|
# light <-> videv
|
|
self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
|
|
self.videv_floor_light.connect_sw_device(self.switch_floor_light, self.switch_floor_light.KEY_OUTPUT_0)
|
|
if config.CHRISTMAS:
|
|
self.videv_garland_light.connect_sw_device(self.switch_garland_light, self.switch_garland_light.KEY_OUTPUT_0)
|
|
|
|
# main light -> floor_light
|
|
self.switch_main_light.add_callback(self.switch_main_light.KEY_OUTPUT_0, None, self.switch_floor_light.set_output_0_mcb, True)
|
|
|
|
# heating function
|
|
self.heating_function = heating_function(
|
|
self.valve_heating,
|
|
config.DEFAULT_TEMPERATURE,
|
|
**get_radiator_data(self.valve_heating.topic)
|
|
)
|
|
self.heating_function.add_callback(None, None, set_radiator_data, True)
|
|
# heating function <-> videv
|
|
self.videv_heating.connect_heating_function(self.heating_function)
|
|
|
|
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(rooms.ffe_sleep, room):
|
|
def __init__(self, mqtt_client):
|
|
super().__init__(mqtt_client)
|
|
room.__init__(self, mqtt_client)
|
|
#
|
|
self.light_wardrobe_light.disable_all_off() # Always on - Off by light sensor
|
|
# light <-> videv
|
|
self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
|
|
self.videv_main_light.connect_br_device(self.light_main_light, self.light_main_light.KEY_BRIGHTNESS)
|
|
self.videv_main_light.connect_ct_device(self.light_main_light, self.light_main_light.KEY_COLOR_TEMP)
|
|
#
|
|
self.videv_bed_dirk_light.connect_sw_device(self.light_bed_dirk_light, self.light_bed_dirk_light.KEY_OUTPUT_0)
|
|
self.videv_bed_dirk_light.connect_br_device(self.light_bed_dirk_light, self.light_bed_dirk_light.KEY_BRIGHTNESS)
|
|
#
|
|
self.videv_bed_marion_light.connect_sw_device(self.switch_bed_marion_light, self.switch_bed_marion_light.KEY_OUTPUT_0)
|
|
#
|
|
self.videv_wardrobe_light.connect_sw_device(self.light_wardrobe_light, self.light_wardrobe_light.KEY_OUTPUT_0)
|
|
self.videv_wardrobe_light.connect_br_device(self.light_wardrobe_light, self.light_wardrobe_light.KEY_BRIGHTNESS)
|
|
|
|
# button / brightness function
|
|
self.brightness_functions = brightness_choose_n_action(self.input_device)
|
|
self.brightness_functions.add(self.light_main_light, self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
|
|
self.brightness_functions.add(self.light_bed_dirk_light, self.light_bed_dirk_light, self.light_bed_dirk_light.KEY_OUTPUT_0)
|
|
# button / main light
|
|
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_TOGGLE, self.switch_main_light.toggle_output_0_mcb)
|
|
# button / bed light
|
|
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_LEFT, self.light_bed_dirk_light.toggle_output_0_mcb)
|
|
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_LEFT_LONG,
|
|
self.switch_bed_marion_light.toggle_output_0_mcb)
|
|
# 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
|
|
)
|
|
|
|
# heating function
|
|
self.heating_function = heating_function(
|
|
self.valve_heating,
|
|
config.DEFAULT_TEMPERATURE,
|
|
**get_radiator_data(self.valve_heating.topic)
|
|
)
|
|
self.heating_function.add_callback(None, None, set_radiator_data, True)
|
|
self.videv_heating.connect_heating_function(self.heating_function)
|
|
|
|
|
|
class first_floor_east_living(room):
|
|
def __init__(self, mqtt_client, pd):
|
|
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)
|
|
|
|
#
|
|
# 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
|
|
)
|