190 lines
8.9 KiB
Python
190 lines
8.9 KiB
Python
|
|
||
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
from devdi import props
|
||
|
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)
|
||
|
#######
|
||
|
# GFW #
|
||
|
#######
|
||
|
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, 1) # Tradfri 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_CTR, 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
|
||
|
|
||
|
|
||
|
#######
|
||
|
# FFW #
|
||
|
#######
|
||
|
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
|
||
|
|
||
|
#######
|
||
|
# FFE #
|
||
|
#######
|
||
|
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_CTR, 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
|
||
|
for i in range(1, 7):
|
||
|
self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, i) # 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
|
||
|
|
||
|
#######
|
||
|
# STW #
|
||
|
#######
|
||
|
loc = props.LOC_STW
|
||
|
# FLOOR
|
||
|
roo = props.ROO_STW
|
||
|
#
|
||
|
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_MSE, props.DTY_SMS_xxx, 1) # Motion Sensor Ground Floor
|
||
|
self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MSE, props.DTY_SMS_xxx, 2) # Motion Sensor Ground Floor
|
||
|
|
||
|
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
|
||
|
"""
|
||
|
topic = self.__topic__(stg, loc, roo, fun, num)
|
||
|
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:
|
||
|
self[topic] = dev_class(mqtt_client, topic)
|
||
|
|
||
|
def get(self, stg, loc, roo, fun, num=None):
|
||
|
"""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
|
||
|
"""
|
||
|
return self[self.__topic__(stg, loc, roo, fun, num)]
|
||
|
|
||
|
def __topic__(self, stg, loc, roo, fun, num):
|
||
|
if num is None:
|
||
|
postfix = ""
|
||
|
else:
|
||
|
postfix = "_%d" % num
|
||
|
#
|
||
|
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)
|
||
|
]) + postfix
|
||
|
else:
|
||
|
return '/'.join([
|
||
|
props.stg_repr(stg),
|
||
|
props.loc_repr(loc),
|
||
|
props.roo_repr(roo),
|
||
|
props.fun_repr(fun)
|
||
|
]) + postfix
|