home_emulation/home_emulation.py

101 lines
2.9 KiB
Python
Raw Normal View History

2023-08-03 20:43:41 +02:00
import config
import devdi
import devdi.props as props
2023-08-03 20:43:41 +02:00
import logging
import mqtt
import os
2023-08-03 20:43:41 +02:00
import report
import time
2023-10-29 15:10:52 +01:00
# TODO: Implementation of missing devices in devices/__init__.py
# TODO: Implementation of interface for external device stimulation
logger = logging.getLogger(config.APP_NAME)
2023-08-03 20:43:41 +02:00
if __name__ == "__main__":
#
# Logging
#
if config.DEBUG:
report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
else:
report.stdoutLoggingConfigure(((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
#
# MQTT Client
#
2023-08-03 20:43:41 +02:00
mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
password=config.MQTT_PASSWORD, name=config.APP_NAME)
#
2023-10-29 15:10:52 +01:00
# Smarthome physical Devices
#
2023-10-29 15:10:52 +01:00
pd = devdi.physical_devices(mc)
#
# Smart Home Functionality
#
#######
# GFW #
#######
loc = props.LOC_GFW
# DIRK
roo = props.ROO_DIR
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
sml = pd.get(props.STG_MYA, loc, roo, props.FUN_MPP)
tml = pd.get(props.STG_ZGW, loc, roo, props.FUN_DEL)
sml.register_power_on_instance(tml, sml.PROPERTIES[1])
# FLOOR
roo = props.ROO_FLO
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
#######
# FFW #
#######
loc = props.LOC_FFW
# JULIAN
roo = props.ROO_JUL
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
# LIVINGROOM
roo = props.ROO_LIV
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
# SLEEP
roo = props.ROO_SLP
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
#######
# FFE #
#######
loc = props.LOC_FFE
# KITCHEN
roo = props.ROO_KIT
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR)
sml.auto_off(600)
# LIVINGROOM
roo = props.ROO_LIV
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
# SLEEP
roo = props.ROO_SLP
2023-10-29 15:10:52 +01:00
sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
tml = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
sml.register_power_on_instance(tml, sml.PROPERTIES[0])
2023-08-03 20:43:41 +02:00
while (True):
time.sleep(1)