Compare commits

...

8 Commits

12 changed files with 400 additions and 883 deletions

2
devdi

@ -1 +1 @@
Subproject commit c11d2e53fd326eb37ba4e4c53a890ff8f1a9a917 Subproject commit 58167fb8ecd719df6a6aca693cf9fd7735149db4

View File

@ -25,11 +25,7 @@ devices (DEVICES)
**Module Documentation:** **Module Documentation:**
""" """
import logging
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
from devices.shelly import shelly as shelly_sw1 from devices.shelly import shelly as shelly_sw1
from devices.shelly import shelly_rpc as shelly_pro3 from devices.shelly import shelly_rpc as shelly_pro3
@ -46,7 +42,27 @@ from devices.silvercrest import silvercrest_motion_sensor
from devices.mydevices import powerplug as my_powerplug from devices.mydevices import powerplug as my_powerplug
from devices.mydevices import audio_status from devices.mydevices import audio_status
from devices.mydevices import remote from devices.mydevices import remote
my_ambient = None
from function.videv import videv_switching as videv_sw
from function.videv import videv_switch_brightness as videv_sw_br
from function.videv import videv_switch_brightness_color_temp as videv_sw_br_ct
from function.videv import videv_switching_timer as videv_sw_tm
from function.videv import videv_switching_motion as videv_sw_mo
from function.videv import videv_heating as videv_hea
from function.videv import videv_pure_switch
from function.videv import videv_multistate
from function.videv import videv_audio_player
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
def my_ambient(mqtt_client, topic):
logger.warning("Device type my_ambient is not yet implemented. Topic %s will not be supported", topic)
return None
class group(object): class group(object):

View File

@ -20,21 +20,21 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
class all_functions(room_collection): class all_functions(room_collection):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
super().__init__(mqtt_client, pd, vd) super().__init__(mqtt_client)
# #
# Rooms # Rooms
# #
# garden # garden
self.gar = garden(self.mqtt_client, pd, vd) self.gar = garden(self.mqtt_client)
# stairway # stairway
self.stw = stairway(self.mqtt_client, pd, vd) self.stw = stairway(self.mqtt_client)
# ground floor west # ground floor west
self.gfw = ground_floor_west(self.mqtt_client, pd, vd) self.gfw = ground_floor_west(self.mqtt_client)
# first floor west # first floor west
self.ffw = first_floor_west(self.mqtt_client, pd, vd) self.ffw = first_floor_west(self.mqtt_client)
# first floor east # first floor east
self.ffe = first_floor_east(self.mqtt_client, pd, vd) self.ffe = first_floor_east(self.mqtt_client)
# #
# Interactions # Interactions
# #
@ -48,33 +48,32 @@ class all_functions(room_collection):
def init_cross_room_interactions(self): def init_cross_room_interactions(self):
# shelly dirk input 1 # shelly dirk input 1
self.last_gfw_dirk_input_1 = None self.last_gfw_dirk_input_1 = None
self.gfw.dirk.main_light_shelly.add_callback(self.gfw.dirk.main_light_shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1) self.gfw.dirk.switch_main_light.add_callback(self.gfw.dirk.switch_main_light.KEY_INPUT_1, None, self.gfw_dirk_input_1)
# tradfri button ffe_sleep right click # tradfri button ffe_sleep right click
self.ffe.sleep.button_tradfri.add_callback(self.ffe.sleep.button_tradfri.KEY_ACTION, self.ffe.sleep.input_device.add_callback(self.ffe.sleep.input_device.KEY_ACTION,
self.ffe.sleep.button_tradfri.ACTION_RIGHT, self.ffe.sleep.input_device.ACTION_RIGHT, self.ffe.floor.switch_main_light.toggle_output_0_mcb)
self.ffe.floor.main_light_shelly.toggle_output_0_mcb)
def init_off_functionality(self): def init_off_functionality(self):
# ALL OFF - Virtual device # ALL OFF - Virtual device
self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self) self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
# ALL OFF - Long push stairway # ALL OFF - Long push stairway
self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0, self.stw.stairway.switch_main_light.add_callback(self.stw.stairway.switch_main_light.KEY_LONGPUSH_0,
True, self.stw.stairway.main_light_shelly.flash_0_mcb) True, self.stw.stairway.switch_main_light.flash_0_mcb)
self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0, True, self.all_off) self.stw.stairway.switch_main_light.add_callback(self.stw.stairway.switch_main_light.KEY_LONGPUSH_0, True, self.all_off)
# FFE ALL OFF - Long push ffe_floor # FFE ALL OFF - Long push ffe_floor
self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0, self.ffe.floor.switch_main_light.add_callback(self.ffe.floor.switch_main_light.KEY_LONGPUSH_0,
True, self.ffe.floor.main_light_shelly.flash_0_mcb) True, self.ffe.floor.switch_main_light.flash_0_mcb)
self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0, True, self.ffe.all_off) self.ffe.floor.switch_main_light.add_callback(self.ffe.floor.switch_main_light.KEY_LONGPUSH_0, True, self.ffe.all_off)
# FFE ALL OFF - Long push input device # FFE ALL OFF - Long push input device
self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off) self.ffe.sleep.input_device.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
# FFW ALL OFF - Long push ffw_floor # FFW ALL OFF - Long push ffw_floor
self.ffw.floor.main_light_shelly.add_callback(self.ffw.floor.main_light_shelly.KEY_LONGPUSH_0, self.ffw.floor.switch_main_light.add_callback(self.ffw.floor.switch_main_light.KEY_LONGPUSH_0,
True, self.ffw.floor.main_light_shelly.flash_0_mcb) True, self.ffw.floor.switch_main_light.flash_0_mcb)
self.ffw.floor.main_light_shelly.add_callback(self.ffw.floor.main_light_shelly.KEY_LONGPUSH_0, True, self.ffw.all_off) self.ffw.floor.switch_main_light.add_callback(self.ffw.floor.switch_main_light.KEY_LONGPUSH_0, True, self.ffw.all_off)
def init_sumer_winter_mode(self): def init_sumer_winter_mode(self):
# ALL summer/winter mode # ALL summer/winter mode
@ -87,5 +86,5 @@ class all_functions(room_collection):
def gfw_dirk_input_1(self, device, key, data): def gfw_dirk_input_1(self, device, key, data):
if self.last_gfw_dirk_input_1 is not None: if self.last_gfw_dirk_input_1 is not None:
if self.last_gfw_dirk_input_1 != data: if self.last_gfw_dirk_input_1 != data:
self.gfw.floor.main_light_shelly.toggle_output_0_mcb(device, key, data) self.gfw.floor.switch_main_light.toggle_output_0_mcb(device, key, data)
self.last_gfw_dirk_input_1 = data self.last_gfw_dirk_input_1 = data

View File

@ -3,13 +3,11 @@
# #
import config import config
from devdi import topic as props from devdi import rooms
from devices import group
from function.db import get_radiator_data, set_radiator_data from function.db import get_radiator_data, set_radiator_data
from function.helpers import day_event from function.helpers import day_event
from function.modules import brightness_choose_n_action, timer_on_activation, heating_function, switched_light from function.modules import brightness_choose_n_action, timer_on_activation, heating_function, switched_light
from function.rooms import room, room_collection 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 import logging
try: try:
@ -18,311 +16,158 @@ except ImportError:
ROOT_LOGGER_NAME = 'root' ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_FFE
class first_floor_east(room_collection): class first_floor_east(room_collection):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client,):
super().__init__(mqtt_client, pd, vd) super().__init__(mqtt_client)
self.dining = first_floor_east_dining(mqtt_client, pd, vd) self.dining = first_floor_east_dining(mqtt_client)
self.floor = first_floor_east_floor(mqtt_client, pd, vd) self.floor = first_floor_east_floor(mqtt_client)
self.kitchen = first_floor_east_kitchen(mqtt_client, pd, vd) self.kitchen = first_floor_east_kitchen(mqtt_client)
self.livingroom = first_floor_east_living(mqtt_client, pd, vd) self.livingroom = first_floor_east_living(mqtt_client)
self.sleep = first_floor_east_sleep(mqtt_client, pd, vd) self.sleep = first_floor_east_sleep(mqtt_client)
class first_floor_east_floor(room): class first_floor_east_floor(rooms.ffe_floor, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_FLO super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # connect videv and switch
# self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
# 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): class first_floor_east_kitchen(rooms.ffe_kitchen, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_KIT super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # light <-> videv
# self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
# http://shelly1l-8CAAB5616C01 self.videv_main_light.connect_br_device(self.light_main_light, self.light_main_light.KEY_BRIGHTNESS)
# main light self.videv_main_light.connect_ct_device(self.light_main_light, self.light_main_light.KEY_COLOR_TEMP)
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, 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)
# Request hue data of lead light after power on # 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) switched_light(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0, self.light_main_light)
# circulation pump
self.circulation_pump = timer_on_activation(self.switch_circulation_pump, self.switch_circulation_pump.KEY_OUTPUT_0, 10*60)
self.switch_circulation_pump.add_callback(self.switch_circulation_pump.KEY_OUTPUT_0, True, self.switch_main_light.flash_0_mcb, True)
self.videv_circulation_pump.connect_sw_device(self.switch_circulation_pump, self.switch_circulation_pump.KEY_OUTPUT_0)
self.videv_circulation_pump.connect_tm_device(self.circulation_pump, timer_on_activation.KEY_TIMER)
# heating function # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
self.videv_heating.connect_heating_function(self.heating_function)
#
# 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(room): class first_floor_east_dining(rooms.ffe_diningroom, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_DIN super().__init__(mqtt_client)
# room.__init__(self, mqtt_client)
# Device initialisation
# #
self.day_events = day_event((6, 0), (22, 0), 30, -30) 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) self.day_events.add_callback(None, True, self.__day_events__, True)
# main light # light <-> videv
self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True) 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 # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
# heating function <-> videv
# self.videv_heating.connect_heating_function(self.heating_function)
# 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): def __day_events__(self, device, key, data):
if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY): if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
if config.CHRISTMAS: if config.CHRISTMAS:
self.garland_powerplug.set_output_0(True) self.switch_garland_light.set_output_0(True)
elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE): elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
if config.CHRISTMAS: if config.CHRISTMAS:
self.garland_powerplug.set_output_0(False) self.switch_garland_light.set_output_0(False)
class first_floor_east_sleep(room): class first_floor_east_sleep(rooms.ffe_sleep, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_SLP super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation 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)
# #
# http://shelly1l-E8DB84A254C7 self.videv_bed_dirk_light.connect_sw_device(self.light_bed_dirk_light, self.light_bed_dirk_light.KEY_OUTPUT_0)
# main light self.videv_bed_dirk_light.connect_br_device(self.light_bed_dirk_light, self.light_bed_dirk_light.KEY_BRIGHTNESS)
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) self.videv_bed_marion_light.connect_sw_device(self.switch_bed_marion_light, self.switch_bed_marion_light.KEY_OUTPUT_0)
# bed light #
self.bed_light_di_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLD) self.videv_wardrobe_light.connect_sw_device(self.light_wardrobe_light, self.light_wardrobe_light.KEY_OUTPUT_0)
self.bed_light_ma_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLM) self.videv_wardrobe_light.connect_br_device(self.light_wardrobe_light, self.light_wardrobe_light.KEY_BRIGHTNESS)
# 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)
# wardrobe light
self.wardrobe_light = pd.get(props.STG_ZFE, loc, roo, props.FUN_WLI)
self.wardrobe_light.disable_all_off() # Always on - Off by light sensor
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
# button / brightness function # button / brightness function
self.brightness_functions = brightness_choose_n_action(self.button_tradfri) self.brightness_functions = brightness_choose_n_action(self.input_device)
self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0) self.brightness_functions.add(self.light_main_light, self.switch_main_light, self.switch_main_light.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) 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 # button / main light
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_TOGGLE, self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_TOGGLE, self.switch_main_light.toggle_output_0_mcb)
self.main_light_shelly.toggle_output_0_mcb)
# button / bed light # button / bed light
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT, 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.bed_light_di_tradfri.toggle_output_0_mcb) self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_LEFT_LONG,
self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT_LONG, self.switch_bed_marion_light.toggle_output_0_mcb)
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 # button
self.brightness_functions_device_videv = videv_multistate( self.videv_multistate.connect_br_function(self.brightness_functions, brightness_choose_n_action.KEY_ACTIVE_DEVICE, 2)
mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
)
self.wardrobe_light_videv = videv_switch_brightness(
mqtt_client, config.TOPIC_FFE_SLEEP_WARDROBE_LIGHT_VIDEV,
self.wardrobe_light, self.wardrobe_light.KEY_OUTPUT_0,
self.wardrobe_light, self.wardrobe_light.KEY_BRIGHTNESS,
)
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 # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) 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(rooms.ffe_livingroom, room):
def __init__(self, mqtt_client):
super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Virtual Device Interface # 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_floor_light.connect_sw_device(self.light_floor_light, self.light_floor_light.KEY_OUTPUT_0)
self.videv_floor_light.connect_br_device(self.light_floor_light, self.light_floor_light.KEY_BRIGHTNESS)
self.videv_floor_light.connect_ct_device(self.light_floor_light, self.light_floor_light.KEY_COLOR_TEMP)
# #
# 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: if config.CHRISTMAS:
self.xmas_tree_videv = videv_switching( self.videv_xmas_tree_light.connect_sw_device(self.switch_xmas_tree_light, self.switch_xmas_tree_light.KEY_OUTPUT_0)
mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
self.powerplug_xmas_tree, self.powerplug_xmas_tree.KEY_OUTPUT_0 # main light -> floor_light
self.switch_main_light.add_callback(self.switch_main_light.KEY_OUTPUT_0, None, self.light_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)
self.videv_heating.connect_heating_function(self.heating_function)

View File

@ -3,11 +3,10 @@
# #
import config import config
from devdi import topic as props from devdi import rooms
from function.db import get_radiator_data, set_radiator_data from function.db import get_radiator_data, set_radiator_data
from function.modules import heating_function from function.modules import heating_function
from function.rooms import room, room_collection from function.rooms import room, room_collection
from function.videv import videv_switch_brightness, videv_switch_brightness_color_temp, videv_heating, videv_switching
import logging import logging
@ -17,210 +16,105 @@ except ImportError:
ROOT_LOGGER_NAME = 'root' ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_FFW
class first_floor_west(room_collection): class first_floor_west(room_collection):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
super().__init__(mqtt_client, pd, vd) super().__init__(mqtt_client)
self.floor = first_floor_west_floor(mqtt_client, pd, vd) self.floor = first_floor_west_floor(mqtt_client)
self.bath = first_floor_west_bath(mqtt_client, pd, vd) self.bath = first_floor_west_bath(mqtt_client)
self.julian = first_floor_west_julian(mqtt_client, pd, vd) self.julian = first_floor_west_julian(mqtt_client)
self.livingroom = first_floor_west_living(mqtt_client, pd, vd) self.livingroom = first_floor_west_living(mqtt_client)
self.sleep = first_floor_west_sleep(mqtt_client, pd, vd) self.sleep = first_floor_west_sleep(mqtt_client)
class first_floor_west_floor(room): class first_floor_west_floor(rooms.ffw_floor, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_FLO super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # connect videv and switch
# self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
# http://shelly1-58BF25D848EA
# 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_FFW_FLOOR_MAIN_LIGHT_VIDEV,
self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
)
class first_floor_west_julian(room): class first_floor_west_julian(rooms.ffw_julian, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_JUL super().__init__(mqtt_client)
# room.__init__(self, mqtt_client)
# Device initialisation
#
# http://shelly1l-3C6105E43452
# main light
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
self.main_light_tradfri = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
# heating function
self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
# #
# 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)
# heating function # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
self.videv_heating.connect_heating_function(self.heating_function)
#
# Virtual Device Interface
#
# main light
self.main_light_videv = videv_switch_brightness_color_temp(
mqtt_client, config.TOPIC_FFW_JULIAN_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
)
# heating function
self.heating_function_videv = videv_heating(
mqtt_client, config.TOPIC_FFW_JULIAN_HEATING_VALVE_VIDEV,
self.heating_function
)
class first_floor_west_bath(room): class first_floor_west_bath(rooms.ffw_bath, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_BAT super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # light <-> videv
# self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
# http://shelly1-58BF25D84219
# 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_ZFW, loc, roo, props.FUN_HEA)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
# heating function # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
self.videv_heating.connect_heating_function(self.heating_function)
#
# Virtual Device Interface
#
# main light
self.main_light = videv_switching(
mqtt_client, config.TOPIC_FFW_BATH_MAIN_LIGHT_VIDEV,
self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
)
# heating function
self.heating_function_videv = videv_heating(
mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_VIDEV,
self.heating_function
)
class first_floor_west_living(room): class first_floor_west_living(rooms.ffw_livingroom, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_LIV super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # light <-> videv
# self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
# http://shelly1l-84CCA8ACE6A1 self.videv_main_light.connect_br_device(self.light_main_light, self.light_main_light.KEY_BRIGHTNESS)
# main light self.videv_main_light.connect_ct_device(self.light_main_light, self.light_main_light.KEY_COLOR_TEMP)
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
self.main_light_tradfri = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
# heating function
self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
# heating function # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
self.videv_heating.connect_heating_function(self.heating_function)
#
# Virtual Device Interface
#
# main light
self.main_light_videv = videv_switch_brightness_color_temp(
mqtt_client, config.TOPIC_FFW_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
)
# heating function
self.heating_function_videv = videv_heating(
mqtt_client, config.TOPIC_FFW_LIVINGROOM_HEATING_VALVE_VIDEV,
self.heating_function
)
class first_floor_west_sleep(room): class first_floor_west_sleep(rooms.ffw_sleep, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_SLP super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # 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)
# #
# http://shelly1-3494546A51F2 self.videv_window_light.connect_sw_device(self.light_window_light, self.light_window_light.KEY_OUTPUT_0)
# main light self.videv_window_light.connect_br_device(self.light_window_light, self.light_window_light.KEY_BRIGHTNESS)
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.videv_window_light.connect_ct_device(self.light_window_light, self.light_window_light.KEY_COLOR_TEMP)
self.main_light_tradfri = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
# heating function # main light -> window light
self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA) self.switch_main_light.add_callback(self.switch_main_light.KEY_OUTPUT_0, None, self.light_window_light.set_output_0_mcb, True)
# window light
self.window_light = pd.get(props.STG_ZFW, loc, roo, props.FUN_WIL)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
# heating function # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
self.videv_heating.connect_heating_function(self.heating_function)
# main light
self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.window_light.set_output_0_mcb, True)
#
# Virtual Device Interface
#
# main light
self.main_light_videv = videv_switch_brightness(
mqtt_client, config.TOPIC_FFW_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
)
# heating function
self.heating_function_videv = videv_heating(
mqtt_client, config.TOPIC_FFW_SLEEP_HEATING_VALVE_VIDEV,
self.heating_function
)
# window lamp
self.windowlamp_videv = videv_switch_brightness_color_temp(
mqtt_client, config.TOPIC_FFW_SLEEP_WINDOW_LAMP_VIDEV,
self.window_light, self.window_light.KEY_OUTPUT_0,
self.window_light, self.window_light.KEY_BRIGHTNESS,
self.window_light, self.window_light.KEY_COLOR_TEMP
)

View File

@ -2,11 +2,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
import config from devdi import rooms
import devdi.topic as props
from function.helpers import day_event from function.helpers import day_event
from function.rooms import room, room_collection from function.rooms import room, room_collection
from function.videv import videv_switching, videv_pure_switch
import logging import logging
try: try:
@ -15,56 +13,28 @@ except ImportError:
ROOT_LOGGER_NAME = 'root' ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_GAR
class garden(room_collection): class garden(room_collection):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
super().__init__(mqtt_client, pd, vd) super().__init__(mqtt_client)
self.garden = garden_garden(mqtt_client, pd, vd) self.garden = garden_garden(mqtt_client)
class garden_garden(room): class garden_garden(rooms.gar_garden, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_GAR super().__init__(mqtt_client)
# room.__init__(self, mqtt_client)
# Device initialisation
# #
self.day_events = day_event((6, 0), (22, 0), 30, -30) self.day_events = day_event((6, 0), (22, 0), 30, -30)
# garden powerplugs
self.garland_powerplug = pd.get(props.STG_ZGW, loc, roo, props.FUN_GAR)
# repeater
self.repeater = pd.get(props.STG_ZGW, loc, roo, props.FUN_REP)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
self.day_events.add_callback(None, True, self.__day_events__, True) self.day_events.add_callback(None, True, self.__day_events__, True)
# # xxx <-> videv
# Virtual Device Interface self.videv_garland_light.connect_sw_device(self.switch_garland_light, self.switch_garland_light.KEY_OUTPUT_0)
# self.videv_repeater.connect_sw_device(self.switch_repeater, self.switch_repeater.KEY_OUTPUT_0)
# mode
self.mode_videv = videv_pure_switch(
mqtt_client, config.TOPIC_GAR_GARDEN_MODE_VIDEV
)
# garland
self.garland_videv = videv_switching(
mqtt_client, config.TOPIC_GAR_GARDEN_GARLAND_VIDEV,
self.garland_powerplug, self.garland_powerplug.KEY_OUTPUT_0
)
# repeater
self.repeater_videv = videv_switching(
mqtt_client, config.TOPIC_GAR_GARDEN_REPEATER_VIDEV,
self.repeater, self.repeater.KEY_OUTPUT_0
)
def __day_events__(self, device, key, data): def __day_events__(self, device, key, data):
if self.mode_videv.get(self.mode_videv.KEY_STATE): if self.videv_mode.get(self.videv_mode.KEY_STATE):
if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY): if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
self.garland_powerplug.set_output_0(True) self.switch_garland_light.set_output_0(True)
elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE): elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
self.garland_powerplug.set_output_0(False) self.switch_garland_light.set_output_0(False)

View File

@ -3,12 +3,10 @@
# #
import config import config
from devdi import topic as props from devdi import rooms
from devices import group
from function.db import get_radiator_data, set_radiator_data from function.db import get_radiator_data, set_radiator_data
from function.modules import brightness_choose_n_action, heating_function, switched_light from function.modules import brightness_choose_n_action, heating_function, switched_light
from function.rooms import room, room_collection 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 logging
import task import task
@ -18,95 +16,16 @@ except ImportError:
ROOT_LOGGER_NAME = 'root' ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_GFW
class ground_floor_west(room_collection): class ground_floor_west(room_collection):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
super().__init__(mqtt_client, pd, vd) super().__init__(mqtt_client)
self.dirk = ground_floor_west_dirk(mqtt_client, pd, vd) self.dirk = ground_floor_west_dirk(mqtt_client)
self.floor = ground_floor_west_floor(mqtt_client, pd, vd) self.floor = ground_floor_west_floor(mqtt_client)
self.marion = ground_floor_west_marion(mqtt_client, pd, vd) self.marion = ground_floor_west_marion(mqtt_client)
class ground_floor_west_floor(room): class ground_floor_west_dirk(rooms.gfw_dirk, 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)
# window light
self.window_light = pd.get(props.STG_ZGW, loc, roo, props.FUN_WIL)
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)
# main light
self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.window_light.set_output_0_mcb, 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
)
# window lamp
self.windowlamp_videv = videv_switch_brightness_color_temp(
mqtt_client, config.TOPIC_GFW_MARION_WINDOW_LAMP_VIDEV,
self.window_light, self.window_light.KEY_OUTPUT_0,
self.window_light, self.window_light.KEY_BRIGHTNESS,
self.window_light, self.window_light.KEY_COLOR_TEMP
)
class ground_floor_west_dirk(room):
STATE_ACTIVE_DEVICE_MAIN_LIGHT = 0 STATE_ACTIVE_DEVICE_MAIN_LIGHT = 0
STATE_ACTIVE_DEVICE_DESK_LIGHT = 1 STATE_ACTIVE_DEVICE_DESK_LIGHT = 1
STATE_ACTIVE_DEVICE_AMPLIFIER = 2 STATE_ACTIVE_DEVICE_AMPLIFIER = 2
@ -118,167 +37,155 @@ class ground_floor_west_dirk(room):
AUDIO_SOURCE_BT = 3 AUDIO_SOURCE_BT = 3
AUDIO_SOURCE_PHONO = 4 AUDIO_SOURCE_PHONO = 4
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
roo = props.ROO_DIR super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # 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)
# #
# http://shelly1l-3C6105E44F27 self.videv_desk_light.connect_sw_device(self.light_desk_light, self.light_desk_light.KEY_OUTPUT_0)
# main light self.videv_desk_light.connect_br_device(self.light_desk_light, self.light_desk_light.KEY_BRIGHTNESS)
self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.videv_desk_light.connect_ct_device(self.light_desk_light, self.light_desk_light.KEY_COLOR_TEMP)
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_PHONO = self.powerplug_common.KEY_OUTPUT_1
self.KEY_POWERPLUG_CD_PLAYER = self.powerplug_common.KEY_OUTPUT_2
self.KEY_POWERPLUG_BT = self.powerplug_common.KEY_OUTPUT_3
# dock
self.dock_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_DCK)
# 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)
self.bt_state = pd.get(props.STG_MYA, loc, roo, props.FUN_ASB)
# heating function
self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA)
super().__init__(mqtt_client, pd, vd)
# #
# Functionality initialisation self.videv_amplifier.connect_sw_device(self.switch_powerplug_4, self.KEY_POWERPLUG_AMPLIFIER)
self.videv_bluetooth.connect_sw_device(self.switch_powerplug_4, self.KEY_POWERPLUG_BT)
self.videv_cd_player.connect_sw_device(self.switch_powerplug_4, self.KEY_POWERPLUG_CD_PLAYER)
self.videv_phono.connect_sw_device(self.switch_powerplug_4, self.KEY_POWERPLUG_PHONO)
# #
# Button - Brightness functionality self.videv_pc_dock.connect_sw_device(self.switch_pc_dock, self.switch_pc_dock.KEY_OUTPUT_0)
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.desk_light_tradfri, self.desk_light_tradfri.KEY_OUTPUT_0)
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.desk_light_tradfri.toggle_output_0_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.dock_tradfri.toggle_output_0_mcb)
# Mediaplayer - Amplifier auto on # amplifier on, if playing device on
self.powerplug_common.add_callback(self.KEY_POWERPLUG_PHONO, None, self.powerplug_common.set_output_0_mcb, True) self.switch_powerplug_4.add_callback(self.KEY_POWERPLUG_PHONO, None, self.switch_powerplug_4.set_output_0_mcb, True)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True) self.switch_powerplug_4.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.switch_powerplug_4.set_output_0_mcb, True)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_BT, None, self.powerplug_common.set_output_0_mcb, True) self.switch_powerplug_4.add_callback(self.KEY_POWERPLUG_BT, None, self.switch_powerplug_4.set_output_0_mcb, True)
self.spotify_state.add_callback(self.spotify_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True) # amplifier on, if player on
self.mpd_state.add_callback(self.mpd_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True) self.audio_status_bluetooth.add_callback(self.audio_status_bluetooth.KEY_STATE, None, self.switch_powerplug_4.set_output_0_mcb, True)
self.bt_state.add_callback(self.bt_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True) self.audio_status_mpd.add_callback(self.audio_status_mpd.KEY_STATE, None, self.switch_powerplug_4.set_output_0_mcb, True)
# Mediaplayer - Audio source selection self.audio_status_spotify.add_callback(self.audio_status_spotify.KEY_STATE, None, self.switch_powerplug_4.set_output_0_mcb, True)
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) # Audio source selection
self.powerplug_common.add_callback(self.KEY_POWERPLUG_BT, True, self.audio_source_selector, True) self.switch_powerplug_4.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_PHONO, True, self.audio_source_selector, True) self.switch_powerplug_4.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.switch_powerplug_4.add_callback(self.KEY_POWERPLUG_BT, True, self.audio_source_selector, True)
self.mpd_state.add_callback(self.mpd_state.KEY_STATE, True, self.audio_source_selector, True) self.switch_powerplug_4.add_callback(self.KEY_POWERPLUG_PHONO, True, self.audio_source_selector, True)
self.bt_state.add_callback(self.bt_state.KEY_STATE, True, self.audio_source_selector, True) self.audio_status_bluetooth.add_callback(self.audio_status_bluetooth.KEY_STATE, True, self.audio_source_selector, True)
self.audio_status_mpd.add_callback(self.audio_status_mpd.KEY_STATE, True, self.audio_source_selector, True)
self.audio_status_spotify.add_callback(self.audio_status_spotify.KEY_STATE, True, self.audio_source_selector, True)
self.audio_source = self.AUDIO_SOURCE_PC self.audio_source = self.AUDIO_SOURCE_PC
self.delayed_task_remote = task.delayed(1.0, self.send_audio_source)
# input device functions
# Brightness functionality
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_desk_light, self.light_desk_light, self.light_desk_light.KEY_OUTPUT_0)
self.brightness_functions.add(self.remote_ctrl, self.switch_powerplug_4, self.KEY_POWERPLUG_AMPLIFIER)
# 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 - Desk light
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_RIGHT,
self.light_desk_light.toggle_output_0_mcb)
# Button - Amplifier
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_LEFT_LONG,
self.switch_powerplug_4.toggle_output_0_mcb)
# Button - CD player
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_RIGHT_LONG,
self.switch_powerplug_4.toggle_output_2_mcb)
# Button - PC dock
self.input_device.add_callback(self.input_device.KEY_ACTION, self.input_device.ACTION_LEFT,
self.switch_pc_dock.toggle_output_0_mcb)
# additional videv connections
self.videv_multistate.connect_br_function(self.brightness_functions, brightness_choose_n_action.KEY_ACTIVE_DEVICE, 3)
#
self.videv_audio_player.connect_audio_device(self.audio_status_bluetooth)
self.videv_audio_player.connect_audio_device(self.audio_status_mpd)
self.videv_audio_player.connect_audio_device(self.audio_status_spotify)
# heating function # heating function
self.heating_function = heating_function( self.heating_function = heating_function(
self.heating_valve, self.valve_heating,
config.DEFAULT_TEMPERATURE, config.DEFAULT_TEMPERATURE,
**get_radiator_data(self.heating_valve.topic) **get_radiator_data(self.valve_heating.topic)
) )
self.heating_function.add_callback(None, None, set_radiator_data, True) self.heating_function.add_callback(None, None, set_radiator_data, True)
# heating function <-> videv
# self.videv_heating.connect_heating_function(self.heating_function)
# 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.desk_light_tradfri, self.desk_light_tradfri.KEY_OUTPUT_0,
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.phono_videv = videv_switching(
mqtt_client, config.TOPIC_GFW_DIRK_PHONO_VIDEV,
self.powerplug_common, self.KEY_POWERPLUG_PHONO
)
self.cd_player_videv = videv_switching(
mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV,
self.powerplug_common, self.KEY_POWERPLUG_CD_PLAYER
)
self.bt_videv = videv_switching(
mqtt_client, config.TOPIC_GFW_DIRK_BT_VIDEV,
self.powerplug_common, self.KEY_POWERPLUG_BT
)
self.pc_dock_videv = videv_switching(
mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV,
self.dock_tradfri, self.dock_tradfri.KEY_OUTPUT_0
)
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, self.bt_state
)
#
# Other stuff
#
self.delayed_task_remote = task.delayed(1.0, self.send_audio_source)
def audio_source_selector(self, device, key, data): def audio_source_selector(self, device, key, data):
if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER: if device == self.switch_powerplug_4 and key == self.KEY_POWERPLUG_CD_PLAYER:
# switch on of cd player # switch on of cd player
self.audio_source = self.AUDIO_SOURCE_CD self.audio_source = self.AUDIO_SOURCE_CD
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_BT: elif device == self.switch_powerplug_4 and key == self.KEY_POWERPLUG_BT:
# switch on of bluetooth # switch on of bluetooth
self.audio_source = self.AUDIO_SOURCE_BT self.audio_source = self.AUDIO_SOURCE_BT
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_PHONO: elif device == self.switch_powerplug_4 and key == self.KEY_POWERPLUG_PHONO:
# switch on of bluetooth # switch on of bluetooth
self.audio_source = self.AUDIO_SOURCE_PHONO self.audio_source = self.AUDIO_SOURCE_PHONO
elif device in [self.spotify_state, self.mpd_state, self.bt_state]: elif device in [self.audio_status_spotify, self.audio_status_mpd, self.audio_status_bluetooth]:
# switch on raspi-source # switch on raspi-source
self.audio_source = self.AUDIO_SOURCE_RASPI self.audio_source = self.AUDIO_SOURCE_RASPI
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER: elif device == self.switch_powerplug_4 and key == self.KEY_POWERPLUG_AMPLIFIER:
# switch on of amplifier -> select source and reset stored source value # switch on of amplifier -> select source and reset stored source value
self.delayed_task_remote.run() self.delayed_task_remote.run()
def send_audio_source(self): def send_audio_source(self):
if self.audio_source == self.AUDIO_SOURCE_PC: if self.audio_source == self.AUDIO_SOURCE_PC:
logger.info("Sending IR command to change audio source to pc") logger.info("Sending IR command to change audio source to pc")
self.remote_amplifier.set_line3() self.remote_ctrl.set_line3()
elif self.audio_source == self.AUDIO_SOURCE_CD: elif self.audio_source == self.AUDIO_SOURCE_CD:
logger.info("Sending IR command to change audio source to cd") logger.info("Sending IR command to change audio source to cd")
self.remote_amplifier.set_cd() self.remote_ctrl.set_cd()
elif self.audio_source == self.AUDIO_SOURCE_BT: elif self.audio_source == self.AUDIO_SOURCE_BT:
logger.info("Sending IR command to change audio source to bluetooth") logger.info("Sending IR command to change audio source to bluetooth")
self.remote_amplifier.set_line2() self.remote_ctrl.set_line2()
elif self.audio_source == self.AUDIO_SOURCE_PHONO: elif self.audio_source == self.AUDIO_SOURCE_PHONO:
logger.info("Sending IR command to change audio source to phono") logger.info("Sending IR command to change audio source to phono")
self.remote_amplifier.set_phono() self.remote_ctrl.set_phono()
elif self.audio_source == self.AUDIO_SOURCE_RASPI: elif self.audio_source == self.AUDIO_SOURCE_RASPI:
logger.info("Sending IR command to change audio source to raspi") logger.info("Sending IR command to change audio source to raspi")
self.remote_amplifier.set_line1() self.remote_ctrl.set_line1()
self.audio_source = self.AUDIO_SOURCE_PC self.audio_source = self.AUDIO_SOURCE_PC
class ground_floor_west_floor(rooms.gfw_floor, room):
def __init__(self, mqtt_client):
super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
#
# Request silvercrest data of lead light after power on
switched_light(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0, self.light_main_light)
# 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)
class ground_floor_west_marion(rooms.gfw_marion, room):
def __init__(self, mqtt_client):
super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
#
# light <-> videv
self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
#
self.videv_window_light.connect_sw_device(self.light_window_light, self.light_window_light.KEY_OUTPUT_0)
self.videv_window_light.connect_br_device(self.light_window_light, self.light_window_light.KEY_BRIGHTNESS)
self.videv_window_light.connect_ct_device(self.light_window_light, self.light_window_light.KEY_COLOR_TEMP)
# main light -> window_light
self.switch_main_light.add_callback(self.switch_main_light.KEY_OUTPUT_0, None, self.light_window_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)

View File

@ -13,10 +13,8 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
class room(object): class room(object):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
self.mqtt_client = mqtt_client self.mqtt_client = mqtt_client
self.pd = pd
self.vd = vd
def all_off(self, device=None, key=None, data=None): def all_off(self, device=None, key=None, data=None):
logger.info("Switching all off \"%s\"", type(self).__name__) logger.info("Switching all off \"%s\"", type(self).__name__)
@ -37,10 +35,8 @@ class room(object):
class room_collection(object): class room_collection(object):
ALLOWED_CLASSES = ("room", "room_collection") ALLOWED_CLASSES = ("room", "room_collection")
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
self.mqtt_client = mqtt_client self.mqtt_client = mqtt_client
self.pd = pd
self.vd = vd
def all_off(self, device=None, key=None, data=None): def all_off(self, device=None, key=None, data=None):
logger.info("Switching all off \"%s\"", type(self).__name__) logger.info("Switching all off \"%s\"", type(self).__name__)
@ -48,8 +44,11 @@ class room_collection(object):
# attribute name is not private # attribute name is not private
if not sub_name.startswith("__"): if not sub_name.startswith("__"):
sub = getattr(self, sub_name) sub = getattr(self, sub_name)
if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES: # try to call all_off
try:
sub.all_off() sub.all_off()
except AttributeError:
pass # don't mind, if sub has no method all_off
def summer_mode(self, device=None, key=None, data=None): def summer_mode(self, device=None, key=None, data=None):
logger.info("Changing to %s \"%s\"", "summer mode" if data else "winter_mode", type(self).__name__) logger.info("Changing to %s \"%s\"", "summer mode" if data else "winter_mode", type(self).__name__)

View File

@ -3,11 +3,10 @@
# #
import config import config
from devdi import topic as props from devdi import rooms
import logging import logging
from function.modules import motion_sensor_light from function.modules import motion_sensor_light
from function.rooms import room, room_collection from function.rooms import room, room_collection
from function.videv import videv_switching_motion
try: try:
from config import APP_NAME as ROOT_LOGGER_NAME from config import APP_NAME as ROOT_LOGGER_NAME
@ -15,40 +14,24 @@ except ImportError:
ROOT_LOGGER_NAME = 'root' ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_STW
class stairway(room_collection): class stairway(room_collection):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
super().__init__(mqtt_client, pd, vd) super().__init__(mqtt_client)
self.stairway = stairway_stairway(mqtt_client, pd, vd) self.stairway = stairway_stairway(mqtt_client)
class stairway_stairway(room): class stairway_stairway(rooms.stairway, room):
def __init__(self, mqtt_client, pd, vd): def __init__(self, mqtt_client):
super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
# #
# Device initialisation # connect videv and switch
# self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
# http://shelly1-3494546A9364
self.main_light_shelly = pd.get(props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL)
self.motion_sensor_ff = pd.get(props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE)
self.motion_sensor_gf = pd.get(props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE)
super().__init__(mqtt_client, pd, vd)
#
# Functionality initialisation
#
self.motion_sensor_light = motion_sensor_light( self.motion_sensor_light = motion_sensor_light(
self.main_light_shelly, self.main_light_shelly.set_output_0, self.switch_main_light, self.switch_main_light.set_output_0,
self.motion_sensor_gf, self.motion_sensor_ff, self.motion_main_light_gf, self.motion_main_light_ff,
timer_value=config.USER_ON_TIME_STAIRWAYS timer_value=config.USER_ON_TIME_STAIRWAYS
) )
self.videv_main_light.connect_mo_function(self.motion_sensor_light)
#
# Virtual Device Interface
#
self.main_light_videv = videv_switching_motion(
mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV,
self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
self.motion_sensor_light
)

View File

@ -12,12 +12,6 @@ Targets:
from base import videv_base from base import videv_base
from function.rooms import room, room_collection from function.rooms import room, room_collection
import time
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
class videv_pure_switch(videv_base): class videv_pure_switch(videv_base):
@ -37,57 +31,56 @@ class videv_pure_switch(videv_base):
class videv_switching(videv_base): class videv_switching(videv_base):
KEY_STATE = 'state' KEY_STATE = 'state'
def __init__(self, mqtt_client, topic, sw_device, sw_key): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
def connect_sw_device(self, sw_device, sw_key):
self.add_routing(self.KEY_STATE, sw_device, sw_key) self.add_routing(self.KEY_STATE, sw_device, sw_key)
class videv_switching_timer(videv_base): class videv_switching_timer(videv_switching):
KEY_STATE = 'state'
KEY_TIMER = 'timer' KEY_TIMER = 'timer'
def __init__(self, mqtt_client, topic, sw_device, sw_key, tm_device, tm_key): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
self.add_routing(self.KEY_STATE, sw_device, sw_key)
def connect_tm_device(self, tm_device, tm_key):
self.add_display(self.KEY_TIMER, tm_device, tm_key) self.add_display(self.KEY_TIMER, tm_device, tm_key)
class videv_switching_motion(videv_base): class videv_switching_motion(videv_switching):
KEY_STATE = 'state' KEY_STATE = 'state'
# #
KEY_TIMER = 'timer' KEY_TIMER = 'timer'
KEY_MOTION_SENSOR = 'motion_%d' KEY_MOTION_SENSOR = 'motion_%d'
def __init__(self, mqtt_client, topic, sw_device, sw_key, motion_function): def __init__(self, mqtt_client, topic):
self.motion_sensors = motion_function.motion_sensors
#
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
self.add_routing(self.KEY_STATE, sw_device, sw_key)
self.add_display(self.KEY_TIMER, motion_function, motion_function.KEY_TIMER) def connect_mo_function(self, mo_function):
self.add_display(self.KEY_TIMER, mo_function, mo_function.KEY_TIMER)
# motion sensor state # motion sensor state
for index, motion_sensor in enumerate(self.motion_sensors): for index, motion_sensor in enumerate(mo_function.motion_sensors):
self.add_display(self.KEY_MOTION_SENSOR % index, motion_sensor, motion_sensor.KEY_OCCUPANCY) self.add_display(self.KEY_MOTION_SENSOR % index, motion_sensor, motion_sensor.KEY_OCCUPANCY)
class videv_switch_brightness(videv_base): class videv_switch_brightness(videv_switching):
KEY_STATE = 'state'
KEY_BRIGHTNESS = 'brightness' KEY_BRIGHTNESS = 'brightness'
def __init__(self, mqtt_client, topic, sw_device, sw_key, br_device, br_key): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
self.add_routing(self.KEY_STATE, sw_device, sw_key)
def connect_br_device(self, br_device, br_key):
self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key) self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
class videv_switch_brightness_color_temp(videv_base): class videv_switch_brightness_color_temp(videv_switch_brightness):
KEY_STATE = 'state'
KEY_BRIGHTNESS = 'brightness'
KEY_COLOR_TEMP = 'color_temp' KEY_COLOR_TEMP = 'color_temp'
def __init__(self, mqtt_client, topic, sw_device, sw_key, br_device, br_key, ct_device, ct_key): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
self.add_routing(self.KEY_STATE, sw_device, sw_key)
self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key) def connect_ct_device(self, ct_device, ct_key):
self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key) self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key)
@ -102,8 +95,10 @@ class videv_heating(videv_base):
# #
KEY_TEMPERATURE = 'temperature' KEY_TEMPERATURE = 'temperature'
def __init__(self, mqtt_client, topic, heating_function): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
def connect_heating_function(self, heating_function):
# #
self.add_routing(self.KEY_USER_TEMPERATURE_SETPOINT, heating_function, heating_function.KEY_USER_TEMPERATURE_SETPOINT) self.add_routing(self.KEY_USER_TEMPERATURE_SETPOINT, heating_function, heating_function.KEY_USER_TEMPERATURE_SETPOINT)
self.add_routing(self.KEY_AWAY_MODE, heating_function, heating_function.KEY_AWAY_MODE) self.add_routing(self.KEY_AWAY_MODE, heating_function, heating_function.KEY_AWAY_MODE)
@ -120,8 +115,10 @@ class videv_heating(videv_base):
class videv_multistate(videv_base): class videv_multistate(videv_base):
KEY_STATE = 'state_%d' KEY_STATE = 'state_%d'
def __init__(self, mqtt_client, topic, key_for_device, device, num_states, default_values=None): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
def connect_br_function(self, device, key_for_device, num_states):
self.num_states = num_states self.num_states = num_states
# send default values # send default values
for i in range(0, num_states): for i in range(0, num_states):
@ -139,13 +136,14 @@ class videv_audio_player(videv_base):
KEY_TITLE = 'title' KEY_TITLE = 'title'
NO_TITLE = '---' NO_TITLE = '---'
def __init__(self, mqtt_client, topic, *args): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
for i, device in enumerate(args): self.__device_cnt__ = 0
self.add_display(self.KEY_ACTIVE_PLAYER % i, device, device.KEY_STATE)
# def connect_audio_device(self, device):
for audio_device in args: self.add_display(self.KEY_ACTIVE_PLAYER % self.__device_cnt__, device, device.KEY_STATE)
audio_device.add_callback(audio_device.KEY_TITLE, None, self.__title_rx__, True) device.add_callback(device.KEY_TITLE, None, self.__title_rx__, True)
self.__device_cnt__ += 1
def __title_rx__(self, device, key, data): def __title_rx__(self, device, key, data):
self.__tx__(self.KEY_TITLE, data or self.NO_TITLE) self.__tx__(self.KEY_TITLE, data or self.NO_TITLE)

View File

@ -1,8 +1,6 @@
import config import config
import devdi.devices
import function import function
import json import json
import logging
import mqtt import mqtt
import os import os
import report import report
@ -46,20 +44,10 @@ if __name__ == "__main__":
password=config.MQTT_PASSWORD, name=config.APP_NAME) password=config.MQTT_PASSWORD, name=config.APP_NAME)
mc.add_callback(INFO_TOPIC, __info_publisher__) mc.add_callback(INFO_TOPIC, __info_publisher__)
#
# Smarthome physical Devices
#
pd = devdi.devices.physical_devices(mc)
#
# Smarthome physical Devices
#
vd = devdi.devices.videv_devices(mc)
# #
# Smart Home Functionality # Smart Home Functionality
# #
func = function.all_functions(mc, pd, vd) func = function.all_functions(mc)
while (True): while (True):
time.sleep(1) time.sleep(1)

View File

@ -1,87 +1,5 @@
# #
# TOPICS # TOPICS
# #
TOPIC_WARNINGS = "videv/warnings"
TOPIC_ALL_OFF_VIDEV = "videv/off" TOPIC_ALL_OFF_VIDEV = "videv/off"
TOPIC_ALL_SUMMER_WINTER_MODE = "videv/summer_mode" TOPIC_ALL_SUMMER_WINTER_MODE = "videv/summer_mode"
# ground floor west
# floor
TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/gfw/floor/main_light"
# marion
TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV = "videv/gfw/marion/main_light"
TOPIC_GFW_MARION_HEATING_VALVE_VIDEV = "videv/gfw/marion/heating_valve"
TOPIC_GFW_MARION_WINDOW_LAMP_VIDEV = "videv/gfw/marion/window_light"
# dirk
TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV = "videv/gfw/dirk/main_light"
TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV = "videv/gfw/dirk/desk_light"
TOPIC_GFW_DIRK_AMPLIFIER_VIDEV = "videv/gfw/dirk/amplifier"
TOPIC_GFW_DIRK_PHONO_VIDEV = "videv/gfw/dirk/phono"
TOPIC_GFW_DIRK_CD_PLAYER_VIDEV = "videv/gfw/dirk/cd_player"
TOPIC_GFW_DIRK_BT_VIDEV = "videv/gfw/dirk/bt"
TOPIC_GFW_DIRK_PC_DOCK_VIDEV = "videv/gfw/dirk/pc_dock"
TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV = "videv/gfw/dirk/active_brightness_device"
TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV = "videv/gfw/dirk/audio_player"
TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV = "videv/gfw/dirk/heating_valve"
# garden
TOPIC_GAR_GARDEN_MODE_VIDEV = "videv/gar/garden/mode"
TOPIC_GAR_GARDEN_GARLAND_VIDEV = "videv/gar/garden/garland"
TOPIC_GAR_GARDEN_REPEATER_VIDEV = "videv/gar/garden/repeater"
# first floor west
# floor
TOPIC_FFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/ffw/floor/main_light"
# julian
TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV = "videv/ffw/julian/main_light"
TOPIC_FFW_JULIAN_HEATING_VALVE_VIDEV = "videv/ffw/julian/heating_valve"
# bath
TOPIC_FFW_BATH_MAIN_LIGHT_VIDEV = "videv/ffw/bath/main_light"
TOPIC_FFW_BATH_HEATING_VALVE_VIDEV = "videv/ffw/bath/heating_valve"
# livingroom
TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV = "videv/ffw/livingroom/main_light"
TOPIC_FFW_LIVINGROOM_HEATING_VALVE_VIDEV = "videv/ffw/livingroom/heating_valve"
# sleep
TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV = "videv/ffw/sleep/main_light"
TOPIC_FFW_SLEEP_HEATING_VALVE_VIDEV = "videv/ffw/sleep/heating_valve"
TOPIC_FFW_SLEEP_WINDOW_LAMP_VIDEV = "videv/ffw/sleep/window_light"
# first floor east
# floor
TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV = "videv/ffe/floor/main_light"
# kitchen
TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV = "videv/ffe/kitchen/main_light"
TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV = "videv/ffe/kitchen/circulation_pump"
TOPIC_FFE_KITCHEN_HEATING_VALVE_VIDEV = "videv/ffe/kitchen/heating_valve"
# diningroom
TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV = "videv/ffe/diningroom/main_light"
TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV = "videv/ffe/diningroom/floorlamp"
TOPIC_FFE_DININGROOM_GARLAND_VIDEV = "videv/ffe/diningroom/garland"
TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV = "videv/ffe/diningroom/heating_valve"
# sleep
TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV = "videv/ffe/sleep/main_light"
TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV = "videv/ffe/sleep/bed_light_di"
TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV = "videv/ffe/sleep/bed_light_ma"
TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV = "videv/ffe/sleep/active_brightness_device"
TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV = "videv/ffe/sleep/heating_valve"
TOPIC_FFE_SLEEP_WARDROBE_LIGHT_VIDEV = "videv/ffe/sleep/wardrobe_light"
# livingroom
TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV = "videv/ffe/livingroom/main_light"
TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV = "videv/ffe/livingroom/floorlamp"
TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV = "videv/ffe/livingroom/xmas_tree"
TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV = "videv/ffe/livingroom/heating_valve"
# stairway
# floor
TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV = "videv/stw/stairway/main_light"