242 рядки
11 KiB
Python
242 рядки
11 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
|
|
import config
|
|
from devdi import props
|
|
from devices import group
|
|
from function.db import get_radiator_data, set_radiator_data
|
|
from function.modules import brightness_choose_n_action, heating_function, switched_light
|
|
from function.rooms import room, room_collection
|
|
from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
|
|
import logging
|
|
import task
|
|
|
|
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_GFW
|
|
|
|
|
|
class ground_floor_west(room_collection):
|
|
def __init__(self, mqtt_client, pd, vd):
|
|
super().__init__(mqtt_client, pd, vd)
|
|
self.dirk = ground_floor_west_dirk(mqtt_client, pd, vd)
|
|
self.floor = ground_floor_west_floor(mqtt_client, pd, vd)
|
|
self.marion = ground_floor_west_marion(mqtt_client, pd, vd)
|
|
|
|
|
|
class ground_floor_west_floor(room):
|
|
def __init__(self, mqtt_client, pd, vd):
|
|
roo = props.ROO_FLO
|
|
#
|
|
# Device initialisation
|
|
#
|
|
# http://shelly1l-84CCA8AD1148
|
|
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
self.main_light_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
|
|
super().__init__(mqtt_client, pd, vd)
|
|
|
|
#
|
|
# Functionality initialisation
|
|
#
|
|
# Request silvercrest data of lead light after power on
|
|
switched_light(self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0, self.main_light_tradfri)
|
|
|
|
#
|
|
# Virtual Device Interface
|
|
#
|
|
self.main_light_videv = videv_switch_brightness_color_temp(
|
|
mqtt_client, config.TOPIC_GFW_FLOOR_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
|
|
)
|
|
|
|
|
|
class ground_floor_west_marion(room):
|
|
def __init__(self, mqtt_client, pd, vd):
|
|
roo = props.ROO_MAR
|
|
#
|
|
# Device initialisation
|
|
#
|
|
# http://shelly1l-E8DB84A1E067
|
|
# main light
|
|
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
# heating function
|
|
self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA)
|
|
super().__init__(mqtt_client, pd, vd)
|
|
|
|
#
|
|
# Functionality initialisation
|
|
#
|
|
# 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
|
|
#
|
|
self.main_light_videv = videv_switching(
|
|
mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV,
|
|
self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
|
|
)
|
|
self.heating_function_videv = videv_heating(
|
|
mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_VIDEV,
|
|
self.heating_function
|
|
)
|
|
|
|
|
|
class ground_floor_west_dirk(room):
|
|
STATE_ACTIVE_DEVICE_MAIN_LIGHT = 0
|
|
STATE_ACTIVE_DEVICE_DESK_LIGHT = 1
|
|
STATE_ACTIVE_DEVICE_AMPLIFIER = 2
|
|
STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
|
|
#
|
|
AUDIO_SOURCE_PC = 0
|
|
AUDIO_SOURCE_CD = 1
|
|
AUDIO_SOURCE_RASPI = 2
|
|
|
|
def __init__(self, mqtt_client, pd, vd):
|
|
roo = props.ROO_DIR
|
|
#
|
|
# Device initialisation
|
|
#
|
|
# http://shelly1l-3C6105E44F27
|
|
# main light
|
|
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
self.main_light_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
|
|
# powerplug
|
|
self.powerplug_common = pd.get(props.STG_MYA, loc, roo, props.FUN_MPP)
|
|
self.KEY_POWERPLUG_AMPLIFIER = self.powerplug_common.KEY_OUTPUT_0
|
|
self.KEY_POWERPLUG_DESK_LIGHT = self.powerplug_common.KEY_OUTPUT_1
|
|
self.KEY_POWERPLUG_CD_PLAYER = self.powerplug_common.KEY_OUTPUT_2
|
|
self.KEY_POWERPLUG_PC_DOCK = self.powerplug_common.KEY_OUTPUT_3
|
|
# desk light
|
|
self.desk_light_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_DEL)
|
|
# button
|
|
self.button_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_INP)
|
|
# hifi
|
|
self.remote_amplifier = pd.get(props.STG_MYA, loc, roo, props.FUN_RCA)
|
|
self.spotify_state = pd.get(props.STG_MYA, loc, roo, props.FUN_ASS)
|
|
self.mpd_state = pd.get(props.STG_MYA, loc, roo, props.FUN_ASM)
|
|
# heating function
|
|
self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA)
|
|
super().__init__(mqtt_client, pd, vd)
|
|
#
|
|
# Functionality initialisation
|
|
#
|
|
# Button - Brightness functionality
|
|
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.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
|
|
self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
|
|
# 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 - Desk light
|
|
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_RIGHT,
|
|
self.powerplug_common.toggle_output_1_mcb)
|
|
# Button - Amplifier
|
|
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT_LONG,
|
|
self.powerplug_common.toggle_output_0_mcb)
|
|
# Button - CD player
|
|
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_RIGHT_LONG,
|
|
self.powerplug_common.toggle_output_2_mcb)
|
|
# Button - PC dock
|
|
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT,
|
|
self.powerplug_common.toggle_output_3_mcb)
|
|
|
|
# Mediaplayer - Amplifier auto on
|
|
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
|
|
self.spotify_state.add_callback(self.spotify_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
|
|
self.mpd_state.add_callback(self.mpd_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
|
|
# Mediaplayer - Audio source selection
|
|
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
|
|
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
|
|
self.spotify_state.add_callback(self.spotify_state.KEY_STATE, True, self.audio_source_selector, True)
|
|
self.mpd_state.add_callback(self.mpd_state.KEY_STATE, True, self.audio_source_selector, True)
|
|
self.audio_source = self.AUDIO_SOURCE_PC
|
|
|
|
# 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
|
|
#
|
|
self.main_light_videv = videv_switch_brightness_color_temp(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_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
|
|
)
|
|
self.desk_light_videv = videv_switch_brightness_color_temp(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV,
|
|
self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT,
|
|
self.desk_light_tradfri, self.desk_light_tradfri.KEY_BRIGHTNESS,
|
|
self.desk_light_tradfri, self.desk_light_tradfri.KEY_COLOR_TEMP
|
|
)
|
|
self.amplifier_videv = videv_switching(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV,
|
|
self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER
|
|
)
|
|
self.cd_player_videv = videv_switching(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV,
|
|
self.powerplug_common, self.KEY_POWERPLUG_CD_PLAYER
|
|
)
|
|
self.pc_dock_videv = videv_switching(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV,
|
|
self.powerplug_common, self.KEY_POWERPLUG_PC_DOCK
|
|
)
|
|
self.heating_function_videv = videv_heating(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV,
|
|
self.heating_function
|
|
)
|
|
self.brightness_functions_device_videv = videv_multistate(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
|
|
brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 3
|
|
)
|
|
self.audio_player_videv = videv_audio_player(
|
|
mqtt_client, config.TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV,
|
|
self.spotify_state, self.mpd_state
|
|
)
|
|
#
|
|
# Other stuff
|
|
#
|
|
self.delayed_task_remote = task.delayed(1.0, self.send_audio_source)
|
|
|
|
def audio_source_selector(self, device, key, data):
|
|
if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
|
|
# switch on of cd player
|
|
self.audio_source = self.AUDIO_SOURCE_CD
|
|
elif device in [self.spotify_state, self.mpd_state]:
|
|
# switch on raspi-source
|
|
self.audio_source = self.AUDIO_SOURCE_RASPI
|
|
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
|
|
# switch on of amplifier -> select source and reset stored source value
|
|
self.delayed_task_remote.run()
|
|
|
|
def send_audio_source(self):
|
|
if self.audio_source == self.AUDIO_SOURCE_PC:
|
|
logger.info("Sending IR command to change audio source to pc")
|
|
self.remote_amplifier.set_line3()
|
|
elif self.audio_source == self.AUDIO_SOURCE_CD:
|
|
logger.info("Sending IR command to change audio source to cd")
|
|
self.remote_amplifier.set_cd()
|
|
elif self.audio_source == self.AUDIO_SOURCE_RASPI:
|
|
logger.info("Sending IR command to change audio source to raspi")
|
|
self.remote_amplifier.set_line1()
|
|
self.audio_source = self.AUDIO_SOURCE_PC
|