Skip to content

Commit

Permalink
✨ Support K & L "extra" topics
Browse files Browse the repository at this point in the history
Fix #141
  • Loading branch information
kamaradclimber committed Oct 23, 2023
1 parent 071a4dc commit dd7226e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
32 changes: 25 additions & 7 deletions custom_components/aquarea/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class HeishaMonSensorEntityDescription(
):
"""Sensor entity description for HeishaMon."""

alternate_mqtt_topic: None | str = None
alternate_mqtt_topics: None | list[str] = None

pass

Expand Down Expand Up @@ -880,7 +880,10 @@ 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",
alternate_mqtt_topics=[
f"{mqtt_prefix}main/Heat_Energy_Production",
f"{mqtt_prefix}extra/Heat_Power_Production", # XTOP3
],
name="Aquarea Heat Power Produced",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement="W",
Expand All @@ -890,7 +893,10 @@ 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",
alternate_mqtt_topics=[
f"{mqtt_prefix}main/Heat_Energy_Consumption",
f"{mqtt_prefix}extra/Heat_Power_Consumption", # XTOP0
],
name="Aquarea Heat Power Consumed",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement="W",
Expand Down Expand Up @@ -970,7 +976,10 @@ 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",
alternate_mqtt_topics=[
f"{mqtt_prefix}main/Cool_Energy_Production",
f"{mqtt_prefix}extra/Cool_Power_Production", # XTOP4
],
state_class=SensorStateClass.MEASUREMENT,
name="Aquarea Thermal Cooling power production",
device_class=SensorDeviceClass.POWER,
Expand All @@ -980,7 +989,10 @@ 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",
alternate_mqtt_topics=[
f"{mqtt_prefix}main/Cool_Energy_Consumption",
f"{mqtt_prefix}extra/Cool_Power_Consumption", # XTOP1
],
state_class=SensorStateClass.MEASUREMENT,
name="Aquarea Thermal Cooling power consumption",
device_class=SensorDeviceClass.POWER,
Expand All @@ -990,7 +1002,10 @@ 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",
alternate_mqtt_topics=[
f"{mqtt_prefix}main/DHW_Energy_Production",
f"{mqtt_prefix}extra/DHW_Power_Production", # XTOP5
],
name="Aquarea DHW Power Produced",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement="W",
Expand All @@ -1000,7 +1015,10 @@ 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",
alternate_mqtt_topics=[
f"{mqtt_prefix}main/DHW_Energy_Consumption",
f"{mqtt_prefix}extra/DHW_Power_Consumption", # XTOP2
],
name="Aquarea DHW Power Consumed",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement="W",
Expand Down
40 changes: 30 additions & 10 deletions custom_components/aquarea/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ async def async_setup_entry(
f"{discovery_prefix}main/DHW_Energy_Production",
f"{discovery_prefix}main/Heat_Energy_Production",
f"{discovery_prefix}main/Cool_Energy_Production",
# K & L models
f"{discovery_prefix}extra/DHW_Power_Production",
f"{discovery_prefix}extra/Heat_Power_Production",
f"{discovery_prefix}extra/Cool_Power_Production",
],
compute_state=sum_all_topics,
suggested_display_precision=0,
Expand All @@ -104,6 +108,10 @@ async def async_setup_entry(
f"{discovery_prefix}main/DHW_Energy_Consumption",
f"{discovery_prefix}main/Heat_Energy_Consumption",
f"{discovery_prefix}main/Cool_Energy_Consumption",
# K & L models
f"{discovery_prefix}extra/DHW_Power_Consumption",
f"{discovery_prefix}extra/Heat_Power_Consumption",
f"{discovery_prefix}extra/Cool_Power_Consumption",
],
compute_state=sum_all_topics,
suggested_display_precision=0,
Expand All @@ -129,6 +137,13 @@ async def async_setup_entry(
f"{discovery_prefix}main/DHW_Energy_Consumption",
f"{discovery_prefix}main/Heat_Energy_Consumption",
f"{discovery_prefix}main/Cool_Energy_Consumption",
# K & L models
f"{discovery_prefix}extra/DHW_Power_Production",
f"{discovery_prefix}extra/Heat_Power_Production",
f"{discovery_prefix}extra/Cool_Power_Production",
f"{discovery_prefix}extra/DHW_Power_Consumption",
f"{discovery_prefix}extra/Heat_Power_Consumption",
f"{discovery_prefix}extra/Cool_Power_Consumption",
],
compute_state=compute_cop,
)
Expand All @@ -137,9 +152,13 @@ async def async_setup_entry(


def compute_cop(values) -> Optional[float]:
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])
assert len(values) == 18
production = sum(
[el for el in values[0:3] + values[6:9] + values[12:15] if el is not None]
)
consumption = sum(
[el for el in values[3:6] + values[9:12] + values[15:18] if el is not None]
)
if consumption == 0:
return 0
cop = production / consumption
Expand Down Expand Up @@ -417,13 +436,14 @@ 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,
)
if self.entity_description.alternate_mqtt_topics is not None:
for alternate_mqtt_topic in self.entity_description.alternate_mqtt_topics:
await mqtt.async_subscribe(
self.hass,
alternate_mqtt_topic,
message_received,
1,
)

@property
def device_info(self):
Expand Down

0 comments on commit dd7226e

Please sign in to comment.