Skip to content

Commit

Permalink
Add connected modules sensor.
Browse files Browse the repository at this point in the history
Connected modules entity lists number of currently connected modules as well as their software version as an extra state attributes.

This replaces the software version sensor.
  • Loading branch information
denpamusic committed Dec 4, 2023
1 parent aff766a commit 8e71933
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 20 deletions.
11 changes: 8 additions & 3 deletions custom_components/plum_ecomax/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from collections.abc import Callable, Generator, Iterable
from dataclasses import dataclass
from dataclasses import asdict, astuple, dataclass
from datetime import date, datetime
import logging
from typing import Any, Final, Literal
Expand Down Expand Up @@ -154,9 +154,9 @@ class EcomaxSensorEntityDescription(SensorEntityDescription):
),
EcomaxSensorEntityDescription(
key="modules",
translation_key="software_version",
translation_key="connected_modules",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda x: x.module_a,
value_fn=lambda x: len([value for value in astuple(x) if value is not None]),
),
EcomaxSensorEntityDescription(
key="product",
Expand Down Expand Up @@ -352,6 +352,11 @@ async def async_update(self, value) -> None:
# device state.
self._attr_extra_state_attributes = {ATTR_NUMERIC_STATE: int(value)}

if isinstance(value, ConnectedModules):
self._attr_extra_state_attributes = {
key: value for key, value in asdict(value).items() if value is not None
}

self.async_write_ha_state()


Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Service password" },
"software_version": { "name": "Software version" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Panel software version" },
"module_a": { "name": "Module A software version" },
"module_b": { "name": "Module B software version" },
"module_c": { "name": "Module C software version" },
"ecoster": { "name": "ecoSTER software version" },
"ecolambda": { "name": "ecoLAMBDA software version" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Oxygen level" },
"boiler_power": { "name": "Boiler power" },
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Service password" },
"software_version": { "name": "Software version" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Panel software version" },
"module_a": { "name": "Module A software version" },
"module_b": { "name": "Module B software version" },
"module_c": { "name": "Module C software version" },
"ecoster": { "name": "ecoSTER software version" },
"ecolambda": { "name": "ecoLAMBDA software version" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Oxygen level" },
"boiler_power": { "name": "Boiler power" },
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Service password" },
"software_version": { "name": "Software version" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Panel software version" },
"module_a": { "name": "Module A software version" },
"module_b": { "name": "Module B software version" },
"module_c": { "name": "Module C software version" },
"ecoster": { "name": "ecoSTER software version" },
"ecolambda": { "name": "ecoLAMBDA software version" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Oxygen level" },
"boiler_power": { "name": "Boiler power" },
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Service password" },
"software_version": { "name": "Software version" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Panel software version" },
"module_a": { "name": "Module A software version" },
"module_b": { "name": "Module B software version" },
"module_c": { "name": "Module C software version" },
"ecoster": { "name": "ecoSTER software version" },
"ecolambda": { "name": "ecoLAMBDA software version" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Oxygen level" },
"boiler_power": { "name": "Boiler power" },
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Hasło serwisowe" },
"software_version": { "name": "Wersja oprogramowania" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Wersja oprogramowania Panel" },
"module_a": { "name": "Wersja oprogramowania Module A" },
"module_b": { "name": "Wersja oprogramowania Module B" },
"module_c": { "name": "Wersja oprogramowania Module C" },
"ecoster": { "name": "Wersja oprogramowania ecoSTER" },
"ecolambda": { "name": "Wersja oprogramowania ecoLAMBDA" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Poziom tlenu" },
"boiler_power": { "name": "Moc kotła" },
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Сервисный пароль" },
"software_version": { "name": "Версия ПО" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Panel software version" },
"module_a": { "name": "Module A software version" },
"module_b": { "name": "Module B software version" },
"module_c": { "name": "Module C software version" },
"ecoster": { "name": "ecoSTER software version" },
"ecolambda": { "name": "ecoLAMBDA software version" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Содержание кислорода" },
"boiler_power": { "name": "Мощность" },
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plum_ecomax/translations/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@
}
},
"service_password": { "name": "Service password" },
"software_version": { "name": "Software version" },
"connected_modules": {
"name": "Connected modules",
"state_attributes": {
"panel": { "name": "Panel software version" },
"module_a": { "name": "Module A software version" },
"module_b": { "name": "Module B software version" },
"module_c": { "name": "Module C software version" },
"ecoster": { "name": "ecoSTER software version" },
"ecolambda": { "name": "ecoLAMBDA software version" }
}
},
"uid": { "name": "UID" },
"oxygen_level": { "name": "Oxygen level" },
"boiler_power": { "name": "Boiler power" },
Expand Down
24 changes: 14 additions & 10 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,33 +409,37 @@ async def test_service_password_sensor(


@pytest.mark.usefixtures("ecomax_p")
async def test_software_version_sensor(
async def test_connected_modules_sensor(
hass: HomeAssistant,
connection: EcomaxConnection,
config_entry: MockConfigEntry,
setup_integration,
) -> None:
"""Test software version sensor."""
"""Test connected_modules sensor."""
await setup_integration(hass, config_entry)
software_version_entity_id = "sensor.ecomax_software_version"
connected_modules_entity_id = "sensor.ecomax_connected_modules"

# Check entry.
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(software_version_entity_id)
entry = entity_registry.async_get(connected_modules_entity_id)
assert entry
assert entry.translation_key == "software_version"
assert entry.translation_key == "connected_modules"

# Get initial value.
state = hass.states.get(software_version_entity_id)
assert state.state == "6.10.32.K1"
assert state.attributes[ATTR_FRIENDLY_NAME] == "ecoMAX Software version"
state = hass.states.get(connected_modules_entity_id)
assert state.state == "3"
assert state.attributes[ATTR_FRIENDLY_NAME] == "ecoMAX Connected modules"
assert state.attributes["module_a"] == "6.10.32.K1"
assert state.attributes["ecolambda"] == "0.8.0"
assert state.attributes["panel"] == "6.30.36"

# Dispatch new value.
await connection.device.dispatch(
ATTR_MODULES, ConnectedModules(module_a="1.0.0.T0")
)
state = hass.states.get(software_version_entity_id)
assert state.state == "1.0.0.T0"
state = hass.states.get(connected_modules_entity_id)
assert state.state == "1"
assert state.attributes["module_a"] == "1.0.0.T0"


@pytest.mark.usefixtures("ecomax_p")
Expand Down

0 comments on commit 8e71933

Please sign in to comment.