1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 14:08:21 +00:00

Fix model_id in Husqvarna Automower (#156608)

This commit is contained in:
Thomas55555
2025-11-14 19:10:16 +01:00
committed by Franck Nijhof
parent cefc0ba96e
commit c0f0cfef59
3 changed files with 43 additions and 7 deletions

View File

@@ -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",

View File

@@ -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,

View File

@@ -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)