From 67844d4ae823984fbeb792e2e65a61843a857af4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sun, 14 Jan 2024 23:02:23 +0000 Subject: [PATCH] FIX #341 - when window state change, open_valve_percent should be resend --- .devcontainer/configuration.yaml | 1 + .../versatile_thermostat/underlyings.py | 14 +++++++++----- tests/test_valve.py | 5 +---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.devcontainer/configuration.yaml b/.devcontainer/configuration.yaml index fbb23b2..52cc5e0 100644 --- a/.devcontainer/configuration.yaml +++ b/.devcontainer/configuration.yaml @@ -168,6 +168,7 @@ climate: target_sensor: input_number.fake_temperature_sensor1 recorder: + commit_interval: 1 include: domains: - input_boolean diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 5c10af9..f87d9ac 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -758,21 +758,25 @@ class UnderlyingValve(UnderlyingEntity): async def turn_off(self): """Turn heater toggleable device off.""" _LOGGER.debug("%s - Stopping underlying valve entity %s", self, self._entity_id) - self._percent_open = 0 - if self.is_device_active: + # Issue 341 + is_active = self.is_device_active + self._percent_open = self.cap_sent_value(0) + if is_active: await self.send_percent_open() async def turn_on(self): """Nothing to do for Valve because it cannot be turned off""" + self.set_valve_open_percent() async def set_hvac_mode(self, hvac_mode: HVACMode) -> bool: """Set the HVACmode. Returns true if something have change""" - if hvac_mode == HVACMode.OFF: - await self.turn_off() - if self._hvac_mode != hvac_mode: self._hvac_mode = hvac_mode + if hvac_mode == HVACMode.OFF: + await self.turn_off() + else: + await self.turn_on() return True else: return False diff --git a/tests/test_valve.py b/tests/test_valve.py index 47593fc..f9d23b3 100644 --- a/tests/test_valve.py +++ b/tests/test_valve.py @@ -321,9 +321,6 @@ async def test_over_valve_full_start( await try_condition(None) assert entity.hvac_mode is HVACMode.HEAT - assert ( - entity.hvac_action is HVACAction.OFF - or entity.hvac_action is HVACAction.IDLE - ) + assert entity.hvac_action is HVACAction.HEATING assert entity.target_temperature == 17.1 # eco assert entity.valve_open_percent == 10