123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
-
- #!/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 devices(dict):
- """
- Class to select a device and hold the device information
- """
-
- def __init__(self, mqtt_client):
- dict.__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
-
- 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)
- ])
|