- Force writing state when entity is removed
- Fix bug with issue #552 on CONF_USE_CENTRAL_BOILER_FEATURE which should be proposed on a central configuration - Improve reload of entity to avoid reloading all VTherm. Only the reconfigured one will be reloaded
This commit is contained in:
@@ -178,13 +178,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
if hass.state == CoreState.running:
|
if hass.state == CoreState.running:
|
||||||
await api.reload_central_boiler_entities_list()
|
await api.reload_central_boiler_entities_list()
|
||||||
await api.init_vtherm_links()
|
await api.init_vtherm_links(entry.entry_id)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Update listener."""
|
"""Update listener."""
|
||||||
|
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Calling update_listener entry: entry_id='%s', value='%s'",
|
||||||
|
entry.entry_id,
|
||||||
|
entry.data,
|
||||||
|
)
|
||||||
|
|
||||||
if entry.data.get(CONF_THERMOSTAT_TYPE) == CONF_THERMOSTAT_CENTRAL_CONFIG:
|
if entry.data.get(CONF_THERMOSTAT_TYPE) == CONF_THERMOSTAT_CENTRAL_CONFIG:
|
||||||
await reload_all_vtherm(hass)
|
await reload_all_vtherm(hass)
|
||||||
else:
|
else:
|
||||||
@@ -193,7 +200,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||||||
api: VersatileThermostatAPI = VersatileThermostatAPI.get_vtherm_api(hass)
|
api: VersatileThermostatAPI = VersatileThermostatAPI.get_vtherm_api(hass)
|
||||||
if api is not None:
|
if api is not None:
|
||||||
await api.reload_central_boiler_entities_list()
|
await api.reload_central_boiler_entities_list()
|
||||||
await api.init_vtherm_links()
|
await api.init_vtherm_links(entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ from homeassistant.core import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import (
|
||||||
|
RestoreEntity,
|
||||||
|
async_get as restore_async_get,
|
||||||
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
|
||||||
@@ -591,14 +594,24 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
|
|||||||
# issue 428. Link to others entities will start at link
|
# issue 428. Link to others entities will start at link
|
||||||
# await self.async_startup()
|
# await self.async_startup()
|
||||||
|
|
||||||
|
async def async_will_remove_from_hass(self):
|
||||||
|
"""Try to force backup of entity"""
|
||||||
|
_LOGGER_ENERGY.debug(
|
||||||
|
"%s - force write before remove. Energy is %s", self, self.total_energy
|
||||||
|
)
|
||||||
|
# Force dump in background
|
||||||
|
await restore_async_get(self.hass).async_dump_states()
|
||||||
|
|
||||||
def remove_thermostat(self):
|
def remove_thermostat(self):
|
||||||
"""Called when the thermostat will be removed"""
|
"""Called when the thermostat will be removed"""
|
||||||
_LOGGER.info("%s - Removing thermostat", self)
|
_LOGGER.info("%s - Removing thermostat", self)
|
||||||
|
|
||||||
for under in self._underlyings:
|
for under in self._underlyings:
|
||||||
under.remove_entity()
|
under.remove_entity()
|
||||||
|
|
||||||
async def async_startup(self, central_configuration):
|
async def async_startup(self, central_configuration):
|
||||||
"""Triggered on startup, used to get old state and set internal states accordingly"""
|
"""Triggered on startup, used to get old state and set internal states accordingly. This is triggered by
|
||||||
|
VTherm API"""
|
||||||
_LOGGER.debug("%s - Calling async_startup", self)
|
_LOGGER.debug("%s - Calling async_startup", self)
|
||||||
|
|
||||||
_LOGGER.debug("%s - Calling async_startup_internal", self)
|
_LOGGER.debug("%s - Calling async_startup_internal", self)
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
|
|||||||
CONF_USE_PRESETS_CENTRAL_CONFIG,
|
CONF_USE_PRESETS_CENTRAL_CONFIG,
|
||||||
CONF_USE_ADVANCED_CENTRAL_CONFIG,
|
CONF_USE_ADVANCED_CENTRAL_CONFIG,
|
||||||
CONF_USE_CENTRAL_MODE,
|
CONF_USE_CENTRAL_MODE,
|
||||||
CONF_USE_CENTRAL_BOILER_FEATURE,
|
# CONF_USE_CENTRAL_BOILER_FEATURE, this is for Central Config
|
||||||
CONF_USED_BY_CENTRAL_BOILER,
|
CONF_USED_BY_CENTRAL_BOILER,
|
||||||
]:
|
]:
|
||||||
if data.get(conf) is True:
|
if data.get(conf) is True:
|
||||||
|
|||||||
@@ -150,10 +150,11 @@ class VersatileThermostatAPI(dict):
|
|||||||
return entity.state
|
return entity.state
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def init_vtherm_links(self):
|
async def init_vtherm_links(self, entry_id=None):
|
||||||
"""Initialize all VTherms entities links
|
"""Initialize all VTherms entities links
|
||||||
This method is called when HA is fully started (and all entities should be initialized)
|
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, ...)
|
Or when we need to reload all VTherm links (with Number temp entities, central boiler, ...)
|
||||||
|
If entry_id is set, only the VTherm of this entry will be reloaded
|
||||||
"""
|
"""
|
||||||
await self.reload_central_boiler_binary_listener()
|
await self.reload_central_boiler_binary_listener()
|
||||||
await self.reload_central_boiler_entities_list()
|
await self.reload_central_boiler_entities_list()
|
||||||
@@ -175,7 +176,8 @@ class VersatileThermostatAPI(dict):
|
|||||||
entity.device_info
|
entity.device_info
|
||||||
and entity.device_info.get("model", None) == DOMAIN
|
and entity.device_info.get("model", None) == DOMAIN
|
||||||
):
|
):
|
||||||
await entity.async_startup(self.find_central_configuration())
|
if entry_id is None or entry_id == entity.unique_id:
|
||||||
|
await entity.async_startup(self.find_central_configuration())
|
||||||
|
|
||||||
async def init_vtherm_preset_with_central(self):
|
async def init_vtherm_preset_with_central(self):
|
||||||
"""Init all VTherm presets when the VTherm uses central temperature"""
|
"""Init all VTherm presets when the VTherm uses central temperature"""
|
||||||
|
|||||||
Reference in New Issue
Block a user