diff --git a/custom_components/plum_ecomax/sensor.py b/custom_components/plum_ecomax/sensor.py index bc96413..49281f1 100644 --- a/custom_components/plum_ecomax/sensor.py +++ b/custom_components/plum_ecomax/sensor.py @@ -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 @@ -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", @@ -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() diff --git a/custom_components/plum_ecomax/strings.json b/custom_components/plum_ecomax/strings.json index 6c27ed0..ee4ee44 100644 --- a/custom_components/plum_ecomax/strings.json +++ b/custom_components/plum_ecomax/strings.json @@ -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" }, diff --git a/custom_components/plum_ecomax/translations/cs.json b/custom_components/plum_ecomax/translations/cs.json index 0068281..6c39f5b 100644 --- a/custom_components/plum_ecomax/translations/cs.json +++ b/custom_components/plum_ecomax/translations/cs.json @@ -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" }, diff --git a/custom_components/plum_ecomax/translations/en.json b/custom_components/plum_ecomax/translations/en.json index 357c24b..2ab26f6 100644 --- a/custom_components/plum_ecomax/translations/en.json +++ b/custom_components/plum_ecomax/translations/en.json @@ -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" }, diff --git a/custom_components/plum_ecomax/translations/fr.json b/custom_components/plum_ecomax/translations/fr.json index ca111dc..a670614 100644 --- a/custom_components/plum_ecomax/translations/fr.json +++ b/custom_components/plum_ecomax/translations/fr.json @@ -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" }, diff --git a/custom_components/plum_ecomax/translations/pl.json b/custom_components/plum_ecomax/translations/pl.json index bc2fc9e..9e55dcb 100644 --- a/custom_components/plum_ecomax/translations/pl.json +++ b/custom_components/plum_ecomax/translations/pl.json @@ -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" }, diff --git a/custom_components/plum_ecomax/translations/ru.json b/custom_components/plum_ecomax/translations/ru.json index e133912..9b86822 100644 --- a/custom_components/plum_ecomax/translations/ru.json +++ b/custom_components/plum_ecomax/translations/ru.json @@ -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": "Мощность" }, diff --git a/custom_components/plum_ecomax/translations/ua.json b/custom_components/plum_ecomax/translations/ua.json index 2058b1f..24fb010 100644 --- a/custom_components/plum_ecomax/translations/ua.json +++ b/custom_components/plum_ecomax/translations/ua.json @@ -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" }, diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 6c0a78f..caca5f4 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -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")