From ae51cfb8c035c2fd161d5697698b641129f75676 Mon Sep 17 00:00:00 2001 From: Thomas55555 <59625598+Thomas55555@users.noreply.github.com> Date: Fri, 14 Nov 2025 19:10:16 +0100 Subject: [PATCH] Fix model_id in Husqvarna Automower (#156608) --- .../components/husqvarna_automower/entity.py | 11 +++--- .../snapshots/test_init.ambr | 4 +-- .../husqvarna_automower/test_init.py | 35 ++++++++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/husqvarna_automower/entity.py b/homeassistant/components/husqvarna_automower/entity.py index cd8d00ac8f1..92d35616b2d 100644 --- a/homeassistant/components/husqvarna_automower/entity.py +++ b/homeassistant/components/husqvarna_automower/entity.py @@ -121,12 +121,15 @@ class AutomowerBaseEntity(CoordinatorEntity[AutomowerDataUpdateCoordinator]): """Initialize AutomowerEntity.""" super().__init__(coordinator) self.mower_id = mower_id - parts = self.mower_attributes.system.model.split(maxsplit=2) + model_witout_manufacturer = self.mower_attributes.system.model.removeprefix( + "Husqvarna " + ).removeprefix("HUSQVARNA ") + parts = model_witout_manufacturer.split(maxsplit=1) self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, mower_id)}, - manufacturer=parts[0], - model=parts[1], - model_id=parts[2], + manufacturer="Husqvarna", + model=parts[0].capitalize().removesuffix("®"), + model_id=parts[1], name=self.mower_attributes.system.name, serial_number=self.mower_attributes.system.serial_number, suggested_area="Garden", diff --git a/tests/components/husqvarna_automower/snapshots/test_init.ambr b/tests/components/husqvarna_automower/snapshots/test_init.ambr index 57ff86634d3..7e1759bb934 100644 --- a/tests/components/husqvarna_automower/snapshots/test_init.ambr +++ b/tests/components/husqvarna_automower/snapshots/test_init.ambr @@ -19,8 +19,8 @@ }), 'labels': set({ }), - 'manufacturer': 'HUSQVARNA', - 'model': 'AUTOMOWER®', + 'manufacturer': 'Husqvarna', + 'model': 'Automower', 'model_id': '450XH', 'name': 'Test Mower 1', 'name_by_user': None, diff --git a/tests/components/husqvarna_automower/test_init.py b/tests/components/husqvarna_automower/test_init.py index 1a93731cb7e..e5d26400c37 100644 --- a/tests/components/husqvarna_automower/test_init.py +++ b/tests/components/husqvarna_automower/test_init.py @@ -199,6 +199,39 @@ async def test_websocket_not_available( assert mock.call_count == 1 +@pytest.mark.parametrize( + ("api_input", "model", "model_id"), + [ + ("HUSQVARNA AUTOMOWER® 450XH", "Automower", "450XH"), + ("Automower 315X", "Automower", "315X"), + ("Husqvarna Automower® 435 AWD", "Automower", "435 AWD"), + ("Husqvarna CEORA® 544 EPOS", "Ceora", "544 EPOS"), + ], +) +async def test_model_id_information( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_automower_client: AsyncMock, + device_registry: dr.DeviceRegistry, + values: dict[str, MowerAttributes], + api_input: str, + model: str, + model_id: str, +) -> None: + """Test model and model_id parsing.""" + values[TEST_MOWER_ID].system.model = api_input + mock_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + reg_device = device_registry.async_get_device( + identifiers={(DOMAIN, TEST_MOWER_ID)}, + ) + assert reg_device is not None + assert reg_device.manufacturer == "Husqvarna" + assert reg_device.model == model + assert reg_device.model_id == model_id + + async def test_device_info( hass: HomeAssistant, mock_automower_client: AsyncMock, @@ -206,7 +239,7 @@ async def test_device_info( device_registry: dr.DeviceRegistry, snapshot: SnapshotAssertion, ) -> None: - """Test select platform.""" + """Test device info.""" mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id)