2023-12-11 09:16:54 +01:00
|
|
|
#!/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,
|
2024-08-21 13:33:04 +02:00
|
|
|
props.DTY_MAM_THP: devices.my_ambient,
|
2023-12-11 09:16:54 +01:00
|
|
|
}.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
|
2024-08-20 11:47:08 +02:00
|
|
|
logger.debug("Added a device type=%s, topic=%s", dty, topic)
|
2023-12-11 09:16:54 +01:00
|
|
|
else:
|
|
|
|
dg = []
|
2023-12-25 07:24:41 +01:00
|
|
|
for i in range(1, num + 1):
|
2023-12-11 09:16:54 +01:00
|
|
|
device_topic = topic + '_%d' % i
|
|
|
|
dg.append(get_device(dty, mqtt_client, device_topic))
|
|
|
|
self[topic] = devices.group(*dg)
|
2024-08-20 11:47:08 +02:00
|
|
|
logger.debug("Added a devicegroup type=%s, topic=%s", dty, topic + '_<num>')
|
2023-12-11 09:16:54 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
"""
|
2023-12-12 12:38:15 +01:00
|
|
|
topic = topic_by_props(stg, loc, roo, fun)
|
2023-12-11 09:16:54 +01:00
|
|
|
return self[topic]
|
|
|
|
|
2023-12-12 12:38:15 +01:00
|
|
|
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))
|
|
|
|
|
2023-12-11 09:16:54 +01:00
|
|
|
|
|
|
|
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
|
2023-12-25 07:24:41 +01:00
|
|
|
self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 2) # Tradfri Main Light
|
2023-12-11 09:16:54 +01:00
|
|
|
|
|
|
|
# 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
|
2024-06-26 21:11:26 +02:00
|
|
|
self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DCK, props.DTY_SPP_SW1) # Tradfri 1 port Powerplug
|
2023-12-11 09:16:54 +01:00
|
|
|
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
|
2024-02-11 15:44:21 +01:00
|
|
|
self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASB, props.DTY_MAS_xxx) # Audio status Bluetooth
|
2023-12-11 09:16:54 +01:00
|
|
|
self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
|
2024-08-21 13:33:04 +02:00
|
|
|
self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_AMB, props.DTY_MAM_THP) # My Ambient information
|
2023-12-11 09:16:54 +01:00
|
|
|
|
|
|
|
# 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
|
2024-01-11 18:43:40 +01:00
|
|
|
self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
|
2023-12-11 09:16:54 +01:00
|
|
|
|
|
|
|
# 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
|
2024-08-21 13:33:04 +02:00
|
|
|
self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_AMB, props.DTY_MAM_THP) # My Ambient information
|
2023-12-11 09:16:54 +01:00
|
|
|
|
|
|
|
# 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
|
2023-12-25 07:24:41 +01:00
|
|
|
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
|
2023-12-11 09:16:54 +01:00
|
|
|
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
|