From 9839ed4920843db86348f825660b3bcf8e195025 Mon Sep 17 00:00:00 2001 From: Sebastian Noe Date: Sat, 21 Dec 2024 09:36:46 +0100 Subject: [PATCH] Add attribute with active underlyings for easier tracking and setup (#658) * Add attribute with active underlyings for easier tracking and setup * Issue #645 add sonoff trvzb (#651) * With Sonoff configuration ok * Fix configuration * Next (not finished) * With 1rst implementation of VTherm TRVZB and underlying * Work in simuated environment * Fix Testus * Release * Fix release name * Add #602 - implement a max_on_percent setting * Calculate offset_calibration as room_temp - local_temp Fix hvac_action calculation * Fix hvac_action Fix offset_calibration=room_temp - (local_temp - current_offset) * Fix underlying target is not updated * Issue #655 - combine motion and presence * Fix Valve testus. Improve sending the open percent to valve * Update custom_components/versatile_thermostat/translations/en.json Co-authored-by: Alexander Dransfield <2844540+alexdrans@users.noreply.github.com> * Indus step1 * Step 2 - renaming. All tests ok * Step 2: manual tests ok * First unit test ok * Test multi ok * All tests ok. Add a multi test for climate with valve regulation * With testu for config_flow ok * Documentation (not finished) * Fix #661 - central boiler doesn't starts with Sonoff TRVZB * Remove // testing * Fix exception when there is no offset at all * Fix class attributes and instance attributes mixing * Documentation 2 * Documentation 3 * Documentation ++ * documentation * Try to fix the central boiler calculation * Fix #669 * Documentation ++ * Documentation ok for FR * Readme FR|EN --------- Co-authored-by: Jean-Marc Collin Co-authored-by: Alexander Dransfield <2844540+alexdrans@users.noreply.github.com> * Documentation rework * En links * Documentation issue #650 --------- Co-authored-by: Sebastian Noe Co-authored-by: Jean-Marc Collin Co-authored-by: Jean-Marc Collin Co-authored-by: Alexander Dransfield <2844540+alexdrans@users.noreply.github.com> --- .../versatile_thermostat/sensor.py | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/custom_components/versatile_thermostat/sensor.py b/custom_components/versatile_thermostat/sensor.py index 11bcda0..62dac45 100644 --- a/custom_components/versatile_thermostat/sensor.py +++ b/custom_components/versatile_thermostat/sensor.py @@ -653,6 +653,14 @@ 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 + + @property + def extra_state_attributes(self) -> dict: + """Return additional attributes for the sensor.""" + return { + "active_device_names": self._attr_active_device_names, + } @property def icon(self) -> str | None: @@ -718,19 +726,19 @@ class NbActiveDeviceForBoilerSensor(SensorEntity): self.calculate_nb_active_devices, ) _LOGGER.info( - "%s - the underlyings that could controls the central boiler are %s", + "%s - the underlyings that could control the central boiler are %s", self, underlying_entities_id, ) self.async_on_remove(listener_cancel) else: - _LOGGER.debug("%s - no VTherm could controls the central boiler", self) + _LOGGER.debug("%s - no VTherm could control the central boiler", self) await self.calculate_nb_active_devices(None) async def calculate_nb_active_devices(self, event: Event): """Calculate the number of active VTherm that have an - influence on central boiler""" + influence on the central boiler and update the list of active device names.""" # _LOGGER.debug("%s- calculate_nb_active_devices - the event is %s ", self, event) @@ -774,6 +782,8 @@ class NbActiveDeviceForBoilerSensor(SensorEntity): ) nb_active = 0 + active_device_names = [] + for entity in self._entities: nb_active += entity.nb_device_actives _LOGGER.debug( @@ -781,13 +791,21 @@ class NbActiveDeviceForBoilerSensor(SensorEntity): entity.name, nb_active, ) + + 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) self._attr_native_value = nb_active - _LOGGER.debug( - "%s - Number of active underlying entities is %s", self, nb_active - ) + self._attr_active_device_names = active_device_names self.async_write_ha_state() def __str__(self): return f"VersatileThermostat-{self.name}" +