diff --git a/__init__.py b/__init__.py index 6406b7c..e69de29 100644 --- a/__init__.py +++ b/__init__.py @@ -1,344 +0,0 @@ - -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -from devdi import props -from devices import group -import logging -import sys - -try: - from config import APP_NAME as ROOT_LOGGER_NAME -except ImportError: - ROOT_LOGGER_NAME = 'root' -logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) - - -class base(dict): - def __init__(self, mqtt_client): - super().__init__(self) - - def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None, ot=None): - """Method to initilise a device - - Args: - stg (numeric): Source transmittion group (see SIS_* in props) - loc (numeric): Location (see LOC_* in props) - roo (numeric): Room (see ROO_* in props) - fun (numeric): Function (see FUN_* in props) - dty (numeric): Device type (see DTP_* in props) - num (numeric): Device number in case of multiple devices - """ - def get_device(dty, mqtt_client, topic, ot): - # Temporary to fit to current implementation - if ot != topic: - logger.error("Topic change for %s: Using this one: %s", topic, ot) - topic = ot - dev_class = props.dty_repr(dty) - if dev_class is None: - logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic) - else: - return dev_class(mqtt_client, topic) - - topic = self.__topic__(stg, loc, roo, fun) - if num is None: - this_device = get_device(dty, mqtt_client, topic, ot) - if this_device is None: - logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic) - else: - self[topic] = this_device - else: - dg = [] - for i in num: - device_topic = self.__topic__(stg, loc, roo, fun) + '_%d' % i - dg.append(get_device(dty, mqtt_client, device_topic, ot=ot % i)) - self[topic] = group(*dg) - - def get(self, stg, loc, roo, fun): - """Method to get a device - - Args: - stg (numeric): Source transmittion group (see SIS_* in props) - loc (numeric): Location (see LOC_* in props) - roo (numeric): Room (see ROO_* in props) - fun (numeric): Function (see FUN_* in props) - num (numeric): Device number in case of multiple devices - """ - topic = self.__topic__(stg, loc, roo, fun) - return self[topic] - - def __topic__(self, stg, loc, roo, fun): - if stg in [props.STG_ZFE, props.STG_ZFW, props.STG_ZGW]: - # Temporary to fit to current implementation - return '/'.join([ - props.stg_repr(stg), - props.roo_repr(roo), - props.fun_repr(fun) - ]) - else: - return '/'.join([ - props.stg_repr(stg), - props.loc_repr(loc), - props.roo_repr(roo), - props.fun_repr(fun) - ]) - - -class physical_devices(base): - """ - Class to create and store physical smarthome devices - """ - - def __init__(self, mqtt_client): - super().__init__(self) - self.__init_gfw__(mqtt_client) - self.__init_ffw__(mqtt_client) - self.__init_ffe__(mqtt_client) - self.__init_stw__(mqtt_client) - - def __init_gfw__(self, mqtt_client): - loc = props.LOC_GFW - - # MARION - roo = props.ROO_MAR - # - # Temporary to fit to current implementation ################################################### - TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY = "shellies/gfw/marion/main_light" - TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE = "zigbee/gfw/marion/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - # FLOOR - roo = props.ROO_FLO - # - # Temporary to fit to current implementation ################################################### - TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY = "shellies/gfw/floor/main_light" - TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/floor/main_light_%d" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, - range(1, 3), ot=TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - - # DIRK - roo = props.ROO_DIR - # - # Temporary to fit to current implementation ################################################### - TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY = "shellies/gfw/dirk/main_light" - TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/dirk/main_light" - TOPIC_GFW_DIRK_INPUT_DEVICE = "zigbee/gfw/dirk/input_device" - TOPIC_GFW_DIRK_POWERPLUG = "my_apps/gfw/dirk/powerplug" - TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE = "zigbee/gfw/dirk/desk_light" - TOPIC_GFW_DIRK_AMPLIFIER_REMOTE = "my_apps/gfw/dirk/remote/RAS5" - TOPIC_GFW_DIRK_SPOTIFY = "my_apps/gfw/dirk/hifi/spotify" - TOPIC_GFW_DIRK_MPD = "my_apps/gfw/dirk/hifi/mpd" - TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE = "zigbee/gfw/dirk/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, - ot=TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx, - ot=TOPIC_GFW_DIRK_INPUT_DEVICE) # Tradfri Input Device 5 Buttons - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx, ot=TOPIC_GFW_DIRK_POWERPLUG) # My 4 port Powerplug - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT, ot=TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE), # Tradfri Desklight - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx, - ot=TOPIC_GFW_DIRK_AMPLIFIER_REMOTE) # Remote Control IR Amplifier - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx, ot=TOPIC_GFW_DIRK_SPOTIFY) # Audio status Spotify - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx, ot=TOPIC_GFW_DIRK_MPD) # Audio status MPD - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - def __init_ffw__(self, mqtt_client): - loc = props.LOC_FFW - # JULIAN - roo = props.ROO_JUL - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY = "shellies/ffw/julian/main_light" - TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/julian/main_light" - TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE = "zigbee/ffw/julian/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, - ot=TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - # BATH - roo = props.ROO_BAT - # - # Temporary to fit to current implementation - # Temporary to fit to current implementation ################################################### - TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE = "zigbee/ffw/bath/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - # LIVINGROOM - roo = props.ROO_LIV - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffw/livingroom/main_light" - TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/livingroom/main_light" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, - ot=TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - - # SLEEP - roo = props.ROO_SLP - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffw/sleep/main_light" - TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/sleep/main_light" - TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffw/sleep/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx, - ot=TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - def __init_ffe__(self, mqtt_client): - loc = props.LOC_FFE - # FLOOR - roo = props.ROO_FLO - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY = "shellies/ffe/floor/main_light" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY) # Shelly Main Light - - # KITCHEN - roo = props.ROO_KIT - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY = "shellies/ffe/kitchen/main_light" - TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY = "shellies/ffe/kitchen/circulation_pump" - TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE = "zigbee/ffe/kitchen/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1, - ot=TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - # DININGROOM - roo = props.ROO_DIN - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/diningroom/main_light" - TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG = "zigbee/ffe/diningroom/powerplug_floorlamp" - TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG = "zigbee/ffe/diningroom/garland" - TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/diningroom/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1, - ot=TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG) # Powerplug Floor Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1, - ot=TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG) # Powerplug Garland - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - # SLEEP - roo = props.ROO_SLP - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffe/sleep/main_light" - TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/sleep/main_light" - TOPIC_FFE_SLEEP_INPUT_DEVICE = "zigbee/ffe/sleep/input_device" - TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE = "zigbee/ffe/sleep/bed_light_di" - TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG = "zigbee/ffe/sleep/bed_light_ma" - TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffe/sleep/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, - ot=TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx, - ot=TOPIC_FFE_SLEEP_INPUT_DEVICE) # Tradfri Input Device 5 Buttons - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx, - ot=TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE) # Tradfri Bed Light Dirk - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1, - ot=TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG) # Powerplug Bed Light Marion - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - # LIVINGROOM - roo = props.ROO_LIV - # - # Temporary to fit to current implementation ################################################### - TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/livingroom/main_light" - TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/livingroom/main_light" - TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE = "zigbee/ffe/livingroom/floorlamp_%d" - TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-tree" - TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-star" - TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/livingroom/heating_valve" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, - ot=TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, - range(1, 7), ot=TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1, - ot=TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1, - ot=TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, - ot=TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE) # Brennenstuhl Heatingvalve - - def __init_stw__(self, mqtt_client): - loc = props.LOC_STW - # FLOOR - # - # Temporary to fit to current implementation ################################################### - TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY = "shellies/stw/stairway/main_light" - TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF = "zigbee/ffe/stairway/motion_sensor_ff" - TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF = "zigbee/gfw/stairway/motion_sensor_gf" - # Temporary to fit to current implementation ################################################### - self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1, - ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx, - ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF) # Motion Sensor First Floor - self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx, - ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF) # Motion Sensor Ground Floor - - -class videv_devices(base): - """ - Class to create and store videv smarthome devices - """ - - def __init__(self, mqtt_client): - super().__init__(self) - self.__init_gfw__(mqtt_client) - self.__init_ffw__(mqtt_client) - self.__init_ffe__(mqtt_client) - self.__init_stw__(mqtt_client) - - def __init_gfw__(self, mqtt_client): - loc = props.LOC_GFW - # TODO: Add devices - - def __init_ffw__(self, mqtt_client): - loc = props.LOC_FFW - # TODO: Add devices - - def __init_ffe__(self, mqtt_client): - loc = props.LOC_FFE - # TODO: Add devices - - def __init_stw__(self, mqtt_client): - loc = props.LOC_STW - # TODO: Add devices diff --git a/devices.py b/devices.py new file mode 100644 index 0000000..d1d3b40 --- /dev/null +++ b/devices.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +from devdi import topic as props +from devdi.topic import topic_by_props +import devices +import logging +import sys + +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' +logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) + + +class base(dict): + def __init__(self, mqtt_client): + super().__init__(self) + + def __dty_repr__(self, dty): + return { + props.DTY_SHY_SW1: devices.shelly_sw1, + props.DTY_TLI_Sxx: devices.tradfri_sw, + props.DTY_TLI_SBx: devices.tradfri_sw_br, + props.DTY_TLI_SBT: devices.tradfri_sw_br_ct, + props.DTY_TIN_5xx: devices.tradfri_button, + props.DTY_LLI_SBT: devices.livarno_sw_br_ct, + props.DTY_BVL_xxx: devices.brennenstuhl_heatingvalve, + props.DTY_SPP_SW1: devices.silvercrest_powerplug, + props.DTY_SMS_xxx: devices.silvercrest_motion_sensor, + props.DTY_MPP_4xx: devices.my_powerplug, + props.DTY_MAS_xxx: devices.audio_status, + props.DTY_MRE_xxx: devices.remote, + }.get(dty) + + def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None): + """Method to initilise a device + + Args: + stg (numeric): Source transmittion group (see SIS_* in props) + loc (numeric): Location (see LOC_* in props) + roo (numeric): Room (see ROO_* in props) + fun (numeric): Function (see FUN_* in props) + dty (numeric): Device type (see DTP_* in props) + num (numeric): Device number in case of multiple devices + """ + def get_device(dty, mqtt_client, topic): + dev_class = self.__dty_repr__(dty) + if dev_class is None: + logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic) + else: + return dev_class(mqtt_client, topic) + + topic = str(topic_by_props(stg, loc, roo, fun)) + if num is None: + this_device = get_device(dty, mqtt_client, topic) + if this_device is None: + logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic) + else: + self[topic] = this_device + else: + dg = [] + for i in num: + device_topic = topic + '_%d' % i + dg.append(get_device(dty, mqtt_client, device_topic)) + self[topic] = devices.group(*dg) + + def get(self, stg, loc, roo, fun): + """Method to get a device + + Args: + stg (numeric): Source transmittion group (see SIS_* in props) + loc (numeric): Location (see LOC_* in props) + roo (numeric): Room (see ROO_* in props) + fun (numeric): Function (see FUN_* in props) + num (numeric): Device number in case of multiple devices + """ + topic = self.__topic__(stg, loc, roo, fun) + return self[topic] + + +class physical_devices(base): + """ + Class to create and store physical smarthome devices + """ + + def __init__(self, mqtt_client): + super().__init__(self) + self.__init_gfw__(mqtt_client) + self.__init_ffw__(mqtt_client) + self.__init_ffe__(mqtt_client) + self.__init_stw__(mqtt_client) + + def __init_gfw__(self, mqtt_client): + loc = props.LOC_GFW + + # MARION + roo = props.ROO_MAR + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # FLOOR + roo = props.ROO_FLO + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT) # Tradfri Main Light + + # DIRK + roo = props.ROO_DIR + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons + self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx) # My 4 port Powerplug + self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT) # Tradfri Desklight + self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx) # Remote Control IR Amplifier + self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx) # Audio status Spotify + self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx) # Audio status MPD + self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # GARDEN + self.add(mqtt_client, props.STG_ZGW, props.LOC_GAR, props.ROO_GAR, props.FUN_GAR, props.DTY_SPP_SW1) + + def __init_ffw__(self, mqtt_client): + loc = props.LOC_FFW + # JULIAN + roo = props.ROO_JUL + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # BATH + roo = props.ROO_BAT + # + self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # LIVINGROOM + roo = props.ROO_LIV + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light + + # SLEEP + roo = props.ROO_SLP + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + def __init_ffe__(self, mqtt_client): + loc = props.LOC_FFE + # FLOOR + roo = props.ROO_FLO + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + + # KITCHEN + roo = props.ROO_KIT + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # DININGROOM + roo = props.ROO_DIN + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1) # Powerplug Floor Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplug Garland + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # SLEEP + roo = props.ROO_SLP + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx) # Tradfri Bed Light Dirk + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1) # Powerplug Bed Light Marion + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + # LIVINGROOM + roo = props.ROO_LIV + # + self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1) # Tradfri Main Light + self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve + + def __init_stw__(self, mqtt_client): + loc = props.LOC_STW + # FLOOR + # + self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light + self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor First Floor + self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor Ground Floor + + +class videv_devices(base): + """ + Class to create and store videv smarthome devices + """ + + def __init__(self, mqtt_client): + super().__init__(self) + self.__init_gfw__(mqtt_client) + self.__init_ffw__(mqtt_client) + self.__init_ffe__(mqtt_client) + self.__init_stw__(mqtt_client) + + def __init_gfw__(self, mqtt_client): + loc = props.LOC_GFW + # TODO: Add devices + + def __init_ffw__(self, mqtt_client): + loc = props.LOC_FFW + # TODO: Add devices + + def __init_ffe__(self, mqtt_client): + loc = props.LOC_FFE + # TODO: Add devices + + def __init_stw__(self, mqtt_client): + loc = props.LOC_STW + # TODO: Add devices diff --git a/props.py b/props.py deleted file mode 100644 index 4a9e657..0000000 --- a/props.py +++ /dev/null @@ -1,191 +0,0 @@ -import devices - - -# -# Device TYpe definitions -# -DTY_SHY_SW1 = 1 -""" Shelly """ -DTY_TLI_Sxx = 2 -""" Tradfri Light (Switching only) """ -DTY_TLI_SBx = 3 -""" Tradfri Light (Switching and Brightnes) """ -DTY_TLI_SBT = 4 -""" Tradfri Light (Switching, Brightnes and Colortemperature) """ -DTY_TIN_5xx = 5 -""" Tradfri Input Device (5 Buttons) """ -DTY_LLI_SBT = 6 -""" Livarno Light (Switching, Brightnes and Colortemperature) """ -DTY_BVL_xxx = 7 -""" Brennenstuhl Heatingvalve """ -DTY_SPP_SW1 = 8 -""" Silvercrest Powerplug """ -DTY_SMS_xxx = 9 -""" Silvercrest Motion Sensor """ -DTY_MPP_4xx = 10 -""" My Powerplug (4 plugs) """ -DTY_MAS_xxx = 11 -""" My Audio status (MPD) """ -DTY_MRE_xxx = 12 -""" My Remote control """ -def dty_repr(dty): - return { - DTY_SHY_SW1: devices.shelly_sw1, - DTY_TLI_Sxx: devices.tradfri_sw, - DTY_TLI_SBx: devices.tradfri_sw_br, - DTY_TLI_SBT: devices.tradfri_sw_br_ct, - DTY_TIN_5xx: devices.tradfri_button, - DTY_LLI_SBT: devices.livarno_sw_br_ct, - DTY_BVL_xxx: devices.brennenstuhl_heatingvalve, - DTY_SPP_SW1: devices.silvercrest_powerplug, - DTY_SMS_xxx: devices.silvercrest_motion_sensor, - DTY_MPP_4xx: devices.my_powerplug, - DTY_MAS_xxx: devices.audio_status, - DTY_MRE_xxx: devices.remote, - }.get(dty) - -# -# Source Transmission Group -# -STG_ZGW = 1 -""" Zigbee ground floor west """ -STG_ZFW = 2 -""" Zigbee first floor west """ -STG_ZFE = 3 -""" Zigbee first floor east """ -STG_SHE = 4 -""" Shellies """ -STG_MYA = 5 -""" My Applications """ -def stg_repr(stg): - return { - STG_ZGW: 'zigbee/gfw', # TODO: -> zigbee_gfw - STG_ZFW: 'zigbee/ffw', # TODO: -> zigbee_ffw - STG_ZFE: 'zigbee/ffe', # TODO: -> zigbee_ffe - STG_SHE: 'shellies', - STG_MYA: 'my_apps', - }.get(stg) - -# -# LOCation -# -LOC_GFW = 1 -""" Grounf floor west """ -LOC_GFE = 2 -""" Ground floor east """ -LOC_STW = 3 -""" Stairway """ -LOC_FFW = 4 -""" First floor west """ -LOC_FFE = 5 -""" First floor east """ -LOC_STW = 6 -""" Stairways """ -def loc_repr(loc): - return { - LOC_GFW: 'gfw', - LOC_GFE: 'gfe', - LOC_STW: 'stw', - LOC_FFW: 'ffw', - LOC_FFE: 'ffe', - LOC_STW: 'stw', - }.get(loc) - -# -# ROOms -# -ROO_DIN = 1 -""" Diningroom """ -ROO_KIT = 2 -""" Kitchen """ -ROO_LIV = 3 -""" Livingroom """ -ROO_FLO = 4 -""" Floor """ -ROO_SLP = 5 -""" Sleep """ -ROO_BAT = 6 -""" Bath """ -ROO_DIR = 7 -""" Dirk """ -ROO_MAR = 8 -""" Marion """ -ROO_JUL = 9 -""" Julian """ -ROO_STG = 10 -""" ground floor """ -ROO_STF = 11 -""" first floor """ -def roo_repr(roo): - return { - ROO_DIN: 'diningroom', - ROO_KIT: 'kitchen', - ROO_LIV: 'livingroom', - ROO_FLO: 'floor', - ROO_SLP: 'sleep', - ROO_BAT: 'bath', - ROO_DIR: 'dirk', - ROO_MAR: 'marion', - ROO_JUL: 'julian', - ROO_STG: 'groundfloor', - ROO_STF: 'firstfloor' - }.get(roo) - -# -# FUNctions -# -FUN_MAL = 1 -""" Main Light """ -FUN_DEL = 2 -""" Desk Light """ -FUN_FLL = 3 -""" Floor Light """ -FUN_BLD = 4 -""" Bed Light Dirk """ -FUN_BLM = 5 -""" Bed Light Marion """ -FUN_HEA = 6 -""" Heating """ -FUN_MPP = 7 -""" Multiple Powerplugs """ -FUN_INP = 8 -""" Input Device """ -FUN_CIR = 9 -""" Circulation Pump """ -FUN_GAR = 10 -""" Garland """ -FUN_XTR = 11 -""" X-Mas Tree """ -FUN_XST = 12 -""" X-Mas Star """ -FUN_MSE = 13 -""" Motion Sensor """ -FUN_RCA = 14 -""" Remote Control Amplifier """ -FUN_RCC = 15 -""" Remote Control CD-Player """ -FUN_ASS = 16 -""" Audio status spotify """ -FUN_ASM = 17 -""" Audio status mpd """ - -def fun_repr(fun): - return { - FUN_MAL: 'main_light', - FUN_DEL: 'desk_light', - FUN_FLL: 'floor_light', - FUN_BLD: 'bed_light_di', - FUN_BLM: 'bed_light_ma', - FUN_HEA: 'heating_valve', - FUN_MPP: 'powerplug', - FUN_INP: 'input_device', - FUN_CIR: 'circulation_pump', - FUN_GAR: 'garland', - FUN_XTR: 'xmas-tree', - FUN_XST: 'xmas-star', - FUN_MSE: 'motion_sensor', - FUN_RCA: 'remote_ctrl_amp', - FUN_RCC: 'remote_ctrl_cd', - FUN_ASS: 'audio_status_spotify', - FUN_ASM: 'audio_status_mpd', - }.get(fun) diff --git a/topic.py b/topic.py new file mode 100644 index 0000000..52064c0 --- /dev/null +++ b/topic.py @@ -0,0 +1,230 @@ +from collections import UserString + +# +# Device TYpe definitions +# +DTY_SHY_SW1 = 1 +""" Shelly """ +DTY_TLI_Sxx = 2 +""" Tradfri Light (Switching only) """ +DTY_TLI_SBx = 3 +""" Tradfri Light (Switching and Brightnes) """ +DTY_TLI_SBT = 4 +""" Tradfri Light (Switching, Brightnes and Colortemperature) """ +DTY_TIN_5xx = 5 +""" Tradfri Input Device (5 Buttons) """ +DTY_LLI_SBT = 6 +""" Livarno Light (Switching, Brightnes and Colortemperature) """ +DTY_BVL_xxx = 7 +""" Brennenstuhl Heatingvalve """ +DTY_SPP_SW1 = 8 +""" Silvercrest Powerplug """ +DTY_SMS_xxx = 9 +""" Silvercrest Motion Sensor """ +DTY_MPP_4xx = 10 +""" My Powerplug (4 plugs) """ +DTY_MAS_xxx = 11 +""" My Audio status (MPD) """ +DTY_MRE_xxx = 12 +""" My Remote control """ + + +# +# Source Transmission Group +# +STG_ZGW = 1 +""" Zigbee ground floor west """ +STG_ZFW = 2 +""" Zigbee first floor west """ +STG_ZFE = 3 +""" Zigbee first floor east """ +STG_SHE = 4 +""" Shellies """ +STG_MYA = 5 +""" My Applications """ + + +# +# LOCation +# +LOC_GFW = 1 +""" Grounf floor west """ +LOC_GFE = 2 +""" Ground floor east """ +LOC_STW = 3 +""" Stairway """ +LOC_FFW = 4 +""" First floor west """ +LOC_FFE = 5 +""" First floor east """ +LOC_STW = 6 +""" Stairways """ +LOC_GAR = 7 + + +# +# ROOms +# +ROO_DIN = 1 +""" Diningroom """ +ROO_KIT = 2 +""" Kitchen """ +ROO_LIV = 3 +""" Livingroom """ +ROO_FLO = 4 +""" Floor """ +ROO_SLP = 5 +""" Sleep """ +ROO_BAT = 6 +""" Bath """ +ROO_DIR = 7 +""" Dirk """ +ROO_MAR = 8 +""" Marion """ +ROO_JUL = 9 +""" Julian """ +ROO_STG = 10 +""" ground floor """ +ROO_STF = 11 +""" first floor """ +ROO_GAR = 12 +""" garden """ + + +# +# FUNctions +# +FUN_MAL = 1 +""" Main Light """ +FUN_DEL = 2 +""" Desk Light """ +FUN_FLL = 3 +""" Floor Light """ +FUN_BLD = 4 +""" Bed Light Dirk """ +FUN_BLM = 5 +""" Bed Light Marion """ +FUN_HEA = 6 +""" Heating """ +FUN_MPP = 7 +""" Multiple Powerplugs """ +FUN_INP = 8 +""" Input Device """ +FUN_CIR = 9 +""" Circulation Pump """ +FUN_GAR = 10 +""" Garland """ +FUN_XTR = 11 +""" X-Mas Tree """ +FUN_XST = 12 +""" X-Mas Star """ +FUN_MSE = 13 +""" Motion Sensor """ +FUN_RCA = 14 +""" Remote Control Amplifier """ +FUN_RCC = 15 +""" Remote Control CD-Player """ +FUN_ASS = 16 +""" Audio status spotify """ +FUN_ASM = 17 +""" Audio status mpd """ + + +class topic_by_props(UserString): + def __init__(self, stg, loc, roo, fun): + if stg in [STG_ZFE, STG_ZFW, STG_ZGW]: + # TODO: Temporary to fit to current implementation + topic = '/'.join([ + self.__stg_repr__(stg), + self.__roo_repr__(roo), + self.__fun_repr__(fun) + ]) + else: + topic = '/'.join([ + self.__stg_repr__(stg), + self.__loc_repr__(loc), + self.__roo_repr__(roo), + self.__fun_repr__(fun) + ]) + + UserString.__init__(self, self.__tmp_old_topics__(stg, loc, roo, fun) or topic) + + def __tmp_old_topics__(self, stg, loc, roo, fun): + # TODO: Temporary to fit to current implementation + if stg == STG_MYA and loc == LOC_GFW and roo == ROO_DIR and fun == FUN_RCA: + return "my_apps/gfw/dirk/remote/RAS5" + elif stg == STG_MYA and loc == LOC_GFW and roo == ROO_DIR and fun == FUN_ASS: + return "my_apps/gfw/dirk/hifi/spotify" + elif stg == STG_MYA and loc == LOC_GFW and roo == ROO_DIR and fun == FUN_ASM: + return "my_apps/gfw/dirk/hifi/mpd" + elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_DIN and fun == FUN_FLL: + return "zigbee/ffe/diningroom/powerplug_floorlamp" + elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_LIV and fun == FUN_FLL: + return "zigbee/ffe/livingroom/floorlamp" + elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_LIV and fun == FUN_XTR: + return "zigbee/ffe/livingroom/powerplug_xmas-tree" + elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_LIV and fun == FUN_XST: + return "zigbee/ffe/livingroom/powerplug_xmas-star" + elif stg == STG_SHE and loc == LOC_STW and roo == ROO_STF and fun == FUN_MAL: + return "shellies/stw/stairway/main_light" + elif stg == STG_ZFE and loc == LOC_STW and roo == ROO_STF and fun == FUN_MSE: + return "zigbee/ffe/stairway/motion_sensor_ff" + elif stg == STG_ZGW and loc == LOC_STW and roo == ROO_STG and fun == FUN_MSE: + return "zigbee/gfw/stairway/motion_sensor_gf" + + def __stg_repr__(self, stg): + return { + STG_ZGW: 'zigbee/gfw', # TODO: -> zigbee_gfw + STG_ZFW: 'zigbee/ffw', # TODO: -> zigbee_ffw + STG_ZFE: 'zigbee/ffe', # TODO: -> zigbee_ffe + STG_SHE: 'shellies', + STG_MYA: 'my_apps', + }.get(stg) + + def __loc_repr__(self, loc): + return { + LOC_GFW: 'gfw', + LOC_GFE: 'gfe', + LOC_STW: 'stw', + LOC_FFW: 'ffw', + LOC_FFE: 'ffe', + LOC_STW: 'stw', + LOC_GAR: 'gar', + }.get(loc) + + def __roo_repr__(self, roo): + return { + ROO_DIN: 'diningroom', + ROO_KIT: 'kitchen', + ROO_LIV: 'livingroom', + ROO_FLO: 'floor', + ROO_SLP: 'sleep', + ROO_BAT: 'bath', + ROO_DIR: 'dirk', + ROO_MAR: 'marion', + ROO_JUL: 'julian', + ROO_STG: 'groundfloor', + ROO_STF: 'firstfloor', + ROO_GAR: 'garden', + }.get(roo) + + def __fun_repr__(self, fun): + return { + FUN_MAL: 'main_light', + FUN_DEL: 'desk_light', + FUN_FLL: 'floor_light', + FUN_BLD: 'bed_light_di', + FUN_BLM: 'bed_light_ma', + FUN_HEA: 'heating_valve', + FUN_MPP: 'powerplug', + FUN_INP: 'input_device', + FUN_CIR: 'circulation_pump', + FUN_GAR: 'garland', + FUN_XTR: 'xmas-tree', + FUN_XST: 'xmas-star', + FUN_MSE: 'motion_sensor', + FUN_RCA: 'remote_ctrl_amp', + FUN_RCC: 'remote_ctrl_cd', + FUN_ASS: 'audio_status_spotify', + FUN_ASM: 'audio_status_mpd', + }.get(fun)