With tests and list of active
This commit is contained in:
@@ -131,7 +131,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
|
||||
"max_power_sensor_entity_id",
|
||||
"temperature_unit",
|
||||
"is_device_active",
|
||||
"nb_device_actives",
|
||||
"device_actives",
|
||||
"target_temperature_step",
|
||||
"is_used_by_central_boiler",
|
||||
"temperature_slope",
|
||||
@@ -1001,14 +1001,19 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
|
||||
return False
|
||||
|
||||
@property
|
||||
def nb_device_actives(self) -> int:
|
||||
"""Calculate the number of active devices"""
|
||||
ret = 0
|
||||
def device_actives(self) -> int:
|
||||
"""Calculate the active devices"""
|
||||
ret = []
|
||||
for under in self._underlyings:
|
||||
if under.is_device_active:
|
||||
ret += 1
|
||||
ret.append(under.entity_id)
|
||||
return ret
|
||||
|
||||
@property
|
||||
def nb_device_actives(self) -> int:
|
||||
"""Calculate the number of active devices"""
|
||||
return len(self.device_actives)
|
||||
|
||||
@property
|
||||
def current_temperature(self) -> float | None:
|
||||
"""Return the sensor temperature."""
|
||||
@@ -2680,6 +2685,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
|
||||
"timezone": str(self._current_tz),
|
||||
"temperature_unit": self.temperature_unit,
|
||||
"is_device_active": self.is_device_active,
|
||||
"device_actives": self.device_actives,
|
||||
"nb_device_actives": self.nb_device_actives,
|
||||
"ema_temp": self._ema_temp,
|
||||
"is_used_by_central_boiler": self.is_used_by_central_boiler,
|
||||
|
||||
@@ -644,6 +644,10 @@ class NbActiveDeviceForBoilerSensor(SensorEntity):
|
||||
"""Representation of the threshold of the number of VTherm
|
||||
which should be active to activate the boiler"""
|
||||
|
||||
_entity_component_unrecorded_attributes = SensorEntity._entity_component_unrecorded_attributes.union( # pylint: disable=protected-access
|
||||
frozenset({"active_device_ids"})
|
||||
)
|
||||
|
||||
def __init__(self, hass: HomeAssistant, unique_id, name, entry_infos) -> None:
|
||||
"""Initialize the energy sensor"""
|
||||
self._hass = hass
|
||||
@@ -653,13 +657,13 @@ class NbActiveDeviceForBoilerSensor(SensorEntity):
|
||||
self._attr_unique_id = "nb_device_active_boiler"
|
||||
self._attr_value = self._attr_native_value = None # default value
|
||||
self._entities = []
|
||||
self._attr_active_device_names = [] # Holds the names of active devices
|
||||
self._attr_active_device_ids = [] # Holds the entity ids of active devices
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
"""Return additional attributes for the sensor."""
|
||||
return {
|
||||
"active_device_names": self._attr_active_device_names,
|
||||
"active_device_ids": self._attr_active_device_ids,
|
||||
}
|
||||
|
||||
@property
|
||||
@@ -782,30 +786,28 @@ class NbActiveDeviceForBoilerSensor(SensorEntity):
|
||||
)
|
||||
|
||||
nb_active = 0
|
||||
active_device_names = []
|
||||
active_device_ids = []
|
||||
|
||||
for entity in self._entities:
|
||||
nb_active += entity.nb_device_actives
|
||||
device_actives = entity.device_actives
|
||||
_LOGGER.debug(
|
||||
"After examining the hvac_action of %s, nb_active is %s",
|
||||
"After examining the hvac_action of %s, device_actives is %s",
|
||||
entity.name,
|
||||
nb_active,
|
||||
device_actives,
|
||||
)
|
||||
|
||||
if (
|
||||
entity.hvac_mode in [HVACMode.HEAT, HVACMode.AUTO]
|
||||
and entity.hvac_action == HVACAction.HEATING
|
||||
):
|
||||
for under in entity.underlying_entities:
|
||||
if under.is_device_active:
|
||||
nb_active += 1
|
||||
active_device_names.append(under.entity_id)
|
||||
|
||||
nb_active += len(device_actives)
|
||||
active_device_ids.extend(device_actives)
|
||||
|
||||
self._attr_native_value = nb_active
|
||||
self._attr_active_device_names = active_device_names
|
||||
self._attr_active_device_ids = active_device_ids
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def active_device_ids(self) -> list:
|
||||
"""Get the list of active device id"""
|
||||
return self._attr_active_device_ids
|
||||
|
||||
def __str__(self):
|
||||
return f"VersatileThermostat-{self.name}"
|
||||
|
||||
|
||||
@@ -277,12 +277,15 @@ class ThermostatOverClimateValve(ThermostatOverClimate):
|
||||
return self.valve_open_percent > 0
|
||||
|
||||
@property
|
||||
def nb_device_actives(self) -> int:
|
||||
def device_actives(self) -> int:
|
||||
"""Calculate the number of active devices"""
|
||||
if self.is_device_active:
|
||||
return len(self._underlyings_valve_regulation)
|
||||
return [
|
||||
under.opening_degree_entity_id
|
||||
for under in self._underlyings_valve_regulation
|
||||
]
|
||||
else:
|
||||
return 0
|
||||
return []
|
||||
|
||||
@property
|
||||
def activable_underlying_entities(self) -> list | None:
|
||||
|
||||
Reference in New Issue
Block a user