Skip to content

Commit ae51cfb

Browse files
authored
Fix model_id in Husqvarna Automower (home-assistant#156608)
1 parent c116a9c commit ae51cfb

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

homeassistant/components/husqvarna_automower/entity.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ def __init__(
121121
"""Initialize AutomowerEntity."""
122122
super().__init__(coordinator)
123123
self.mower_id = mower_id
124-
parts = self.mower_attributes.system.model.split(maxsplit=2)
124+
model_witout_manufacturer = self.mower_attributes.system.model.removeprefix(
125+
"Husqvarna "
126+
).removeprefix("HUSQVARNA ")
127+
parts = model_witout_manufacturer.split(maxsplit=1)
125128
self._attr_device_info = DeviceInfo(
126129
identifiers={(DOMAIN, mower_id)},
127-
manufacturer=parts[0],
128-
model=parts[1],
129-
model_id=parts[2],
130+
manufacturer="Husqvarna",
131+
model=parts[0].capitalize().removesuffix("®"),
132+
model_id=parts[1],
130133
name=self.mower_attributes.system.name,
131134
serial_number=self.mower_attributes.system.serial_number,
132135
suggested_area="Garden",

tests/components/husqvarna_automower/snapshots/test_init.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
}),
2020
'labels': set({
2121
}),
22-
'manufacturer': 'HUSQVARNA',
23-
'model': 'AUTOMOWER®',
22+
'manufacturer': 'Husqvarna',
23+
'model': 'Automower',
2424
'model_id': '450XH',
2525
'name': 'Test Mower 1',
2626
'name_by_user': None,

tests/components/husqvarna_automower/test_init.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,47 @@ async def mock_function():
199199
assert mock.call_count == 1
200200

201201

202+
@pytest.mark.parametrize(
203+
("api_input", "model", "model_id"),
204+
[
205+
("HUSQVARNA AUTOMOWER® 450XH", "Automower", "450XH"),
206+
("Automower 315X", "Automower", "315X"),
207+
("Husqvarna Automower® 435 AWD", "Automower", "435 AWD"),
208+
("Husqvarna CEORA® 544 EPOS", "Ceora", "544 EPOS"),
209+
],
210+
)
211+
async def test_model_id_information(
212+
hass: HomeAssistant,
213+
mock_config_entry: MockConfigEntry,
214+
mock_automower_client: AsyncMock,
215+
device_registry: dr.DeviceRegistry,
216+
values: dict[str, MowerAttributes],
217+
api_input: str,
218+
model: str,
219+
model_id: str,
220+
) -> None:
221+
"""Test model and model_id parsing."""
222+
values[TEST_MOWER_ID].system.model = api_input
223+
mock_config_entry.add_to_hass(hass)
224+
await hass.config_entries.async_setup(mock_config_entry.entry_id)
225+
await hass.async_block_till_done()
226+
reg_device = device_registry.async_get_device(
227+
identifiers={(DOMAIN, TEST_MOWER_ID)},
228+
)
229+
assert reg_device is not None
230+
assert reg_device.manufacturer == "Husqvarna"
231+
assert reg_device.model == model
232+
assert reg_device.model_id == model_id
233+
234+
202235
async def test_device_info(
203236
hass: HomeAssistant,
204237
mock_automower_client: AsyncMock,
205238
mock_config_entry: MockConfigEntry,
206239
device_registry: dr.DeviceRegistry,
207240
snapshot: SnapshotAssertion,
208241
) -> None:
209-
"""Test select platform."""
242+
"""Test device info."""
210243

211244
mock_config_entry.add_to_hass(hass)
212245
await hass.config_entries.async_setup(mock_config_entry.entry_id)

0 commit comments

Comments
 (0)