Skip to content

Commit

Permalink
⬇️ Support firmwares < 3.2
Browse files Browse the repository at this point in the history
This patch restore compatibility with firmwares < 3.2 by listening to
new and old mqtt topics
  • Loading branch information
kamaradclimber committed Oct 20, 2023
1 parent ba13b66 commit bbd90aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions custom_components/aquarea/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class HeishaMonSensorEntityDescription(
HeishaMonEntityDescription, SensorEntityDescription
):
"""Sensor entity description for HeishaMon."""
alternate_mqtt_topic: None | str = None

pass

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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",
Expand Down
23 changes: 21 additions & 2 deletions custom_components/aquarea/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bbd90aa

Please sign in to comment.