Handle intended via_device missing in tellduslive (#178178)

This commit is contained in:
Erik Montnemery
2026-08-05 10:03:17 +02:00
committed by GitHub
parent 67fd9c8baf
commit 7c508bea51
2 changed files with 38 additions and 5 deletions
@@ -121,10 +121,11 @@ class TelldusLiveEntity(Entity):
config_entry = self.platform.config_entry
if TYPE_CHECKING:
assert config_entry
# The hub is registered in async_new_client before entities are added.
device_info["via_device_id"] = dr.async_get_device_id_by_identifier(
self.hass,
(DOMAIN, client),
config_entry_id=config_entry.entry_id,
# The hub is not registered when fetching the client list failed while
# device requests succeeded, so link only when the hub device exists.
hub_device = dr.async_get(self.hass).async_get_device_by_identifier(
(DOMAIN, client), config_entry.entry_id
)
if hub_device is not None:
device_info["via_device_id"] = hub_device.id
return device_info
+32
View File
@@ -40,3 +40,35 @@ async def test_device_via_device_links(
assert child_device.via_device_id == hub_device.id
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
async def test_device_added_without_hub(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_config_entry: MockConfigEntry,
mock_tellduslive: MagicMock,
) -> None:
"""Test a device is still added, unlinked, when its hub is not registered."""
# A failed clients/list request yields an empty hub list, so no hub is registered.
mock_tellduslive.get_clients.return_value = []
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.data[NEW_CLIENT_TASK]
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.LOADED
assert (
device_registry.async_get_device_by_identifier(
(DOMAIN, HUB_ID), mock_config_entry.entry_id
)
is None
)
child_device = device_registry.async_get_device_by_identifier(
(DOMAIN, DEVICE_ID), mock_config_entry.entry_id
)
assert child_device is not None
assert child_device.via_device_id is None
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)