From bbd90aabf5bb8be678c9a1f73599422168a89736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Seux?= Date: Fri, 20 Oct 2023 16:34:15 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=87=EF=B8=8F=20Support=20firmwares=20<=20?= =?UTF-8?q?3.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch restore compatibility with firmwares < 3.2 by listening to new and old mqtt topics --- custom_components/aquarea/definitions.py | 7 +++++++ custom_components/aquarea/sensor.py | 23 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/custom_components/aquarea/definitions.py b/custom_components/aquarea/definitions.py index c274d04..9bae74a 100644 --- a/custom_components/aquarea/definitions.py +++ b/custom_components/aquarea/definitions.py @@ -175,6 +175,7 @@ class HeishaMonSensorEntityDescription( HeishaMonEntityDescription, SensorEntityDescription ): """Sensor entity description for HeishaMon.""" + alternate_mqtt_topic: None | str = None pass @@ -877,6 +878,7 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]: HeishaMonSensorEntityDescription( heishamon_topic_id="TOP15", key=f"{mqtt_prefix}main/Heat_Power_Production", + alternate_mqtt_topic=f"{mqtt_prefix}main/Heat_Energy_Production", name="Aquarea Heat Power Produced", device_class=SensorDeviceClass.POWER, native_unit_of_measurement="W", @@ -886,6 +888,7 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]: HeishaMonSensorEntityDescription( heishamon_topic_id="TOP16", key=f"{mqtt_prefix}main/Heat_Power_Consumption", + alternate_mqtt_topic=f"{mqtt_prefix}main/Heat_Energy_Consumption", name="Aquarea Heat Power Consumed", device_class=SensorDeviceClass.POWER, native_unit_of_measurement="W", @@ -965,6 +968,7 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]: HeishaMonSensorEntityDescription( heishamon_topic_id="TOP38", key=f"{mqtt_prefix}main/Cool_Power_Production", + alternate_mqtt_topic=f"{mqtt_prefix}main/Cool_Energy_Production", state_class=SensorStateClass.MEASUREMENT, name="Aquarea Thermal Cooling power production", device_class=SensorDeviceClass.POWER, @@ -974,6 +978,7 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]: HeishaMonSensorEntityDescription( heishamon_topic_id="TOP39", key=f"{mqtt_prefix}main/Cool_Power_Consumption", + alternate_mqtt_topic=f"{mqtt_prefix}main/Cool_Energy_Consumption", state_class=SensorStateClass.MEASUREMENT, name="Aquarea Thermal Cooling power consumption", device_class=SensorDeviceClass.POWER, @@ -983,6 +988,7 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]: HeishaMonSensorEntityDescription( heishamon_topic_id="TOP40", key=f"{mqtt_prefix}main/DHW_Power_Production", + alternate_mqtt_topic=f"{mqtt_prefix}main/DHW_Energy_Production", name="Aquarea DHW Power Produced", device_class=SensorDeviceClass.POWER, native_unit_of_measurement="W", @@ -992,6 +998,7 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]: HeishaMonSensorEntityDescription( heishamon_topic_id="TOP41", key=f"{mqtt_prefix}main/DHW_Power_Consumption", + alternate_mqtt_topic=f"{mqtt_prefix}main/DHW_Energy_Consumption", name="Aquarea DHW Power Consumed", device_class=SensorDeviceClass.POWER, native_unit_of_measurement="W", diff --git a/custom_components/aquarea/sensor.py b/custom_components/aquarea/sensor.py index 71163ad..3ce5d74 100644 --- a/custom_components/aquarea/sensor.py +++ b/custom_components/aquarea/sensor.py @@ -79,6 +79,10 @@ async def async_setup_entry( f"{discovery_prefix}main/DHW_Power_Production", f"{discovery_prefix}main/Heat_Power_Production", f"{discovery_prefix}main/Cool_Power_Production", + # legacy topics, for firmwares < 3.2 + f"{discovery_prefix}main/DHW_Energy_Production", + f"{discovery_prefix}main/Heat_Energy_Production", + f"{discovery_prefix}main/Cool_Energy_Production", ], compute_state=sum_all_topics, suggested_display_precision=0, @@ -96,6 +100,10 @@ async def async_setup_entry( f"{discovery_prefix}main/DHW_Power_Consumption", f"{discovery_prefix}main/Heat_Power_Consumption", f"{discovery_prefix}main/Cool_Power_Consumption", + # legacy topics, for firmwares < 3.2 + f"{discovery_prefix}main/DHW_Energy_Consumption", + f"{discovery_prefix}main/Heat_Energy_Consumption", + f"{discovery_prefix}main/Cool_Energy_Consumption", ], compute_state=sum_all_topics, suggested_display_precision=0, @@ -114,6 +122,13 @@ async def async_setup_entry( f"{discovery_prefix}main/DHW_Power_Consumption", f"{discovery_prefix}main/Heat_Power_Consumption", f"{discovery_prefix}main/Cool_Power_Consumption", + # legacy topics, for firmwares < 3.2 + f"{discovery_prefix}main/DHW_Energy_Production", + f"{discovery_prefix}main/Heat_Energy_Production", + f"{discovery_prefix}main/Cool_Energy_Production", + f"{discovery_prefix}main/DHW_Energy_Consumption", + f"{discovery_prefix}main/Heat_Energy_Consumption", + f"{discovery_prefix}main/Cool_Energy_Consumption", ], compute_state=compute_cop, ) @@ -123,8 +138,8 @@ async def async_setup_entry( def compute_cop(values) -> Optional[float]: assert len(values) == 6 - production = sum([el for el in values[0:3] if el is not None]) - consumption = sum([el for el in values[3:6] if el is not None]) + production = sum([el for el in values[0:3] + values[6:9] if el is not None]) + consumption = sum([el for el in values[3:6] + values[9:12] if el is not None]) if consumption == 0: return 0 cop = production / consumption @@ -402,6 +417,10 @@ def message_received(message): await mqtt.async_subscribe( self.hass, self.entity_description.key, message_received, 1 ) + if self.entity_description.alternate_mqtt_topic is not None: + await mqtt.async_subscribe( + self.hass, self.entity_description.alternate_mqtt_topic, message_received, 1 + ) @property def device_info(self):