Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬇️ Support firmwares < 3.2 #134

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 22 additions & 3 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 @@ -122,9 +137,9 @@ 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])
assert len(values) == 12
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
Loading