123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- #!/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 range(1, num + 1):
- 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)
- """
- topic = topic_by_props(stg, loc, roo, fun)
- return self[topic]
-
- def get_str(self, stg, loc, roo, fun):
- """Method to get a device by str version of props
-
- Args:
- stg (str): Source transmittion group (see SIS_* in props)
- loc (str): Location (see LOC_* in props)
- roo (str): Room (see ROO_* in props)
- fun (str): Function (see FUN_* in props)
- """
- return self.get(getattr(props, stg), getattr(props, loc), getattr(props, roo), getattr(props, 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
- #
- 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, 2) # 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_ZGW, loc, roo, props.FUN_DCK, props.DTY_SPP_SW1) # Tradfri 1 port Powerplug
- 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_MYA, loc, roo, props.FUN_ASB, props.DTY_MAS_xxx) # Audio status Bluetooth
- 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
- self.add(mqtt_client, props.STG_ZFW, 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_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, 6) # Tradfri Floorlamp
- self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1) # X-Mas Tree
- self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1) # X-Mas Star
- 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
|