From 95c4aa8ae9deb6e32985de9c2c8b99dffac1bd2e Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Mon, 6 Nov 2023 16:13:35 +0000 Subject: [PATCH] Issue #174 - regression following PR#150 --- .devcontainer/devcontainer.json | 2 +- .vscode/settings.json | 2 +- .../versatile_thermostat/base_thermostat.py | 11 ++++++++++- tests/test_power.py | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 35ce9e5..07cb694 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,7 +42,7 @@ // "terminal.integrated.shell.linux": "/bin/bash", "python.pythonPath": "/usr/bin/python3", "python.analysis.autoSearchPaths": true, - "pylint.lintOnChange": true, + "pylint.lintOnChange": false, "python.formatting.provider": "black", "python.formatting.blackPath": "/usr/local/py-utils/bin/black", "editor.formatOnPaste": false, diff --git a/.vscode/settings.json b/.vscode/settings.json index 0469a57..4d5aa44 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ "editor.defaultFormatter": "ms-python.black-formatter", "editor.formatOnSave": true }, - "pylint.lintOnChange": true, + "pylint.lintOnChange": false, "files.associations": { "*.yaml": "home-assistant" }, diff --git a/custom_components/versatile_thermostat/base_thermostat.py b/custom_components/versatile_thermostat/base_thermostat.py index 6b62fd9..41a1c9d 100644 --- a/custom_components/versatile_thermostat/base_thermostat.py +++ b/custom_components/versatile_thermostat/base_thermostat.py @@ -1827,7 +1827,15 @@ class BaseThermostat(ClimateEntity, RestoreEntity): self._device_power, ) - ret = (self._current_power + self._device_power) >= self._current_power_max + if self.is_over_climate: + power_consumption_max = self._device_power + else: + power_consumption_max = max( + self._device_power / self.nb_underlying_entities, + self._device_power * self._prop_algorithm.on_percent, + ) + + ret = (self._current_power + power_consumption_max) >= self._current_power_max if not self._overpowering_state and ret and self._hvac_mode != HVACMode.OFF: _LOGGER.warning( "%s - overpowering is detected. Heater preset will be set to 'power'", @@ -1845,6 +1853,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity): "current_power": self._current_power, "device_power": self._device_power, "current_power_max": self._current_power_max, + "current_power_consumption": power_consumption_max, }, ) diff --git a/tests/test_power.py b/tests/test_power.py index ae68b43..49046e1 100644 --- a/tests/test_power.py +++ b/tests/test_power.py @@ -4,8 +4,11 @@ from unittest.mock import patch, call from datetime import datetime, timedelta import logging -from custom_components.versatile_thermostat.thermostat_switch import ThermostatOverSwitch +from custom_components.versatile_thermostat.thermostat_switch import ( + ThermostatOverSwitch, +) from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import + logging.getLogger().setLevel(logging.DEBUG) @@ -185,6 +188,7 @@ async def test_power_management_hvac_on(hass: HomeAssistant, skip_hass_states_is "current_power": 50, "device_power": 100, "current_power_max": 149, + "current_power_consumption": 100.0, }, ), ],