diff --git a/devdi b/devdi index c11d2e5..4fa0081 160000 --- a/devdi +++ b/devdi @@ -1 +1 @@ -Subproject commit c11d2e53fd326eb37ba4e4c53a890ff8f1a9a917 +Subproject commit 4fa00811c6d243888828e67b0952b5b06f46a3d7 diff --git a/devices/__init__.py b/devices/__init__.py index b59101d..89ae00d 100644 --- a/devices/__init__.py +++ b/devices/__init__.py @@ -25,11 +25,7 @@ devices (DEVICES) **Module Documentation:** """ - -try: - from config import APP_NAME as ROOT_LOGGER_NAME -except ImportError: - ROOT_LOGGER_NAME = 'root' +import logging from devices.shelly import shelly as shelly_sw1 from devices.shelly import shelly_rpc as shelly_pro3 @@ -46,7 +42,22 @@ from devices.silvercrest import silvercrest_motion_sensor from devices.mydevices import powerplug as my_powerplug from devices.mydevices import audio_status from devices.mydevices import remote -my_ambient = None + +from function.videv import videv_heating as videv_hea +from function.videv import videv_switch_brightness_color_temp as videv_sw_br_ct +from function.videv import videv_switch_brightness as videv_sw_br +from function.videv import videv_switching as videv_sw + +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): diff --git a/function/__init__.py b/function/__init__.py index 76a94bf..b6043c5 100644 --- a/function/__init__.py +++ b/function/__init__.py @@ -20,21 +20,25 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) class all_functions(room_collection): - def __init__(self, mqtt_client, pd, vd): - super().__init__(mqtt_client, pd, vd) + def __init__(self, mqtt_client): + # TODO: Remove this after changing to new devdi + from devdi.devices import physical_devices + pd = physical_devices(mqtt_client) + # TODO: Remove this after changing to new devdi + super().__init__(mqtt_client) # # Rooms # # garden - self.gar = garden(self.mqtt_client, pd, vd) + self.gar = garden(self.mqtt_client, pd) # stairway - self.stw = stairway(self.mqtt_client, pd, vd) + self.stw = stairway(self.mqtt_client, pd) # ground floor west - self.gfw = ground_floor_west(self.mqtt_client, pd, vd) + self.gfw = ground_floor_west(self.mqtt_client, pd) # first floor west - self.ffw = first_floor_west(self.mqtt_client, pd, vd) + self.ffw = first_floor_west(self.mqtt_client, pd) # first floor east - self.ffe = first_floor_east(self.mqtt_client, pd, vd) + self.ffe = first_floor_east(self.mqtt_client, pd) # # Interactions # @@ -50,9 +54,8 @@ class all_functions(room_collection): 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) # tradfri button ffe_sleep right click - self.ffe.sleep.button_tradfri.add_callback(self.ffe.sleep.button_tradfri.KEY_ACTION, - self.ffe.sleep.button_tradfri.ACTION_RIGHT, - self.ffe.floor.main_light_shelly.toggle_output_0_mcb) + self.ffe.sleep.input_device.add_callback(self.ffe.sleep.input_device.KEY_ACTION, + self.ffe.sleep.input_device.ACTION_RIGHT, self.ffe.floor.switch_main_light.toggle_output_0_mcb) def init_off_functionality(self): # ALL OFF - Virtual device @@ -64,12 +67,12 @@ class all_functions(room_collection): self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0, True, self.all_off) # FFE ALL OFF - Long push ffe_floor - self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0, - True, self.ffe.floor.main_light_shelly.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.floor.switch_main_light.flash_0_mcb) + 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 - 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 self.ffw.floor.main_light_shelly.add_callback(self.ffw.floor.main_light_shelly.KEY_LONGPUSH_0, diff --git a/function/first_floor_east.py b/function/first_floor_east.py index 3442fb6..350a33d 100644 --- a/function/first_floor_east.py +++ b/function/first_floor_east.py @@ -4,7 +4,7 @@ import config from devdi import topic as props -from devices import group +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 @@ -22,38 +22,26 @@ loc = props.LOC_FFE class first_floor_east(room_collection): - def __init__(self, mqtt_client, pd, vd): - super().__init__(mqtt_client, pd, vd) - self.dining = first_floor_east_dining(mqtt_client, pd, vd) - self.floor = first_floor_east_floor(mqtt_client, pd, vd) - self.kitchen = first_floor_east_kitchen(mqtt_client, pd, vd) - self.livingroom = first_floor_east_living(mqtt_client, pd, vd) - self.sleep = first_floor_east_sleep(mqtt_client, pd, vd) + 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(room): - def __init__(self, mqtt_client, pd, vd): - roo = props.ROO_FLO +class first_floor_east_floor(rooms.ffe_floor, room): + def __init__(self, mqtt_client): + super().__init__(mqtt_client) + room.__init__(self, mqtt_client) # - # Device initialisation - # - # http://shelly1l-3C6105E4E629 - # main light - self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) - super().__init__(mqtt_client, pd, vd) - - # - # Virtual Device Interface - # - # main light - self.main_light = videv_switching( - mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, - self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0 - ) + # 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, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_KIT # # Device initialisation @@ -69,7 +57,7 @@ class first_floor_east_kitchen(room): # heating function self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA) - super().__init__(mqtt_client, pd, vd) + super().__init__(mqtt_client) # # Functionality initialisation @@ -110,66 +98,32 @@ class first_floor_east_kitchen(room): ) -class first_floor_east_dining(room): - def __init__(self, mqtt_client, pd, vd): - roo = props.ROO_DIN - # - # Device initialisation +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) - - # http://shelly1l-84CCA8ADD055 - # main light - self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) - # floor lamp - self.floorlamp_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL) - # heating function - self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA) - # garland - if config.CHRISTMAS: - self.garland_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_GAR) - super().__init__(mqtt_client, pd, vd) - - # - # Functionality initialisation - # self.day_events.add_callback(None, True, self.__day_events__, True) - # main light - self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True) + # 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.heating_valve, + self.valve_heating, 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) - - # - # 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 - ) + # 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): @@ -180,92 +134,53 @@ class first_floor_east_dining(room): self.garland_powerplug.set_output_0(False) -class first_floor_east_sleep(room): - def __init__(self, mqtt_client, pd, vd): - roo = props.ROO_SLP +class first_floor_east_sleep(rooms.ffe_sleep, room): + def __init__(self, mqtt_client): + 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 - # main light - self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) - self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL) - # bed light - self.bed_light_di_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLD) - self.bed_light_ma_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLM) - # heating function - self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA) - # button - self.button_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_INP) - # 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 + 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) - super().__init__(mqtt_client, pd, vd) - - # - # Functionality initialisation - # # button / brightness function - self.brightness_functions = brightness_choose_n_action(self.button_tradfri) - self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0) - self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0) + 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.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_TOGGLE, - self.main_light_shelly.toggle_output_0_mcb) + 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.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT, - self.bed_light_di_tradfri.toggle_output_0_mcb) - self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT_LONG, - self.bed_light_ma_powerplug.toggle_output_0_mcb) - - # heating function - self.heating_function = heating_function( - self.heating_valve, - config.DEFAULT_TEMPERATURE, - **get_radiator_data(self.heating_valve.topic) - ) - self.heating_function.add_callback(None, None, set_radiator_data, True) - - # - # Virtual Device Interface - # - # main light - self.main_light_videv = videv_switch_brightness_color_temp( - mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV, - self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0, - self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS, - self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP - ) - # bed light - self.bed_light_di_videv = videv_switch_brightness( - mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, - self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0, - self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_BRIGHTNESS, - ) - self.bed_light_ma_videv = videv_switching( - mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, - self.bed_light_ma_powerplug, self.bed_light_ma_powerplug.KEY_OUTPUT_0 - ) - # heating function - self.heating_function_videv = videv_heating( - mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV, - self.heating_function - ) + 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 ) - 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, + + # 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, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_LIV # # Device initialisation @@ -283,7 +198,7 @@ class first_floor_east_living(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation diff --git a/function/first_floor_west.py b/function/first_floor_west.py index e54976a..40017b4 100644 --- a/function/first_floor_west.py +++ b/function/first_floor_west.py @@ -21,17 +21,17 @@ loc = props.LOC_FFW class first_floor_west(room_collection): - def __init__(self, mqtt_client, pd, vd): - super().__init__(mqtt_client, pd, vd) - self.floor = first_floor_west_floor(mqtt_client, pd, vd) - self.bath = first_floor_west_bath(mqtt_client, pd, vd) - self.julian = first_floor_west_julian(mqtt_client, pd, vd) - self.livingroom = first_floor_west_living(mqtt_client, pd, vd) - self.sleep = first_floor_west_sleep(mqtt_client, pd, vd) + def __init__(self, mqtt_client, pd): + super().__init__(mqtt_client) + self.floor = first_floor_west_floor(mqtt_client, pd) + self.bath = first_floor_west_bath(mqtt_client, pd) + self.julian = first_floor_west_julian(mqtt_client, pd) + self.livingroom = first_floor_west_living(mqtt_client, pd) + self.sleep = first_floor_west_sleep(mqtt_client, pd) class first_floor_west_floor(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_FLO # # Device initialisation @@ -39,7 +39,7 @@ class first_floor_west_floor(room): # 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) + super().__init__(mqtt_client) # # Virtual Device Interface @@ -52,7 +52,7 @@ class first_floor_west_floor(room): class first_floor_west_julian(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_JUL # # Device initialisation @@ -63,7 +63,7 @@ class first_floor_west_julian(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation # @@ -93,7 +93,7 @@ class first_floor_west_julian(room): class first_floor_west_bath(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_BAT # # Device initialisation @@ -103,7 +103,7 @@ class first_floor_west_bath(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation @@ -132,7 +132,7 @@ class first_floor_west_bath(room): class first_floor_west_living(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_LIV # # Device initialisation @@ -143,7 +143,7 @@ class first_floor_west_living(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation @@ -174,7 +174,7 @@ class first_floor_west_living(room): class first_floor_west_sleep(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_SLP # # Device initialisation @@ -187,7 +187,7 @@ class first_floor_west_sleep(room): self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA) # window light self.window_light = pd.get(props.STG_ZFW, loc, roo, props.FUN_WIL) - super().__init__(mqtt_client, pd, vd) + super().__init__(mqtt_client) # # Functionality initialisation diff --git a/function/garden.py b/function/garden.py index d70519e..ea9815c 100644 --- a/function/garden.py +++ b/function/garden.py @@ -19,13 +19,13 @@ loc = props.LOC_GAR class garden(room_collection): - def __init__(self, mqtt_client, pd, vd): - super().__init__(mqtt_client, pd, vd) - self.garden = garden_garden(mqtt_client, pd, vd) + def __init__(self, mqtt_client, pd): + super().__init__(mqtt_client) + self.garden = garden_garden(mqtt_client, pd) class garden_garden(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_GAR # # Device initialisation @@ -37,7 +37,7 @@ class garden_garden(room): # repeater self.repeater = pd.get(props.STG_ZGW, loc, roo, props.FUN_REP) - super().__init__(mqtt_client, pd, vd) + super().__init__(mqtt_client) # # Functionality initialisation diff --git a/function/ground_floor_west.py b/function/ground_floor_west.py index 95b61df..b47b67b 100644 --- a/function/ground_floor_west.py +++ b/function/ground_floor_west.py @@ -4,7 +4,6 @@ import config from devdi import topic as 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 @@ -22,15 +21,15 @@ 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) + def __init__(self, mqtt_client, pd): + super().__init__(mqtt_client) + self.dirk = ground_floor_west_dirk(mqtt_client, pd) + self.floor = ground_floor_west_floor(mqtt_client, pd) + self.marion = ground_floor_west_marion(mqtt_client, pd) class ground_floor_west_floor(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_FLO # # Device initialisation @@ -38,7 +37,7 @@ class ground_floor_west_floor(room): # 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) + super().__init__(mqtt_client) # # Functionality initialisation @@ -58,7 +57,7 @@ class ground_floor_west_floor(room): class ground_floor_west_marion(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_MAR # # Device initialisation @@ -70,7 +69,7 @@ class ground_floor_west_marion(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation @@ -118,7 +117,7 @@ class ground_floor_west_dirk(room): AUDIO_SOURCE_BT = 3 AUDIO_SOURCE_PHONO = 4 - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): roo = props.ROO_DIR # # Device initialisation @@ -146,7 +145,7 @@ class ground_floor_west_dirk(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation # diff --git a/function/rooms.py b/function/rooms.py index 42f4694..a63de5b 100644 --- a/function/rooms.py +++ b/function/rooms.py @@ -13,10 +13,8 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) class room(object): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client): self.mqtt_client = mqtt_client - self.pd = pd - self.vd = vd def all_off(self, device=None, key=None, data=None): logger.info("Switching all off \"%s\"", type(self).__name__) @@ -37,10 +35,8 @@ class room(object): class room_collection(object): ALLOWED_CLASSES = ("room", "room_collection") - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client): self.mqtt_client = mqtt_client - self.pd = pd - self.vd = vd def all_off(self, device=None, key=None, data=None): logger.info("Switching all off \"%s\"", type(self).__name__) diff --git a/function/stairway.py b/function/stairway.py index 8f9ccae..dc2b208 100644 --- a/function/stairway.py +++ b/function/stairway.py @@ -19,13 +19,13 @@ loc = props.LOC_STW class stairway(room_collection): - def __init__(self, mqtt_client, pd, vd): - super().__init__(mqtt_client, pd, vd) - self.stairway = stairway_stairway(mqtt_client, pd, vd) + def __init__(self, mqtt_client, pd): + super().__init__(mqtt_client) + self.stairway = stairway_stairway(mqtt_client, pd) class stairway_stairway(room): - def __init__(self, mqtt_client, pd, vd): + def __init__(self, mqtt_client, pd): # # Device initialisation # @@ -33,7 +33,7 @@ class stairway_stairway(room): 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) + super().__init__(mqtt_client) # # Functionality initialisation diff --git a/function/videv.py b/function/videv.py index 93b2f76..4737450 100644 --- a/function/videv.py +++ b/function/videv.py @@ -37,8 +37,13 @@ class videv_pure_switch(videv_base): class videv_switching(videv_base): KEY_STATE = 'state' - def __init__(self, mqtt_client, topic, sw_device, sw_key): + def __init__(self, mqtt_client, topic, sw_device=None, sw_key=None): super().__init__(mqtt_client, topic) + # TODO: Remove the following code and the parameters from __init__ + if sw_device is not None and sw_key is not None: + self.connect_sw_device(sw_device, sw_key) + + def connect_sw_device(self, sw_device, sw_key): self.add_routing(self.KEY_STATE, sw_device, sw_key) @@ -69,25 +74,29 @@ class videv_switching_motion(videv_base): self.add_display(self.KEY_MOTION_SENSOR % index, motion_sensor, motion_sensor.KEY_OCCUPANCY) -class videv_switch_brightness(videv_base): - KEY_STATE = 'state' +class videv_switch_brightness(videv_switching): KEY_BRIGHTNESS = 'brightness' - def __init__(self, mqtt_client, topic, sw_device, sw_key, br_device, br_key): - super().__init__(mqtt_client, topic) - self.add_routing(self.KEY_STATE, sw_device, sw_key) + def __init__(self, mqtt_client, topic, sw_device=None, sw_key=None, br_device=None, br_key=None): + super().__init__(mqtt_client, topic, sw_device, sw_key) + # TODO: Remove the following code and the parameters from __init__ + if br_device is not None and br_key is not None: + self.connect_br_device(br_device, br_key) + + def connect_br_device(self, br_device, br_key): self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key) -class videv_switch_brightness_color_temp(videv_base): - KEY_STATE = 'state' - KEY_BRIGHTNESS = 'brightness' +class videv_switch_brightness_color_temp(videv_switch_brightness): KEY_COLOR_TEMP = 'color_temp' - def __init__(self, mqtt_client, topic, sw_device, sw_key, br_device, br_key, ct_device, ct_key): - 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 __init__(self, mqtt_client, topic, sw_device=None, sw_key=None, br_device=None, br_key=None, ct_device=None, ct_key=None): + super().__init__(mqtt_client, topic, sw_device, sw_key, br_device, br_key) + # TODO: Remove the following code and the parameters from __init__ + if ct_device is not None and ct_key is not None: + self.connect_ct_device(ct_device, ct_key) + + def connect_ct_device(self, ct_device, ct_key): self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key) @@ -102,8 +111,13 @@ class videv_heating(videv_base): # KEY_TEMPERATURE = 'temperature' - def __init__(self, mqtt_client, topic, heating_function): + def __init__(self, mqtt_client, topic, heating_function=None): super().__init__(mqtt_client, topic) + # TODO: Remove the following code and the parameters from __init__ + if heating_function is not None: + self.connect_heating_function(heating_function) + + 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_AWAY_MODE, heating_function, heating_function.KEY_AWAY_MODE) diff --git a/smart_brain.py b/smart_brain.py index 80561c4..4248329 100644 --- a/smart_brain.py +++ b/smart_brain.py @@ -1,8 +1,6 @@ import config -import devdi.devices import function import json -import logging import mqtt import os import report @@ -46,20 +44,10 @@ if __name__ == "__main__": password=config.MQTT_PASSWORD, name=config.APP_NAME) 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 # - func = function.all_functions(mc, pd, vd) + func = function.all_functions(mc) while (True): time.sleep(1)