diff --git a/homeassistant/components/aerosmart/coordinator.py b/homeassistant/components/aerosmart/coordinator.py index 795f52a89daf..daae655e335c 100644 --- a/homeassistant/components/aerosmart/coordinator.py +++ b/homeassistant/components/aerosmart/coordinator.py @@ -17,6 +17,7 @@ from homeassistant.helpers import device_registry as dr from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DOMAIN +from .helpers import format_device_type _LOGGER = logging.getLogger(__name__) @@ -101,7 +102,9 @@ class AerosmartCoordinator(DataUpdateCoordinator[UpdateReport]): general = self.device.general if (device_type := general.device_type) is not None: - registry.async_update_device(device.id, model=str(device_type)) + registry.async_update_device( + device.id, model=format_device_type(device_type) + ) if (software_version := general.software_version) is not None: registry.async_update_device(device.id, sw_version=str(software_version)) diff --git a/homeassistant/components/aerosmart/entity.py b/homeassistant/components/aerosmart/entity.py index 9db4529a865b..2206ddc6b553 100644 --- a/homeassistant/components/aerosmart/entity.py +++ b/homeassistant/components/aerosmart/entity.py @@ -13,6 +13,7 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN from .coordinator import AerosmartCoordinator +from .helpers import format_device_type @dataclass(frozen=True, kw_only=True) @@ -46,7 +47,7 @@ class AerosmartEntity(CoordinatorEntity[AerosmartCoordinator]): ) general = coordinator.device.general if (device_type := general.device_type) is not None: - device_info.model = str(device_type) + device_info.model = format_device_type(device_type) if (software_version := general.software_version) is not None: device_info.sw_version = str(software_version) self._attr_device_info = device_info diff --git a/homeassistant/components/aerosmart/helpers.py b/homeassistant/components/aerosmart/helpers.py index 2b26580e910b..567dc0a5e9a5 100644 --- a/homeassistant/components/aerosmart/helpers.py +++ b/homeassistant/components/aerosmart/helpers.py @@ -9,6 +9,19 @@ from homeassistant.const import CONF_DEVICE, CONF_HOST, CONF_PORT, CONF_TYPE from .const import CONF_BAUDRATE, TYPE_SERIAL +_DEVICE_TYPE_NAMES = { + 4: "aerosmart s", + 5: "aerosmart m", + 6: "aerosmart l", + 7: "aerosmart xls", + 11: "aerosmart mono", +} + + +def format_device_type(device_type: int) -> str: + """Return the product name for a device type code.""" + return _DEVICE_TYPE_NAMES.get(device_type, str(device_type)) + def create_modbus_params( data: Mapping[str, Any], diff --git a/tests/components/aerosmart/test_coordinator.py b/tests/components/aerosmart/test_coordinator.py index 617b192d81d7..b14846ae0931 100644 --- a/tests/components/aerosmart/test_coordinator.py +++ b/tests/components/aerosmart/test_coordinator.py @@ -7,6 +7,7 @@ from modbus_connection import ( ModbusTimeoutError, ) from modbus_connection.mock import MockModbusUnit +import pytest from pytest_homeassistant.common import MockConfigEntry, async_fire_time_changed from homeassistant.components.aerosmart.const import DOMAIN, READINGS_SCAN_INTERVAL @@ -23,7 +24,7 @@ async def test_device_info_includes_model_and_software_version( mock_modbus_unit_ventilation: MockModbusUnit, ) -> None: """Device metadata is included when the controller provides it.""" - mock_modbus_unit_ventilation.holding[5000] = [0, 3] + mock_modbus_unit_ventilation.holding[5000] = [0, 5] mock_modbus_unit_ventilation.holding[1156] = [0, 42] mock_config_entry.add_to_hass(hass) @@ -34,16 +35,25 @@ async def test_device_info_includes_model_and_software_version( (DOMAIN, mock_config_entry.entry_id), mock_config_entry.entry_id ) assert device is not None - assert device.model == "3" + assert device.model == "aerosmart m" assert device.sw_version == "42" +@pytest.mark.parametrize( + ("device_type", "expected_model"), + [ + pytest.param(5, "aerosmart m", id="known"), + pytest.param(3, "3", id="unknown"), + ], +) async def test_device_info_recovers_after_initial_general_failure( hass: HomeAssistant, device_registry: dr.DeviceRegistry, freezer: FrozenDateTimeFactory, mock_config_entry: MockConfigEntry, mock_modbus_unit_ventilation: MockModbusUnit, + device_type: int, + expected_model: str, ) -> None: """Device metadata is updated when the general subsystem recovers.""" mock_modbus_unit_ventilation.fail_read( @@ -73,7 +83,7 @@ async def test_device_info_recovers_after_initial_general_failure( assert outside_temperature.state == "0.456" mock_modbus_unit_ventilation.fail_read(5000, None) - mock_modbus_unit_ventilation.holding[5000] = [0, 3] + mock_modbus_unit_ventilation.holding[5000] = [0, device_type] mock_modbus_unit_ventilation.holding[1156] = [0, 42] freezer.tick(READINGS_SCAN_INTERVAL) async_fire_time_changed(hass) @@ -81,7 +91,7 @@ async def test_device_info_recovers_after_initial_general_failure( device = device_registry.async_get(device.id) assert device is not None - assert device.model == "3" + assert device.model == expected_model assert device.sw_version == "42" diff --git a/tests/components/aerosmart/test_helpers.py b/tests/components/aerosmart/test_helpers.py new file mode 100644 index 000000000000..b43f1a21163c --- /dev/null +++ b/tests/components/aerosmart/test_helpers.py @@ -0,0 +1,21 @@ +"""Tests for the aerosmart helpers.""" + +import pytest + +from homeassistant.components.aerosmart.helpers import format_device_type + + +@pytest.mark.parametrize( + ("device_type", "expected"), + [ + pytest.param(4, "aerosmart s", id="s"), + pytest.param(5, "aerosmart m", id="m"), + pytest.param(6, "aerosmart l", id="l"), + pytest.param(7, "aerosmart xls", id="xls"), + pytest.param(11, "aerosmart mono", id="mono"), + pytest.param(3, "3", id="unknown"), + ], +) +def test_format_device_type(device_type: int, expected: str) -> None: + """Known aerosmart types use product names and unknown types keep their code.""" + assert format_device_type(device_type) == expected