Try to fix the central boiler calculation
This commit is contained in:
@@ -1132,6 +1132,11 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
|
|||||||
"""Returns the underlying entities"""
|
"""Returns the underlying entities"""
|
||||||
return self._underlyings
|
return self._underlyings
|
||||||
|
|
||||||
|
@property
|
||||||
|
def activable_underlying_entities(self) -> list | None:
|
||||||
|
"""Returns the activable underlying entities for controling the central boiler"""
|
||||||
|
return self.underlying_entities
|
||||||
|
|
||||||
def find_underlying_by_entity_id(self, entity_id: str) -> Entity | None:
|
def find_underlying_by_entity_id(self, entity_id: str) -> Entity | None:
|
||||||
"""Get the underlying entity by a entity_id"""
|
"""Get the underlying entity by a entity_id"""
|
||||||
for under in self._underlyings:
|
for under in self._underlyings:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant, callback, Event, CoreState
|
from homeassistant.core import HomeAssistant, callback, Event, CoreState, State
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
UnitOfTime,
|
UnitOfTime,
|
||||||
@@ -23,13 +23,13 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.event import async_track_state_change_event
|
from homeassistant.helpers.event import (
|
||||||
|
async_track_state_change_event,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ClimateEntity,
|
ClimateEntity,
|
||||||
DOMAIN as CLIMATE_DOMAIN,
|
DOMAIN as CLIMATE_DOMAIN,
|
||||||
HVACAction,
|
|
||||||
HVACMode,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -708,7 +708,7 @@ class NbActiveDeviceForBoilerSensor(SensorEntity):
|
|||||||
for entity in component.entities:
|
for entity in component.entities:
|
||||||
if isinstance(entity, BaseThermostat) and entity.is_used_by_central_boiler:
|
if isinstance(entity, BaseThermostat) and entity.is_used_by_central_boiler:
|
||||||
self._entities.append(entity)
|
self._entities.append(entity)
|
||||||
for under in entity.underlying_entities:
|
for under in entity.activable_underlying_entities:
|
||||||
underlying_entities_id.append(under.entity_id)
|
underlying_entities_id.append(under.entity_id)
|
||||||
if len(underlying_entities_id) > 0:
|
if len(underlying_entities_id) > 0:
|
||||||
# Arme l'écoute de la première entité
|
# Arme l'écoute de la première entité
|
||||||
@@ -728,21 +728,59 @@ class NbActiveDeviceForBoilerSensor(SensorEntity):
|
|||||||
|
|
||||||
await self.calculate_nb_active_devices(None)
|
await self.calculate_nb_active_devices(None)
|
||||||
|
|
||||||
async def calculate_nb_active_devices(self, _):
|
async def calculate_nb_active_devices(self, event: Event):
|
||||||
"""Calculate the number of active VTherm that have an
|
"""Calculate the number of active VTherm that have an
|
||||||
influence on central boiler"""
|
influence on central boiler"""
|
||||||
|
|
||||||
_LOGGER.debug(
|
# _LOGGER.debug("%s- calculate_nb_active_devices - the event is %s ", self, event)
|
||||||
"%s - calculating the number of active underlying device for boiler activation",
|
|
||||||
self,
|
if event is not None:
|
||||||
)
|
new_state: State = event.data.get("new_state")
|
||||||
|
# _LOGGER.debug(
|
||||||
|
# "%s - calculate_nb_active_devices new_state is %s", self, new_state
|
||||||
|
# )
|
||||||
|
if not new_state:
|
||||||
|
return
|
||||||
|
|
||||||
|
old_state: State = event.data.get("old_state")
|
||||||
|
|
||||||
|
# For underlying climate, we need to observe also the hvac_action if available
|
||||||
|
new_hvac_action = new_state.attributes.get("hvac_action")
|
||||||
|
old_hvac_action = (
|
||||||
|
old_state.attributes.get("hvac_action")
|
||||||
|
if old_state is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
# Filter events that are not interested for us
|
||||||
|
if (
|
||||||
|
old_state is not None
|
||||||
|
and new_state.state == old_state.state
|
||||||
|
and new_hvac_action == old_hvac_action
|
||||||
|
):
|
||||||
|
# A false state change
|
||||||
|
return
|
||||||
|
|
||||||
|
_LOGGER.debug(
|
||||||
|
"%s - calculating the number of active underlying device for boiler activation. change change from %s to %s",
|
||||||
|
self,
|
||||||
|
old_state,
|
||||||
|
new_state,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
_LOGGER.debug(
|
||||||
|
"%s - calculating the number of active underlying device for boiler activation. First time calculation",
|
||||||
|
self,
|
||||||
|
)
|
||||||
|
|
||||||
nb_active = 0
|
nb_active = 0
|
||||||
for entity in self._entities:
|
for entity in self._entities:
|
||||||
_LOGGER.debug(
|
|
||||||
"Examining the hvac_action of %s",
|
|
||||||
entity.name,
|
|
||||||
)
|
|
||||||
nb_active += entity.nb_device_actives
|
nb_active += entity.nb_device_actives
|
||||||
|
_LOGGER.debug(
|
||||||
|
"After examining the hvac_action of %s, nb_active is %s",
|
||||||
|
entity.name,
|
||||||
|
nb_active,
|
||||||
|
)
|
||||||
|
|
||||||
self._attr_native_value = nb_active
|
self._attr_native_value = nb_active
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
|||||||
@@ -284,6 +284,11 @@ class ThermostatOverClimateValve(ThermostatOverClimate):
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def activable_underlying_entities(self) -> list | None:
|
||||||
|
"""Returns the activable underlying entities for controling the central boiler"""
|
||||||
|
return self._underlyings_valve_regulation
|
||||||
|
|
||||||
@overrides
|
@overrides
|
||||||
async def service_set_auto_regulation_mode(self, auto_regulation_mode: str):
|
async def service_set_auto_regulation_mode(self, auto_regulation_mode: str):
|
||||||
"""This should not be possible in valve regulation mode"""
|
"""This should not be possible in valve regulation mode"""
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ from custom_components.versatile_thermostat.thermostat_switch import (
|
|||||||
ThermostatOverSwitch,
|
ThermostatOverSwitch,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from custom_components.versatile_thermostat.thermostat_climate import (
|
||||||
|
ThermostatOverClimate,
|
||||||
|
)
|
||||||
|
|
||||||
from custom_components.versatile_thermostat.vtherm_api import VersatileThermostatAPI
|
from custom_components.versatile_thermostat.vtherm_api import VersatileThermostatAPI
|
||||||
|
|
||||||
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
|
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
|
||||||
|
|||||||
Reference in New Issue
Block a user