From 744bfdb9fe1fd68d302526cd8661ec2a78b807f9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sat, 9 Mar 2024 15:06:58 +0000 Subject: [PATCH] Validation tests ok --- custom_components/versatile_thermostat/base_thermostat.py | 5 +++-- custom_components/versatile_thermostat/climate.py | 3 --- custom_components/versatile_thermostat/number.py | 8 ++++++-- tests/test_temp_number.py | 8 ++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/custom_components/versatile_thermostat/base_thermostat.py b/custom_components/versatile_thermostat/base_thermostat.py index ac3bc57..02fbd42 100644 --- a/custom_components/versatile_thermostat/base_thermostat.py +++ b/custom_components/versatile_thermostat/base_thermostat.py @@ -772,8 +772,6 @@ class BaseThermostat(ClimateEntity, RestoreEntity): self._hvac_mode or HVACMode.OFF, ) - self.hass.create_task(self._check_initial_state()) - self.reset_last_change_time() await self.get_my_previous_state() @@ -2696,3 +2694,6 @@ class BaseThermostat(ClimateEntity, RestoreEntity): # Re-applicate the last preset if any to take change into account if self._attr_preset_mode: await self._async_set_preset_mode_internal(self._attr_preset_mode, True) + + self.hass.create_task(self._check_initial_state()) + diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index 8d5f0a0..aa548f5 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -45,9 +45,6 @@ from .thermostat_valve import ThermostatOverValve _LOGGER = logging.getLogger(__name__) -# _LOGGER.setLevel(logging.DEBUG) - - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, diff --git a/custom_components/versatile_thermostat/number.py b/custom_components/versatile_thermostat/number.py index 91febce..fe7f0a1 100644 --- a/custom_components/versatile_thermostat/number.py +++ b/custom_components/versatile_thermostat/number.py @@ -318,7 +318,7 @@ class CentralConfigTemperatureNumber( pass @overrides - def set_native_value(self, value: float) -> None: + async def async_set_native_value(self, value: float) -> None: """The value have change from the Number Entity in UI""" float_value = float(value) old_value = float(self._attr_native_value) @@ -327,6 +327,9 @@ class CentralConfigTemperatureNumber( self._attr_value = self._attr_native_value = float_value + # persist the value + self.async_write_ha_state() + # We have to reload all VTherm for which uses the central configuration api: VersatileThermostatAPI = VersatileThermostatAPI.get_vtherm_api(self.hass) # Update the VTherms which have temperature in central config @@ -426,7 +429,7 @@ class TemperatureNumber( # pylint: disable=abstract-method return @overrides - def set_native_value(self, value: float) -> None: + async def async_set_native_value(self, value: float) -> None: """Change the value""" if self.my_climate is None: @@ -442,6 +445,7 @@ class TemperatureNumber( # pylint: disable=abstract-method return self._attr_value = self._attr_native_value = float_value + self.async_write_ha_state() # Update the VTherm temp self.hass.create_task( diff --git a/tests/test_temp_number.py b/tests/test_temp_number.py index 18b8436..74a8c67 100644 --- a/tests/test_temp_number.py +++ b/tests/test_temp_number.py @@ -869,7 +869,7 @@ async def test_change_central_config_temperature( assert temp_entity assert temp_entity.value == 19.1 - temp_entity.set_native_value(20.3) + await temp_entity.async_set_native_value(20.3) assert temp_entity assert temp_entity.value == 20.3 # Wait for async job to complete @@ -985,7 +985,7 @@ async def test_change_vtherm_temperature( assert temp_entity assert temp_entity.value == 19.1 - temp_entity.set_native_value(20.3) + await temp_entity.async_set_native_value(20.3) assert temp_entity assert temp_entity.value == 20.3 # Wait for async job to complete @@ -1106,7 +1106,7 @@ async def test_change_vtherm_temperature_with_presence( assert temp_entity assert temp_entity.value == 30 - temp_entity.set_native_value(20.3) + await temp_entity.async_set_native_value(20.3) assert temp_entity assert temp_entity.value == 20.3 # Wait for async job to complete @@ -1131,7 +1131,7 @@ async def test_change_vtherm_temperature_with_presence( assert temp_entity assert temp_entity.value == 30 - temp_entity.set_native_value(20.3) + await temp_entity.async_set_native_value(20.3) assert temp_entity assert temp_entity.value == 20.3 # Wait for async job to complete