Update central config Number temp entity

This commit is contained in:
Jean-Marc Collin
2024-03-05 18:19:52 +00:00
parent d2eb581a19
commit 6fa616775e
5 changed files with 25 additions and 30 deletions

View File

@@ -22,7 +22,7 @@
"extensions": [
"ms-python.python",
"ms-python.pylint",
// already included into ms-python.python
// Doesn't work (crash). Default in python is to use Jedi see Settings / Python / Default Language
// "ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",

View File

@@ -126,6 +126,7 @@ async def reload_all_vtherm(hass):
api: VersatileThermostatAPI = VersatileThermostatAPI.get_vtherm_api(hass)
if api:
await api.reload_central_boiler_entities_list()
await api.init_vtherm_links()
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@@ -146,6 +147,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
await api.reload_central_boiler_entities_list()
await api.init_vtherm_links()
return True
@@ -160,6 +162,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
api: VersatileThermostatAPI = VersatileThermostatAPI.get_vtherm_api(hass)
if api is not None:
await api.reload_central_boiler_entities_list()
await api.init_vtherm_links()
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

View File

@@ -2722,3 +2722,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity):
if self._motion_on:
self._attr_preset_modes.append(PRESET_ACTIVITY)
# 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)

View File

@@ -227,7 +227,9 @@ class ActivateBoilerThresholdNumber(
return f"VersatileThermostat-{self.name}"
class CentralConfigTemperatureNumber(NumberEntity, RestoreEntity):
class CentralConfigTemperatureNumber(
NumberEntity, RestoreEntity
): # pylint: disable=abstract-method
"""Representation of one temperature number"""
_attr_has_entity_name = True
@@ -318,35 +320,19 @@ class CentralConfigTemperatureNumber(NumberEntity, RestoreEntity):
pass
@overrides
async def async_set_native_value(self, value: float) -> None:
"""Change the value"""
def 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)
if float_value == old_value:
return
# TODO implements the native value change -> reload values for all central config
# based VTherm
# if self.my_climate is None:
# _LOGGER.warning(
# "%s - cannot change temperature because VTherm is not initialized", self
# )
# return
self._attr_value = self._attr_native_value = float_value
#
# float_value = float(value)
# old_value = float(self._attr_native_value)
#
# if float_value == old_value:
# return
#
# self._attr_value = self._attr_native_value = float_value
#
# self.async_write_ha_state()
#
# # Update the VTherm
# self.hass.create_task(
# self.my_climate.service_set_preset_temperature(
# self._preset_name.replace("_temp", ""), self._attr_native_value, None
# )
# )
# We have to reload all VTherm for which uses the central configuration
api: VersatileThermostatAPI = VersatileThermostatAPI.get_vtherm_api(self.hass)
# Update the VTherms
self.hass.create_task(api.init_vtherm_links())
def __str__(self):
return f"VersatileThermostat-{self.name}"

View File

@@ -152,6 +152,7 @@ class VersatileThermostatAPI(dict):
async def init_vtherm_links(self):
"""INitialize all VTherms entities links
This method is called when HA is fully started (and all entities should be initialized)
Or when we need to reload all VTherm links (with Number temp entities, central boiler, ...)
"""
await self.reload_central_boiler_binary_listener()
await self.reload_central_boiler_entities_list()
@@ -161,7 +162,8 @@ class VersatileThermostatAPI(dict):
)
if component:
for entity in component.entities:
await entity.init_presets(self.find_central_configuration())
if hasattr(entity, "init_presets"):
await entity.init_presets(self.find_central_configuration())
async def reload_central_boiler_binary_listener(self):
"""Reloads the BinarySensor entity which listen to the number of