2023-10-22 20:11:31 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from devdi import props
2023-10-29 11:29:59 +01:00
from devices import group
2023-10-22 20:11:31 +02:00
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 )
2023-10-29 11:29:59 +01:00
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 ) :
2023-10-22 20:11:31 +02:00
loc = props . LOC_GFW
# MARION
roo = props . ROO_MAR
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# FLOOR
roo = props . ROO_FLO
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# DIRK
roo = props . ROO_DIR
#
2023-10-29 11:29:59 +01:00
# 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 ) :
2023-10-22 20:11:31 +02:00
loc = props . LOC_FFW
# JULIAN
roo = props . ROO_JUL
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# BATH
roo = props . ROO_BAT
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# LIVINGROOM
roo = props . ROO_LIV
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# SLEEP
roo = props . ROO_SLP
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
2023-10-29 11:29:59 +01:00
def __init_ffe__ ( self , mqtt_client ) :
2023-10-22 20:11:31 +02:00
loc = props . LOC_FFE
# FLOOR
roo = props . ROO_FLO
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# KITCHEN
roo = props . ROO_KIT
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# DININGROOM
roo = props . ROO_DIN
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# SLEEP
roo = props . ROO_SLP
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
# LIVINGROOM
roo = props . ROO_LIV
#
2023-10-29 11:29:59 +01:00
# 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 ) :
2023-10-22 20:11:31 +02:00
loc = props . LOC_STW
# FLOOR
#
2023-10-29 11:29:59 +01:00
# 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
2023-10-22 20:11:31 +02:00
2023-10-29 11:29:59 +01:00
def add ( self , mqtt_client , stg , loc , roo , fun , dty , num = None , ot = None ) :
2023-10-22 20:11:31 +02:00
""" 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
"""
2023-10-29 11:29:59 +01:00
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
2023-10-22 20:11:31 +02:00
else :
2023-10-29 11:29:59 +01:00
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 )
2023-10-22 20:11:31 +02:00
2023-10-29 11:29:59 +01:00
def get ( self , stg , loc , roo , fun ) :
2023-10-22 20:11:31 +02:00
""" 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
"""
2023-10-29 11:29:59 +01:00
topic = self . __topic__ ( stg , loc , roo , fun )
return self [ topic ]
2023-10-22 20:11:31 +02:00
2023-10-29 11:29:59 +01:00
def __topic__ ( self , stg , loc , roo , fun ) :
2023-10-22 20:11:31 +02:00
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 )
2023-10-29 11:29:59 +01:00
] )
2023-10-22 20:11:31 +02:00
else :
return ' / ' . join ( [
props . stg_repr ( stg ) ,
props . loc_repr ( loc ) ,
props . roo_repr ( roo ) ,
props . fun_repr ( fun )
2023-10-29 11:29:59 +01:00
] )