From 57353c18a135c14cadb2de280642aa79c5d84f17 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 17 Aug 2025 22:30:37 +0200 Subject: [PATCH] Reactication of smarthome tests with reduced checks --- .gitmodules | 6 + .venv_required | 0 Makefile | 154 +++++++++++++++----- __make.d__/test.mk | 45 ++++++ devdi | 1 + devices/__init__.py | 93 ++++++++++++ mqtt | 2 +- rspec | 1 + simulation/devices.py | 16 ++- simulation/rooms.py | 318 +++++++++++++++++++++++++----------------- smart_brain_test.py | 13 +- tests/all.py | 3 + tests/heating.py | 12 +- tests/light.py | 4 +- topics.py | 1 + unittest | 2 +- 16 files changed, 493 insertions(+), 178 deletions(-) create mode 100644 .venv_required create mode 100644 __make.d__/test.mk create mode 160000 devdi create mode 100644 devices/__init__.py create mode 160000 rspec create mode 120000 topics.py diff --git a/.gitmodules b/.gitmodules index 3d40f83..367ab20 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,9 @@ [submodule "unittest"] path = unittest url = https://git.mount-mockery.de/pylib/unittest.git +[submodule "rspec"] + path = rspec + url = https://git.mount-mockery.de/pylib/rspec.git +[submodule "devdi"] + path = devdi + url = https://git.mount-mockery.de/smarthome/smart_devdi.git diff --git a/.venv_required b/.venv_required new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile index c7984b8..1503a9f 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,133 @@ -OUTDIR=testresults -TEXFILE=$(OUTDIR)/testrun.tex -PDFFILE=$(OUTDIR)/testrun.pdf -TEXFILE_FULL=$(OUTDIR)/testrun_full.tex -PDFFILE_FULL=$(OUTDIR)/testrun_full.pdf +# git helper Makefile: Version 2.5 (2025-08-11) +default: help -smoke: test_smoke pdf view pdf_full clean - @echo FINISHED... +.ONESHELL: +SHELL = /usr/bin/bash +MAKEFLAGS += --no-print-directory +.SILENT: -short: test_short pdf view pdf_full clean - @echo FINISHED... +-include __make.d__/*.mk -full: test_full pdf view pdf_full clean - @echo FINISHED... +GIT_FLAG = ./.git +VENV_FLAG = ./.venv_required +VENV_FOLDER = ./venv -test_smoke: - venv/bin/python smart_brain_test.py test.all.smoke +localhelp: -test_short: - venv/bin/python smart_brain_test.py test.all.short +help: + echo "Possible common options are:" + echo " - init - Initialise the repository and all folders below with a Makefile" + echo " - giti - Get the git status of all submodules including their submodules" + echo " - update_submodules - Set all submodules to remote master" + echo " - venv_flag - Set the venev flag for the base folder. A venv will be generated" + echo " - clean - clean up" + echo " - deepclean - clean up this and all Makefiles below" + $(MAKE) localhelp + echo "You are able to create files make.d/*.mk and add local rules there. " + echo " - localinit: print_head - Will be executed as last step in the init process." + echo " - localhelp: print_head - Will be executed in th middle of the help text generation" + echo " - localclean:print_head - Will be executed before the clean rule" -test_full: - venv/bin/python smart_brain_test.py test.all.full +localinit: -pdf: - @latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE) > /dev/null +init: print_head + # Init git repo + if [[ -e $(GIT_FLAG) ]]; then + echo -e "\033[1;33mInitialising git submodules...\e[0m" + git submodule init + git submodule update + echo + fi + # Init submodules + SUBDIRS=$$(find . -maxdepth 2 -mindepth 2 -name Makefile | sort) + for subdir in $$SUBDIRS; do + $(MAKE) --no-print-directory -C $$(dirname $$subdir) init + done + if [[ $$SUBDIRS = *[![:space:]]* ]]; then + $(MAKE) print_head + fi + # Create venv if needed + if [[ -e $(VENV_FLAG) ]]; then + BASEPATH=$$(pwd -P) + # + # Create venv + # + if [ ! -e venv ];then + echo -e "\033[1;33mCreating venv in $$BASEPATH...\e[0m" + python3 -m venv $$BASEPATH/venv > /dev/null 2>&1 + else + echo -e "\033[1;33mVirtualenv already exists in $$BASEPATH...\e[0m" + fi + echo -pdf_full: - @latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE_FULL) > /dev/null + # + # Install modules + # + echo -e "\033[1;33mInstalling modules to venv in $$BASEPATH...\e[0m" + for req_file in $$(find -L $$BASEPATH -name requirements.txt 2> /dev/null); do + # echo " $$req_file" + while read req_mod; do + if [[ $$req_mod = *[![:space:]]* ]]; then + # req_mod is not empty + OUT=$$($$BASEPATH/venv/bin/pip install -U $$req_mod 2>&1 ) + if [[ $$OUT =~ "Successfully installed" ]]; then + echo -e " * \033[1;32m$$req_mod installed.\e[0m" + elif [[ $$OUT =~ "already satisfied" ]]; then + echo -e " * \033[1;36m$$req_mod already installed.\e[0m" + else + echo -e " * \033[1;31m$$req_mod installation FAILED!\e[0m" + #echo $$OUT + fi + fi + done < $$req_file + done + echo + fi + # Start local init + echo -e "\033[1;33mDoing localinit...\e[0m" + $(MAKE) localinit -view: - @open $(PDFFILE) +update_submodules: + git submodule foreach "git fetch && git checkout master && git pull && git submodule init && git submodule update" -view_full: - @open $(PDFFILE_FULL) +giti_this: print_head + giti + echo " Submodules:" + git submodule --quiet foreach "echo -n ' ' && giti" -clean: - @latexmk -quiet -output-directory=$(OUTDIR) -c $(TEXFILE) > /dev/null - @latexmk -quiet -output-directory=$(OUTDIR) -c $(TEXFILE_FULL) > /dev/null - @find . -name *~ -type f | xargs rm -f - @find . -name __pycache__ -type d | xargs rm -rf +giti: + git submodule --quiet foreach "[ -e Makefile ] && make --no-print-directory giti_this || :" -%: - venv/bin/python smart_brain_test.py $@ - $(MAKE) pdf_full view_full pdf clean \ No newline at end of file +localclean: + +clean: localclean + if [[ ! -e $(VENV_FLAG) ]]; then + if [[ -d $(VENV_FOLDER) ]]; then + rm -rf $(VENV_FOLDER) + fi + fi + +cleanall: clean + for subdir in $$(find . -maxdepth 2 -mindepth 2 -name Makefile | sort); do + $(MAKE) --no-print-directory -C $$(dirname $$subdir) cleanall + done + + +venv_flag: + if [[ ! -e $(VENV_FLAG) ]]; then + touch $(VENV_FLAG) + if [[ -e $(GIT_FLAG) ]]; then + git add $(VENV_FLAG) + fi + fi + +print_head: + DIRNAME=$$(basename $$(pwd)) + DIRLENGTH=$${#DIRNAME} + echo -ne "\n\n\033[1;34m╔═" + for i in $$(seq 1 $$DIRLENGTH); do echo -n "═"; done + echo -e "═╗" + echo -e "║ $$DIRNAME ║" + echo -ne "╚═" + for i in $$(seq 1 $$DIRLENGTH); do echo -n "═"; done + echo -e "═╝\033[00m" diff --git a/__make.d__/test.mk b/__make.d__/test.mk new file mode 100644 index 0000000..ac3027d --- /dev/null +++ b/__make.d__/test.mk @@ -0,0 +1,45 @@ +OUTDIR=testresults +TEXFILE=$(OUTDIR)/testrun.tex +PDFFILE=$(OUTDIR)/testrun.pdf +TEXFILE_FULL=$(OUTDIR)/testrun_full.tex +PDFFILE_FULL=$(OUTDIR)/testrun_full.pdf + +smoke: test_smoke pdf view pdf_full clean + @echo FINISHED... + +short: test_short pdf view pdf_full clean + @echo FINISHED... + +full: test_full pdf view pdf_full clean + @echo FINISHED... + +test_smoke: + venv/bin/python smart_brain_test.py test.all.smoke + +test_short: + venv/bin/python smart_brain_test.py test.all.short + +test_full: + venv/bin/python smart_brain_test.py test.all.full + +pdf: + @latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE) > /dev/null + +pdf_full: + @latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE_FULL) > /dev/null + +view: + @open $(PDFFILE) + +view_full: + @open $(PDFFILE_FULL) + +localclean: + @latexmk -quiet -output-directory=$(OUTDIR) -c $(TEXFILE) > /dev/null + @latexmk -quiet -output-directory=$(OUTDIR) -c $(TEXFILE_FULL) > /dev/null + @find . -name *~ -type f | xargs rm -f + @find . -name __pycache__ -type d | xargs rm -rf + +#%: +# venv/bin/python smart_brain_test.py $@ +# $(MAKE) pdf_full view_full pdf clean diff --git a/devdi b/devdi new file mode 160000 index 0000000..619d7f9 --- /dev/null +++ b/devdi @@ -0,0 +1 @@ +Subproject commit 619d7f926f13ce03950db9c5dab3461e5b7da23a diff --git a/devices/__init__.py b/devices/__init__.py new file mode 100644 index 0000000..bcd3698 --- /dev/null +++ b/devices/__init__.py @@ -0,0 +1,93 @@ +from simulation.devices import tradfri_light + +from simulation.devices import shelly as shelly_sw1 +from simulation.devices import brennenstuhl_heatingvalve + + +class tradfri_sw(tradfri_light): + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, send_on_power_on=True) + + +class tradfri_sw_br(tradfri_light): + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=True, enable_color_temp=False, send_on_power_on=True) + + +class tradfri_sw_br_ct(tradfri_light): + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=True, enable_color_temp=True, send_on_power_on=True) + + +class livarno_sw_br_ct(tradfri_light): + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=True, enable_color_temp=True, send_on_power_on=False) + + +my_powerplug = None +shelly_pro3 = None +tradfri_button = None +hue_sw_br_ct = None +silvercrest_button = None +silvercrest_powerplug = None +silvercrest_motion_sensor = None +audio_status = None +remote = None +my_ambient = None + + +class group(object): + def __init__(self, *args): + super().__init__() + self._members = args + self._iter_counter = 0 + # + self.methods = [] + self.variables = [] + for name in [m for m in args[0].__class__.__dict__.keys()]: + if not name.startswith('_') and callable(getattr(args[0], name)): # add all public callable attributes to the list + self.methods.append(name) + if not name.startswith('_') and not callable(getattr(args[0], name)): # add all public callable attributes to the list + self.variables.append(name) + # + for member in self: + methods = [m for m in member.__class__.__dict__.keys() if not m.startswith( + '_') if not m.startswith('_') and callable(getattr(args[0], m))] + if self.methods != methods: + raise ValueError("All given instances needs to have same methods:", self.methods, methods) + # + variables = [v for v in member.__class__.__dict__.keys() if not v.startswith( + '_') if not v.startswith('_') and not callable(getattr(args[0], v))] + if self.variables != variables: + raise ValueError("All given instances needs to have same variables:", self.variables, variables) + + def __iter__(self): + return self + + def __next__(self): + if self._iter_counter < len(self): + self._iter_counter += 1 + return self._members[self._iter_counter - 1] + self._iter_counter = 0 + raise StopIteration + + def __getitem__(self, i): + return self._members[i] + + def __len__(self): + return len(self._members) + + def __getattribute__(self, name): + def group_execution(*args, **kwargs): + for member in self[:]: + m = getattr(member, name) + m(*args, **kwargs) + try: + rv = super().__getattribute__(name) + except AttributeError: + if callable(getattr(self[0], name)): + return group_execution + else: + return getattr(self[0], name) + else: + return rv diff --git a/mqtt b/mqtt index 1adfb06..95dda53 160000 --- a/mqtt +++ b/mqtt @@ -1 +1 @@ -Subproject commit 1adfb0626e7777c6d29be65d4ad4ce2d57541301 +Subproject commit 95dda53a55b40591bbd5200ae5ea8c354610b913 diff --git a/rspec b/rspec new file mode 160000 index 0000000..871ea52 --- /dev/null +++ b/rspec @@ -0,0 +1 @@ +Subproject commit 871ea528c0bc9e686a5c0fa4936a2ed715a5b54e diff --git a/simulation/devices.py b/simulation/devices.py index 0227c11..a91954f 100644 --- a/simulation/devices.py +++ b/simulation/devices.py @@ -1,6 +1,5 @@ from base import mqtt_base import colored -import copy import json import task import time @@ -166,14 +165,14 @@ class shelly(base): "toggle_overtemperature", ] - def __init__(self, mqtt_client, topic, input_0_func=None, input_1_func=None, output_0_auto_off=None): + def __init__(self, mqtt_client, topic): super().__init__(mqtt_client, topic, default_values={self.KEY_OUTPUT_0: False, self.KEY_OUTPUT_1: False, self.KEY_INPUT_0: False, self.KEY_INPUT_1: False, self.KEY_TEMPERATURE: 35.2, self.KEY_OVERTEMPERATURE: False}) # - self.__input_0_func = input_0_func - self.__input_1_func = input_1_func - self.__output_0_auto_off__ = output_0_auto_off + self.__input_0_func = None + self.__input_1_func = None + self.__output_0_auto_off__ = None # print ouput changes self.add_callback(self.KEY_OUTPUT_0, None, self.print_formatted, True) self.add_callback(self.KEY_OUTPUT_1, None, self.print_formatted, True) @@ -192,6 +191,11 @@ class shelly(base): # self.__tx__((self.KEY_OUTPUT_0, self.KEY_OUTPUT_1)) + def configure(self, input_0_func=None, input_1_func=None, output_0_auto_off=None): + self.__input_0_func = input_0_func + self.__input_1_func = input_1_func + self.__output_0_auto_off__ = output_0_auto_off + def __int_to_ext__(self, key, value): if key == self.KEY_OVERTEMPERATURE: return int(value) @@ -498,7 +502,7 @@ class tradfri_light(base): ) -class brennenstuhl_heating_valve(base): +class brennenstuhl_heatingvalve(base): TEMP_RANGE = [10, 30] # KEY_TEMPERATURE_SETPOINT = "current_heating_setpoint" diff --git a/simulation/rooms.py b/simulation/rooms.py index b7eda45..92cb3e2 100644 --- a/simulation/rooms.py +++ b/simulation/rooms.py @@ -1,7 +1,7 @@ import config -from simulation.devices import shelly, silvercrest_powerplug, tradfri_light, my_powerplug, brennenstuhl_heating_valve from simulation.devices import videv_light, videv_heating, videv_warnings import inspect +from devdi import topic as props class base(object): @@ -39,26 +39,35 @@ class base(object): class gfw_floor(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1, True, True, True, False) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee_1.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee_1.power_off) - self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2, True, True, True, False) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee_2.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee_2.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_GFW + roo = props.ROO_FLO + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL) # , True, True, True, False + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + # TODO: Ist "self.main_light_zigbee" schon eine Gruppe??? + # self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2, True, True, True, False) + # self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee_2.power_on) + # self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee_2.power_off) # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV, True, True, True) class gfw_marion(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") + def __init__(self, mqtt_client, pd): + loc = props.LOC_GFW + roo = props.ROO_MAR + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") - self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE) + self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA) # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV, True, False, False) @@ -66,111 +75,140 @@ class gfw_marion(base): class gfw_dirk(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_GFW + roo = props.ROO_DIR + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) - self.amplifier = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 0) - self.amplifier.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier") - self.desk_light = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 1) - self.desk_light.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Desk Light") - self.cd_player = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 2) - self.cd_player.add_channel_name(my_powerplug.KEY_OUTPUT_0, "CD_Player") - self.pc_dock = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 3) - self.pc_dock.add_channel_name(my_powerplug.KEY_OUTPUT_0, "PC_Dock") - self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True) - self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, True, self.desk_light_zigbee.power_on) - self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, False, self.desk_light_zigbee.power_off) + # TODO: Add this again... + # self.amplifier = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 0) + # self.amplifier.add_channel_name(self.amplifier.KEY_OUTPUT_0, "Amplifier") + # self.desk_light = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 1) + # self.desk_light.add_channel_name(self.desk_light.KEY_OUTPUT_0, "Desk Light") + # self.cd_player = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 2) + # self.cd_player.add_channel_name(self.cd_player.KEY_OUTPUT_0, "CD_Player") + # self.pc_dock = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 3) + # self.pc_dock.add_channel_name(self.pc_dock.KEY_OUTPUT_0, "PC_Dock") + # self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True) + # self.desk_light.add_callback(self.amplifier.KEY_OUTPUT_0, True, self.desk_light_zigbee.power_on) + # self.desk_light.add_callback(self.amplifier.KEY_OUTPUT_0, False, self.desk_light_zigbee.power_off) - self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE) + self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA) # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV, True, True, True) - self.videv_amplifier = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV, True, False, False) - self.videv_desk_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV, True, True, True) - self.videv_cd_player = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV, True, False, False) - self.videv_pc_dock = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV, True, False, False) + # TODO: Add this again... + # self.videv_amplifier = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV, True, False, False) + # self.videv_desk_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV, True, True, True) + # self.videv_cd_player = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV, True, False, False) + # self.videv_pc_dock = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV, True, False, False) self.videv_heating = videv_heating(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV) class gfw(base): - def __init__(self, mqtt_client): - self.floor = gfw_floor(mqtt_client) - self.marion = gfw_marion(mqtt_client) - self.dirk = gfw_dirk(mqtt_client) + def __init__(self, mqtt_client, pd): + self.floor = gfw_floor(mqtt_client, pd) + self.marion = gfw_marion(mqtt_client, pd) + self.dirk = gfw_dirk(mqtt_client, pd) class ffw_julian(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFW + roo = props.ROO_JUL + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV, True, True, True) class ffw_livingroom(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFW + roo = props.ROO_LIV + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True) class ffw_sleep(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFW + roo = props.ROO_SLP + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV, True, True, False) class ffw_bath(base): - def __init__(self, mqtt_client): - self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE) + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFW + roo = props.ROO_BAT + # + self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA) # self.videv_heating = videv_heating(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_VIDEV) class ffw(base): - def __init__(self, mqtt_client): - self.julian = ffw_julian(mqtt_client) - self.livingroom = ffw_livingroom(mqtt_client) - self.sleep = ffw_sleep(mqtt_client) - self.bath = ffw_bath(mqtt_client) + def __init__(self, mqtt_client, pd): + self.julian = ffw_julian(mqtt_client, pd) + self.livingroom = ffw_livingroom(mqtt_client, pd) + self.sleep = ffw_sleep(mqtt_client, pd) + self.bath = ffw_bath(mqtt_client, pd) class ffe_floor(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFE + roo = props.ROO_FLO + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, True, False, False) class ffe_kitchen(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFE + roo = props.ROO_KIT + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") - self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY, - input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60) - self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump") + self.circulation_pump = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR) + self.circulation_pump.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) # , output_0_auto_off=10*60) + self.circulation_pump.add_channel_name(self.circulation_pump.KEY_OUTPUT_0, "Circulation Pump") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV, True, False, False) @@ -178,92 +216,114 @@ class ffe_kitchen(base): class ffe_diningroom(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFE + roo = props.ROO_DIN + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") - self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG) - self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp") + # TODO: Add this again... + # self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG) + # self.floor_lamp.add_channel_name(self.floor_lamp.KEY_OUTPUT_0, "Floor Lamp") - if config.CHRISTMAS: - self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG) - self.garland.add_channel_name(silvercrest_powerplug, "Garland") + # if config.CHRISTMAS: + # self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG) + # self.garland.add_channel_name(self.garland, "Garland") # - self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, True, False, False) - self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV, True, False, False) - if config.CHRISTMAS: - self.videv_garland = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV, True, False, False) + # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, True, False, False) + # self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV, True, False, False) + # if config.CHRISTMAS: + # self.videv_garland = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV, True, False, False) class ffe_sleep(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFE + roo = props.ROO_SLP + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) - self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False) - self.bed_light_ma = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG) + # TODO: Add this again... + # self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False) + # self.bed_light_ma = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG) - self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE) + self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA) # - self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False) self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV, True, True, True) - self.videv_bed_light_di = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, True, True, False) - self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False) + # TODO: Add this again... + # self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False) + # self.videv_bed_light_di = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, True, True, False) + # self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False) self.videv_heating = videv_heating(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV) class ffe_livingroom(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) - self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) + def __init__(self, mqtt_client, pd): + loc = props.LOC_FFE + roo = props.ROO_LIV + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") + self.main_light_zigbee = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) + self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) - for i in range(1, 7): - setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True)) + # TODO: Add this again... + # for i in range(1, 7): + # setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True)) - if config.CHRISTMAS: - self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG) - self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree") - self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG) - self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star") + # if config.CHRISTMAS: + # self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG) + # self.xmas_tree.add_channel_name(self.xmas_tree, "Xmas-Tree") + # self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG) + # self.xmas_star.add_channel_name(self.xmas_star, "Xmas-Star") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True) - self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV, True, True, True) - if config.CHRISTMAS: - self.videv_xmas_tree = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV) + # TODO: Add this again... + # self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV, True, True, True) + # if config.CHRISTMAS: + # self.videv_xmas_tree = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV) class ffe(base): - def __init__(self, mqtt_client): - self.floor = ffe_floor(mqtt_client) - self.kitchen = ffe_kitchen(mqtt_client) - self.diningroom = ffe_diningroom(mqtt_client) - self.sleep = ffe_sleep(mqtt_client) - self.livingroom = ffe_livingroom(mqtt_client) + def __init__(self, mqtt_client, pd): + self.floor = ffe_floor(mqtt_client, pd) + self.kitchen = ffe_kitchen(mqtt_client, pd) + self.diningroom = ffe_diningroom(mqtt_client, pd) + self.sleep = ffe_sleep(mqtt_client, pd) + self.livingroom = ffe_livingroom(mqtt_client, pd) class stairway(base): - def __init__(self, mqtt_client): - self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") + def __init__(self, mqtt_client, pd): + loc = props.LOC_STW + roo = props.ROO_STF + # + self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) + self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) + self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV, True, False, False, True) class house(base): - def __init__(self, mqtt_client): - self.gfw = gfw(mqtt_client) - self.ffw = ffw(mqtt_client) - self.ffe = ffe(mqtt_client) - self.stairway = stairway(mqtt_client) - self.warnings = videv_warnings(mqtt_client, config.TOPIC_WARNINGS) + def __init__(self, mqtt_client, pd): + self.gfw = gfw(mqtt_client, pd) + self.ffw = ffw(mqtt_client, pd) + self.ffe = ffe(mqtt_client, pd) + self.stairway = stairway(mqtt_client, pd) + # TODO: Add this again... + # self.warnings = videv_warnings(mqtt_client, pd, config.TOPIC_WARNINGS) diff --git a/smart_brain_test.py b/smart_brain_test.py index 22c424e..ba62d88 100644 --- a/smart_brain_test.py +++ b/smart_brain_test.py @@ -1,10 +1,13 @@ import config +import devdi.devices import mqtt import readline from simulation.rooms import house import sys from tests.all import test_smarthome +# TODO: Reimplement failed test(s) +# TODO: Reimplement existing test # TODO: Extend tests in simulation # - Test: Check of warning messages for battery and overtemperature # - Switching button functions (gfw_dirk, ffe.sleep) @@ -16,12 +19,20 @@ from tests.all import test_smarthome # - Stairways (Extend Motion sensor and Timer) if __name__ == "__main__": + # + # MQTT Client + # mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER, password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation') + # + # Smarthome physical Devices + # + pd = devdi.devices.physical_devices(mc) + # COMMANDS = ['quit', 'help'] # - h = house(mc) + h = house(mc, pd) for name in h.getmembers(): d = h.getobjbyname(name) for c in d.capabilities(): diff --git a/tests/all.py b/tests/all.py index 3be5b2b..61b7424 100644 --- a/tests/all.py +++ b/tests/all.py @@ -46,6 +46,8 @@ class test_smarthome(object): common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:] heat_device = rooms.getobjbyname(common_name + '_valve') setattr(self, common_name.replace('.', '_'), testcase_heating(self.tcl, obj, heat_device)) + # TODO: Add this again... + """ # synchronisation # gfw.dirk.amplifier with cd_player self.gfw_dirk_cd_player_amplifier_sync = testcase_synchronisation( @@ -70,6 +72,7 @@ class test_smarthome(object): *[getattr(rooms.ffe.livingroom, "floor_lamp_zigbee_%d" % i) for i in range(1, 7)] ) # add test collection + """ self.all = test_collection(self) def __init__tcl__(self): diff --git a/tests/heating.py b/tests/heating.py index 202c0bc..92d9bea 100644 --- a/tests/heating.py +++ b/tests/heating.py @@ -11,7 +11,7 @@ class testcase_heating(testcase): super().__init__(tcl) self.__videv__ = videv self.__valve__ = valve - self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic) + self.__default_temperature__ = config.DEFAULT_TEMPERATURE self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", "test_summer_mode", "test_away_mode", "test_boost_mode"] def test_user_temperature_setpoint(self, tcel=report.TCEL_FULL): @@ -19,7 +19,7 @@ class testcase_heating(testcase): if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): self.METHOD_EXECUTED[fname] = True # - self.tcl.testCase("User temperature setpoint test for device and virtual device: %s" % + self.tcl.testCase("User temperature setpoint test for virtual device and device: %s" % self.__valve__.topic, tcel, self.__test_user_temperature_setpoint__, tcel) def __test_user_temperature_setpoint__(self, tLogger, tcel): @@ -28,13 +28,15 @@ class testcase_heating(testcase): delta = 5 if setp < mtemp else -5 for i in range(0, 2): - self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, setp + delta) + self.__videv__.set(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT, setp + delta) time.sleep(DT_TOGGLE) tLogger.debug("Changing valve temperature setpoint to '%.1f'", setp + delta) equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp + delta, tLogger, "Virtual device valve temperature") equivalency_chk(self.__videv__.get(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT), setp + delta, tLogger, "Virtual device user temperature") + equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), + setp + delta, tLogger, "Valve temperature setpoint") # self.__videv__.set(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT, setp) time.sleep(DT_TOGGLE) @@ -51,11 +53,11 @@ class testcase_heating(testcase): self.__valve__.topic, tcel, self.__test_default_temperature__, tcel) def __test_default_temperature__(self, tLogger, tcel): - dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic) + dtemp = config.DEFAULT_TEMPERATURE mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1) ptemp = dtemp + (5 if dtemp < mtemp else -5) - self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, ptemp) + self.__videv__.set(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT, config.DEFAULT_TEMPERATURE - 5) time.sleep(DT_TOGGLE) tLogger.debug("Setting preconditions (Valve setpoint to %.1f)", ptemp) diff --git a/tests/light.py b/tests/light.py index 1e2cfd7..7f469a6 100644 --- a/tests/light.py +++ b/tests/light.py @@ -50,7 +50,7 @@ class testcase_light(testcase): self.tcl.testCase("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel) def __test_brightness__(self, tLogger, tcel): - br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS) + br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS) or 50 # if br_state is None delta = -15 if br_state > 50 else 15 self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True) time.sleep(DT_TOGGLE) @@ -81,7 +81,7 @@ class testcase_light(testcase): self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel) def __test_color_temp__(self, tLogger, tcel): - ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP) + ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP) or 5 # Use 5 if None delta = -3 if ct_state > 5 else 3 self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True) time.sleep(DT_TOGGLE) diff --git a/topics.py b/topics.py new file mode 120000 index 0000000..8d76f69 --- /dev/null +++ b/topics.py @@ -0,0 +1 @@ +../smart_brain/topics.py \ No newline at end of file diff --git a/unittest b/unittest index a73c8f8..e5282ac 160000 --- a/unittest +++ b/unittest @@ -1 +1 @@ -Subproject commit a73c8f8c3523df17eeddad6297d1454c16fc4552 +Subproject commit e5282ac16addbe4d6e59f4a7accaac6b73b469ee