From d4072ee8f8f24d8432ad9c24925960e638164217 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sun, 2 Feb 2025 18:41:10 +0000 Subject: [PATCH] Fix All tests ok --- .../versatile_thermostat/thermostat_switch.py | 3 ++- custom_components/versatile_thermostat/underlyings.py | 8 ++++++-- tests/test_safety.py | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_components/versatile_thermostat/thermostat_switch.py b/custom_components/versatile_thermostat/thermostat_switch.py index f007ea9..1c819b4 100644 --- a/custom_components/versatile_thermostat/thermostat_switch.py +++ b/custom_components/versatile_thermostat/thermostat_switch.py @@ -81,6 +81,8 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): max_on_percent=self._max_on_percent, ) + self._is_inversed = config_entry.get(CONF_INVERSE_SWITCH) is True + lst_switches = config_entry.get(CONF_UNDERLYING_LIST) self._lst_vswitch_on = config_entry.get(CONF_VSWITCH_ON_CMD_LIST, []) self._lst_vswitch_off = config_entry.get(CONF_VSWITCH_OFF_CMD_LIST, []) @@ -101,7 +103,6 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): ) ) - self._is_inversed = config_entry.get(CONF_INVERSE_SWITCH) is True self._should_relaunch_control_heating = False @overrides diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 6c6438b..fc88f25 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -280,7 +280,11 @@ class UnderlyingSwitch(UnderlyingEntity): # return (self.is_inversed and not real_state) or ( # not self.is_inversed and real_state # ) - return self._hass.states.is_state(self._entity_id, self._on_command.get("state")) + is_on = self._hass.states.is_state(self._entity_id, self._on_command.get("state")) + if self.is_inversed: + return not is_on + + return is_on async def _keep_alive_callback(self): """Keep alive: Turn on if already turned on, turn off if already turned off.""" @@ -329,7 +333,7 @@ class UnderlyingSwitch(UnderlyingEntity): raise ValueError(f"Invalid input format: {vswitch}. Must be conform to 'command[/argument[:value]]'") else: - command = SERVICE_TURN_ON if use_on and not self.is_inversed else SERVICE_TURN_OFF + command = SERVICE_TURN_ON if take_on else SERVICE_TURN_OFF if value is None: value = STATE_ON if take_on else STATE_OFF diff --git a/tests/test_safety.py b/tests/test_safety.py index 391a137..a85173c 100644 --- a/tests/test_safety.py +++ b/tests/test_safety.py @@ -624,6 +624,7 @@ async def test_security_over_climate( assert entity._saved_preset_mode == "none" +@pytest.mark.parametrize("expected_lingering_timers", [True]) async def test_migration_security_safety( hass: HomeAssistant, skip_hass_states_is_state,