From 34ad44bdec2dcf077ddaaf7fe8aea19f39939fef Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sat, 8 Aug 2026 11:45:08 +0200 Subject: [PATCH] Migrate calls to async_get_device in tests (#178511) --- tests/components/fritz/test_coordinator.py | 4 +- tests/components/mqtt/test_device_trigger.py | 4 +- tests/components/mqtt/test_discovery.py | 44 +++++++++++++++----- tests/components/mqtt/test_tag.py | 4 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/tests/components/fritz/test_coordinator.py b/tests/components/fritz/test_coordinator.py index 9a12c4f1f21e..39eaf06a2a5e 100644 --- a/tests/components/fritz/test_coordinator.py +++ b/tests/components/fritz/test_coordinator.py @@ -724,8 +724,8 @@ async def test_old_discovery_does_not_self_reference_box( assert entry.state is ConfigEntryState.LOADED - router = device_registry.async_get_device( - identifiers={(DOMAIN, MOCK_SERIAL_NUMBER)} + router = device_registry.async_get_device_by_identifier( + (DOMAIN, MOCK_SERIAL_NUMBER), entry.entry_id ) assert router is not None assert router.via_device_id is None diff --git a/tests/components/mqtt/test_device_trigger.py b/tests/components/mqtt/test_device_trigger.py index 2f090ceda689..bd397c21f9e6 100644 --- a/tests/components/mqtt/test_device_trigger.py +++ b/tests/components/mqtt/test_device_trigger.py @@ -1348,7 +1348,9 @@ async def test_entity_device_info_with_via_device( async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data) await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")}) + device = device_registry.async_get_device_by_identifier( + ("mqtt", "helloworld"), mqtt_config_entry.entry_id + ) assert device is not None assert device.via_device_id == hub.id diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index f5ea13afda18..44d7de239222 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -3292,7 +3292,9 @@ async def test_discovery_with_late_via_device_discovery( # The child device links to the stub via device by via_device_id stub_id = via_device_entry.id - child_device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")}) + child_device_entry = device_registry.async_get_device_by_identifier( + ("mqtt", "0AFFD2"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert child_device_entry is not None assert child_device_entry.via_device_id == stub_id @@ -3321,7 +3323,9 @@ async def test_discovery_with_late_via_device_discovery( # The stub merges into the announced device, keeping its id, so the link # from the child device survives assert via_device_entry.id == stub_id - child_device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")}) + child_device_entry = device_registry.async_get_device_by_identifier( + ("mqtt", "0AFFD2"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert child_device_entry is not None assert child_device_entry.via_device_id == stub_id @@ -3384,7 +3388,9 @@ async def test_discovery_with_late_via_device_update( # The discovery update established the via_device_id link on the child device stub_id = via_device_entry.id - child_device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")}) + child_device_entry = device_registry.async_get_device_by_identifier( + ("mqtt", "0AFFD2"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert child_device_entry is not None assert child_device_entry.via_device_id == stub_id @@ -3411,7 +3417,9 @@ async def test_discovery_with_late_via_device_update( assert via_device_entry is not None assert via_device_entry.name == "My Switch" assert via_device_entry.id == stub_id - child_device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")}) + child_device_entry = device_registry.async_get_device_by_identifier( + ("mqtt", "0AFFD2"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert child_device_entry is not None assert child_device_entry.via_device_id == stub_id @@ -3447,8 +3455,12 @@ async def test_via_device_relinks_after_parent_removed( ) await hass.async_block_till_done() - parent = device_registry.async_get_device({("mqtt", "parent-id")}) - child = device_registry.async_get_device({("mqtt", "child-id")}) + parent = device_registry.async_get_device_by_identifier( + ("mqtt", "parent-id"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) + child = device_registry.async_get_device_by_identifier( + ("mqtt", "child-id"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert parent is not None assert child is not None assert child.via_device_id == parent.id @@ -3456,7 +3468,9 @@ async def test_via_device_relinks_after_parent_removed( # Removing the parent clears the child's via_device_id device_registry.async_remove_device(parent.id) await hass.async_block_till_done() - child = device_registry.async_get_device({("mqtt", "child-id")}) + child = device_registry.async_get_device_by_identifier( + ("mqtt", "child-id"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert child is not None assert child.via_device_id is None @@ -3467,8 +3481,12 @@ async def test_via_device_relinks_after_parent_removed( ) await hass.async_block_till_done() - parent_stub = device_registry.async_get_device({("mqtt", "parent-id")}) - child = device_registry.async_get_device({("mqtt", "child-id")}) + parent_stub = device_registry.async_get_device_by_identifier( + ("mqtt", "parent-id"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) + child = device_registry.async_get_device_by_identifier( + ("mqtt", "child-id"), hass.config_entries.async_entries("mqtt")[0].entry_id + ) assert parent_stub is not None assert child is not None assert child.via_device_id == parent_stub.id @@ -3496,7 +3514,9 @@ async def test_via_device_across_subentries( config_entry = hass.config_entries.async_entries(DOMAIN)[0] subentry_id = next(iter(config_entry.subentries)) - parent = device_registry.async_get_device({(DOMAIN, subentry_id)}) + parent = device_registry.async_get_device_by_identifier( + (DOMAIN, subentry_id), config_entry.entry_id + ) assert parent is not None assert parent.config_subentry_id == subentry_id @@ -3512,7 +3532,9 @@ async def test_via_device_across_subentries( ) await hass.async_block_till_done() - child = device_registry.async_get_device({(DOMAIN, "child-id")}) + child = device_registry.async_get_device_by_identifier( + (DOMAIN, "child-id"), config_entry.entry_id + ) assert child is not None # The parent lives in a subentry and the discovered child does not, yet the # link resolves because lookups are scoped to the config entry. diff --git a/tests/components/mqtt/test_tag.py b/tests/components/mqtt/test_tag.py index 0d6d0a4f888b..924bda3e909f 100644 --- a/tests/components/mqtt/test_tag.py +++ b/tests/components/mqtt/test_tag.py @@ -554,7 +554,9 @@ async def test_entity_device_info_with_via_device( async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data) await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")}) + device = device_registry.async_get_device_by_identifier( + ("mqtt", "helloworld"), mqtt_config_entry.entry_id + ) assert device is not None assert device.via_device_id == hub.id