From 43618effb8cda697072988599de8470d7bc039cd Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 7 Aug 2026 13:49:00 +0200 Subject: [PATCH] Migrate calls to async_get_device in tests (part 6) (#178339) --- .../vodafone_station/test_coordinator.py | 5 ++- tests/components/voip/test_devices.py | 28 ++++++++------ tests/components/waqi/test_init.py | 25 ++++++++---- tests/components/watts/test_init.py | 28 ++++++++------ .../components/webostv/test_device_trigger.py | 12 ++++-- tests/components/webostv/test_media_player.py | 8 +++- tests/components/webostv/test_trigger.py | 6 ++- tests/components/wiim/test_entity.py | 4 +- tests/components/withings/test_init.py | 4 +- tests/components/withings/test_sensor.py | 10 +++-- tests/components/wmspro/test_cover.py | 4 +- tests/components/wmspro/test_light.py | 4 +- tests/components/wmspro/test_scene.py | 4 +- tests/components/wmspro/test_switch.py | 4 +- tests/components/wolflink/test_init.py | 8 +++- tests/components/wolflink/test_sensor.py | 4 +- tests/components/wyoming/test_devices.py | 4 +- tests/components/xbox/test_init.py | 36 +++++++++++++++--- .../xiaomi_ble/test_device_trigger.py | 36 +++++++++++++----- tests/components/xthings_cloud/test_init.py | 4 +- tests/components/yale/test_binary_sensor.py | 6 ++- tests/components/yale/test_lock.py | 6 +-- .../components/yolink/test_device_trigger.py | 4 +- tests/components/yoto/test_init.py | 12 +++++- tests/components/youtube/test_init.py | 4 +- .../components/zeversolar/test_diagnostics.py | 4 +- tests/components/zha/test_device_action.py | 16 ++++++-- tests/components/zha/test_device_trigger.py | 38 +++++++++++-------- tests/components/zha/test_diagnostics.py | 4 +- tests/components/zha/test_logbook.py | 8 +++- tests/components/zha/test_update.py | 10 +++-- .../zwave_me/test_remove_stale_devices.py | 13 +++---- tests/helpers/test_entity.py | 4 +- tests/helpers/test_entity_platform.py | 24 ++++++++---- 34 files changed, 265 insertions(+), 126 deletions(-) diff --git a/tests/components/vodafone_station/test_coordinator.py b/tests/components/vodafone_station/test_coordinator.py index c119184d3cc1..f235f747fe65 100644 --- a/tests/components/vodafone_station/test_coordinator.py +++ b/tests/components/vodafone_station/test_coordinator.py @@ -66,7 +66,10 @@ async def test_coordinator_device_cleanup( assert f"Skipping entity {DEVICE_2_HOST}" in caplog.text assert ( - device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_1_MAC)}) is None + device_registry.async_get_device_by_identifier( + (DOMAIN, DEVICE_1_MAC), mock_config_entry.entry_id + ) + is None ) assert f"Removing device: {DEVICE_1_HOST}" in caplog.text diff --git a/tests/components/voip/test_devices.py b/tests/components/voip/test_devices.py index 2771ab7d66c3..bf1b2a38ed48 100644 --- a/tests/components/voip/test_devices.py +++ b/tests/components/voip/test_devices.py @@ -20,13 +20,14 @@ async def test_device_registry_info( voip_devices: VoIPDevices, call_info: CallInfo, device_registry: dr.DeviceRegistry, + config_entry: MockConfigEntry, ) -> None: """Test info in device registry.""" voip_device = voip_devices.async_get_or_create(call_info) assert not voip_device.async_allow_call(hass) - device = device_registry.async_get_device( - identifiers={(DOMAIN, call_info.caller_endpoint.uri)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, call_info.caller_endpoint.uri), config_entry.entry_id ) assert device is not None assert device.name == call_info.caller_endpoint.host @@ -40,8 +41,8 @@ async def test_device_registry_info( assert not voip_device.async_allow_call(hass) - device = device_registry.async_get_device( - identifiers={(DOMAIN, call_info.caller_endpoint.uri)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, call_info.caller_endpoint.uri), config_entry.entry_id ) assert device.sw_version == "2.0.0.0" @@ -51,14 +52,15 @@ async def test_device_registry_info_from_unknown_phone( voip_devices: VoIPDevices, call_info: CallInfo, device_registry: dr.DeviceRegistry, + config_entry: MockConfigEntry, ) -> None: """Test info in device registry from unknown phone.""" call_info.headers["user-agent"] = "Unknown" voip_device = voip_devices.async_get_or_create(call_info) assert not voip_device.async_allow_call(hass) - device = device_registry.async_get_device( - identifiers={(DOMAIN, call_info.caller_endpoint.uri)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, call_info.caller_endpoint.uri), config_entry.entry_id ) assert device.manufacturer is None assert device.model == "Unknown" @@ -70,13 +72,14 @@ async def test_device_registry_info_update_contact( voip_devices: VoIPDevices, call_info: CallInfo, device_registry: dr.DeviceRegistry, + config_entry: MockConfigEntry, ) -> None: """Test info in device registry.""" voip_device = voip_devices.async_get_or_create(call_info) assert not voip_device.async_allow_call(hass) - device = device_registry.async_get_device( - identifiers={(DOMAIN, call_info.caller_endpoint.uri)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, call_info.caller_endpoint.uri), config_entry.entry_id ) assert device is not None assert device.name == call_info.caller_endpoint.host @@ -92,8 +95,8 @@ async def test_device_registry_info_update_contact( assert voip_device.contact == SipEndpoint("Test ") assert not voip_device.async_allow_call(hass) - device = device_registry.async_get_device( - identifiers={(DOMAIN, call_info.caller_endpoint.uri)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, call_info.caller_endpoint.uri), config_entry.entry_id ) assert device.sw_version == "2.0.0.0" @@ -179,13 +182,16 @@ async def test_device_registry_migration( call_info: CallInfo, entity_registry: er.EntityRegistry, device_registry: dr.DeviceRegistry, + config_entry: MockConfigEntry, ) -> None: """Test info in device registry migrates old devices.""" voip_device = voip_devices.async_get_or_create(call_info) new_id = call_info.caller_endpoint.uri assert voip_device.voip_id == new_id - device = device_registry.async_get_device(identifiers={(DOMAIN, new_id)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, new_id), config_entry.entry_id + ) assert device is not None assert device.id == legacy_dev_reg_entry.id assert device.identifiers == {(DOMAIN, new_id)} diff --git a/tests/components/waqi/test_init.py b/tests/components/waqi/test_init.py index fd35031fc0c1..92adbf32b6fa 100644 --- a/tests/components/waqi/test_init.py +++ b/tests/components/waqi/test_init.py @@ -111,7 +111,11 @@ async def test_migration_from_v1( assert entity.config_subentry_id == subentry.subentry_id assert entity.config_entry_id == entry.entry_id - assert (device := device_registry.async_get_device(identifiers={(DOMAIN, "4584")})) + assert ( + device := device_registry.async_get_device_by_identifier( + (DOMAIN, "4584"), mock_config_entry.entry_id + ) + ) assert device.identifiers == {(DOMAIN, "4584")} assert device.id == device_1.id assert device.config_entries == {mock_config_entry.entry_id} @@ -129,7 +133,11 @@ async def test_migration_from_v1( assert entity.unique_id == "4585_air_quality" assert entity.config_subentry_id == subentry.subentry_id assert entity.config_entry_id == entry.entry_id - assert (device := device_registry.async_get_device(identifiers={(DOMAIN, "4585")})) + assert ( + device := device_registry.async_get_device_by_identifier( + (DOMAIN, "4585"), mock_config_entry.entry_id + ) + ) assert device.identifiers == {(DOMAIN, "4585")} assert device.id == device_2.id assert device.config_entries == {mock_config_entry.entry_id} @@ -315,11 +323,11 @@ async def test_migration_from_v1_disabled( assert subentry.data == {CONF_STATION_NUMBER: int(subentry.unique_id)} assert "de Jongweg" in subentry.title - assert not device_registry.async_get_device( - identifiers={(DOMAIN, mock_config_entry.entry_id)} + assert not device_registry.async_get_device_by_identifier( + (DOMAIN, mock_config_entry.entry_id), mock_config_entry.entry_id ) - assert not device_registry.async_get_device( - identifiers={(DOMAIN, mock_config_entry_2.entry_id)} + assert not device_registry.async_get_device_by_identifier( + (DOMAIN, mock_config_entry_2.entry_id), mock_config_entry_2.entry_id ) for idx, subentry in enumerate(station_subentries): @@ -331,8 +339,9 @@ async def test_migration_from_v1_disabled( assert entity.disabled_by is subentry_data["entity_disabled_by"] assert ( - device := device_registry.async_get_device( - identifiers={(DOMAIN, subentry.unique_id)} + device := device_registry.async_get_device_by_identifier( + (DOMAIN, subentry.unique_id), + mock_config_entries[main_config_entry].entry_id, ) ) assert device.identifiers == {(DOMAIN, subentry.unique_id)} diff --git a/tests/components/watts/test_init.py b/tests/components/watts/test_init.py index 2044e5cedd23..41fa0aa1cdb0 100644 --- a/tests/components/watts/test_init.py +++ b/tests/components/watts/test_init.py @@ -203,10 +203,16 @@ async def test_dynamic_device_creation( """Test new devices are created dynamically.""" await setup_integration(hass, mock_config_entry) - assert device_registry.async_get_device(identifiers={(DOMAIN, "thermostat_123")}) - assert device_registry.async_get_device(identifiers={(DOMAIN, "thermostat_456")}) + assert device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_123"), mock_config_entry.entry_id + ) + assert device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_456"), mock_config_entry.entry_id + ) assert ( - device_registry.async_get_device(identifiers={(DOMAIN, "thermostat_789")}) + device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_789"), mock_config_entry.entry_id + ) is None ) @@ -234,8 +240,8 @@ async def test_dynamic_device_creation( async_fire_time_changed(hass) await hass.async_block_till_done() - new_device_entry = device_registry.async_get_device( - identifiers={(DOMAIN, "thermostat_789")} + new_device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_789"), mock_config_entry.entry_id ) assert new_device_entry is not None assert new_device_entry.name == "Kitchen Thermostat" @@ -254,11 +260,11 @@ async def test_stale_device_removal( """Test stale devices are removed dynamically.""" await setup_integration(hass, mock_config_entry) - device_123 = device_registry.async_get_device( - identifiers={(DOMAIN, "thermostat_123")} + device_123 = device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_123"), mock_config_entry.entry_id ) - device_456 = device_registry.async_get_device( - identifiers={(DOMAIN, "thermostat_456")} + device_456 = device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_456"), mock_config_entry.entry_id ) assert device_123 is not None assert device_456 is not None @@ -275,8 +281,8 @@ async def test_stale_device_removal( await hass.async_block_till_done() # Verify thermostat_456 has been removed - device_456_after_removal = device_registry.async_get_device( - identifiers={(DOMAIN, "thermostat_456")} + device_456_after_removal = device_registry.async_get_device_by_identifier( + (DOMAIN, "thermostat_456"), mock_config_entry.entry_id ) assert device_456_after_removal is None diff --git a/tests/components/webostv/test_device_trigger.py b/tests/components/webostv/test_device_trigger.py index 75ba4b0d4788..4c96c77b2be6 100644 --- a/tests/components/webostv/test_device_trigger.py +++ b/tests/components/webostv/test_device_trigger.py @@ -24,9 +24,11 @@ async def test_get_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, client ) -> None: """Test we get the expected triggers.""" - await setup_webostv(hass) + entry = await setup_webostv(hass) - device = device_registry.async_get_device(identifiers={(DOMAIN, FAKE_UUID)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, FAKE_UUID), entry.entry_id + ) turn_on_trigger = { "platform": "device", @@ -49,9 +51,11 @@ async def test_if_fires_on_turn_on_request( client, ) -> None: """Test for turn_on and turn_off triggers firing.""" - await setup_webostv(hass) + entry = await setup_webostv(hass) - device = device_registry.async_get_device(identifiers={(DOMAIN, FAKE_UUID)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, FAKE_UUID), entry.entry_id + ) assert await async_setup_component( hass, diff --git a/tests/components/webostv/test_media_player.py b/tests/components/webostv/test_media_player.py index 9217b7e6f00b..5e541e5b3205 100644 --- a/tests/components/webostv/test_media_player.py +++ b/tests/components/webostv/test_media_player.py @@ -324,7 +324,9 @@ async def test_device_info_startup_off( assert hass.states.get(ENTITY_ID).state == STATE_OFF - device = device_registry.async_get_device(identifiers={(DOMAIN, entry.unique_id)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, entry.unique_id), entry.entry_id + ) assert device assert device.identifiers == {(DOMAIN, entry.unique_id)} @@ -363,7 +365,9 @@ async def test_entity_attributes( assert attrs[ATTR_MEDIA_TITLE] == "Channel Name 2" # Device Info - device = device_registry.async_get_device(identifiers={(DOMAIN, entry.unique_id)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, entry.unique_id), entry.entry_id + ) assert device == snapshot # Sound output when off diff --git a/tests/components/webostv/test_trigger.py b/tests/components/webostv/test_trigger.py index 646b8f8034ae..b3d759e7ee41 100644 --- a/tests/components/webostv/test_trigger.py +++ b/tests/components/webostv/test_trigger.py @@ -25,9 +25,11 @@ async def test_webostv_turn_on_trigger_device_id( client, ) -> None: """Test for turn_on triggers by device_id firing.""" - await setup_webostv(hass) + entry = await setup_webostv(hass) - device = device_registry.async_get_device(identifiers={(DOMAIN, FAKE_UUID)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, FAKE_UUID), entry.entry_id + ) assert await async_setup_component( hass, diff --git a/tests/components/wiim/test_entity.py b/tests/components/wiim/test_entity.py index f7bf17d085dc..79110c607232 100644 --- a/tests/components/wiim/test_entity.py +++ b/tests/components/wiim/test_entity.py @@ -25,8 +25,8 @@ async def test_device_info_uses_http_api_url( await setup_integration(hass, mock_config_entry) - device_entry = device_registry.async_get_device( - identifiers={(DOMAIN, mock_wiim_device.udn)} + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, mock_wiim_device.udn), mock_config_entry.entry_id ) assert device_entry is not None assert device_entry.configuration_url == mock_wiim_device.http_api_url diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index 63c50983ae9b..1a69cc74786d 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -710,7 +710,9 @@ async def test_devices( await hass.async_block_till_done() for device_id in ("12345", "f998be4b9ccc9e136fd8cd8e8e344c31ec3b271d"): - device = device_registry.async_get_device({(DOMAIN, device_id)}) + device = device_registry.async_get_device_by_identifier( + (DOMAIN, device_id), webhook_config_entry.entry_id + ) assert device is not None assert device == snapshot(name=device_id) diff --git a/tests/components/withings/test_sensor.py b/tests/components/withings/test_sensor.py index 0a44756f8f4a..718ca42b4ca6 100644 --- a/tests/components/withings/test_sensor.py +++ b/tests/components/withings/test_sensor.py @@ -397,8 +397,9 @@ async def test_device_sensors_created_when_device_data_received( await hass.async_block_till_done() assert hass.states.get("sensor.body_battery") - assert device_registry.async_get_device( - {(DOMAIN, "f998be4b9ccc9e136fd8cd8e8e344c31ec3b271d")} + assert device_registry.async_get_device_by_identifier( + (DOMAIN, "f998be4b9ccc9e136fd8cd8e8e344c31ec3b271d"), + polling_config_entry.entry_id, ) withings.get_devices.return_value = [] @@ -408,8 +409,9 @@ async def test_device_sensors_created_when_device_data_received( await hass.async_block_till_done() assert hass.states.get("sensor.body_battery") is None - assert not device_registry.async_get_device( - {(DOMAIN, "f998be4b9ccc9e136fd8cd8e8e344c31ec3b271d")} + assert not device_registry.async_get_device_by_identifier( + (DOMAIN, "f998be4b9ccc9e136fd8cd8e8e344c31ec3b271d"), + polling_config_entry.entry_id, ) diff --git a/tests/components/wmspro/test_cover.py b/tests/components/wmspro/test_cover.py index c47c6eef7c32..22bc1f045dcc 100644 --- a/tests/components/wmspro/test_cover.py +++ b/tests/components/wmspro/test_cover.py @@ -56,7 +56,9 @@ async def test_cover_device( assert len(mock_hub_configuration.mock_calls) == 1 assert len(mock_hub_status.mock_calls) == len(mock_hub_configuration.destinations) - device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "58717")}) + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, "58717"), mock_config_entry.entry_id + ) assert device_entry is not None assert device_entry == snapshot diff --git a/tests/components/wmspro/test_light.py b/tests/components/wmspro/test_light.py index cc91385e9664..aaf8ea1f0549 100644 --- a/tests/components/wmspro/test_light.py +++ b/tests/components/wmspro/test_light.py @@ -44,7 +44,9 @@ async def test_light_device( assert len(mock_hub_configuration.mock_calls) == 1 assert len(mock_hub_status.mock_calls) == len(mock_hub_configuration.destinations) - device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "97358")}) + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, "97358"), mock_config_entry.entry_id + ) assert device_entry is not None assert device_entry == snapshot diff --git a/tests/components/wmspro/test_scene.py b/tests/components/wmspro/test_scene.py index 7a65e39f1946..a28ea911c499 100644 --- a/tests/components/wmspro/test_scene.py +++ b/tests/components/wmspro/test_scene.py @@ -36,7 +36,9 @@ async def test_scene_room_device( assert len(mock_hub_configuration.mock_calls) == 1 assert len(mock_dest_refresh.mock_calls) == 2 - device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "42581")}) + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, "42581"), mock_config_entry.entry_id + ) assert device_entry is not None assert device_entry == snapshot diff --git a/tests/components/wmspro/test_switch.py b/tests/components/wmspro/test_switch.py index 818c74818910..af4d7b5748cf 100644 --- a/tests/components/wmspro/test_switch.py +++ b/tests/components/wmspro/test_switch.py @@ -44,7 +44,9 @@ async def test_switch_device( assert len(mock_hub_configuration.mock_calls) == 1 assert len(mock_hub_status.mock_calls) == len(mock_hub_configuration.destinations) - device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "499120")}) + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, "499120"), mock_config_entry.entry_id + ) assert device_entry is not None assert device_entry == snapshot diff --git a/tests/components/wolflink/test_init.py b/tests/components/wolflink/test_init.py index b8632bc5c33e..a01af2871b30 100644 --- a/tests/components/wolflink/test_init.py +++ b/tests/components/wolflink/test_init.py @@ -393,8 +393,12 @@ async def test_setup_multiple_devices( await setup_integration(hass, mock_config_entry) # Both devices must appear in the device registry. - first = device_registry.async_get_device({(DOMAIN, "1234")}) - second = device_registry.async_get_device({(DOMAIN, "9999")}) + first = device_registry.async_get_device_by_identifier( + (DOMAIN, "1234"), mock_config_entry.entry_id + ) + second = device_registry.async_get_device_by_identifier( + (DOMAIN, "9999"), mock_config_entry.entry_id + ) assert first is not None assert second is not None assert first.name == "first-device" diff --git a/tests/components/wolflink/test_sensor.py b/tests/components/wolflink/test_sensor.py index 06c50fc3c598..5459f87178b8 100644 --- a/tests/components/wolflink/test_sensor.py +++ b/tests/components/wolflink/test_sensor.py @@ -24,7 +24,9 @@ async def test_device_entry( await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - device = device_registry.async_get_device({(mock_config_entry.domain, "1234")}) + device = device_registry.async_get_device_by_identifier( + (mock_config_entry.domain, "1234"), mock_config_entry.entry_id + ) assert device == snapshot diff --git a/tests/components/wyoming/test_devices.py b/tests/components/wyoming/test_devices.py index d7cba133c2cb..24c6480a1231 100644 --- a/tests/components/wyoming/test_devices.py +++ b/tests/components/wyoming/test_devices.py @@ -20,8 +20,8 @@ async def test_device_registry_info( # Satellite uses config entry id since only one satellite per entry is # supported. - device = device_registry.async_get_device( - identifiers={(DOMAIN, satellite_config_entry.entry_id)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, satellite_config_entry.entry_id), satellite_config_entry.entry_id ) assert device is not None assert device.name == "Test Satellite" diff --git a/tests/components/xbox/test_init.py b/tests/components/xbox/test_init.py index e0cee16cb8dc..469a96b6f2b6 100644 --- a/tests/components/xbox/test_init.py +++ b/tests/components/xbox/test_init.py @@ -219,8 +219,18 @@ async def test_dynamic_devices( assert config_entry.state is ConfigEntryState.LOADED - assert device_registry.async_get_device({(DOMAIN, "ABCDEFG")}) is None - assert device_registry.async_get_device({(DOMAIN, "HIJKLMN")}) is None + assert ( + device_registry.async_get_device_by_identifier( + (DOMAIN, "ABCDEFG"), config_entry.entry_id + ) + is None + ) + assert ( + device_registry.async_get_device_by_identifier( + (DOMAIN, "HIJKLMN"), config_entry.entry_id + ) + is None + ) xbox_live_client.smartglass.get_console_list.return_value = SmartglassConsoleList( **await async_load_json_object_fixture( @@ -232,8 +242,12 @@ async def test_dynamic_devices( async_fire_time_changed(hass) await hass.async_block_till_done() - assert device_registry.async_get_device({(DOMAIN, "ABCDEFG")}) - assert device_registry.async_get_device({(DOMAIN, "HIJKLMN")}) + assert device_registry.async_get_device_by_identifier( + (DOMAIN, "ABCDEFG"), config_entry.entry_id + ) + assert device_registry.async_get_device_by_identifier( + (DOMAIN, "HIJKLMN"), config_entry.entry_id + ) xbox_live_client.smartglass.get_console_list.return_value = SmartglassConsoleList( **await async_load_json_object_fixture( @@ -245,5 +259,15 @@ async def test_dynamic_devices( async_fire_time_changed(hass) await hass.async_block_till_done() - assert device_registry.async_get_device({(DOMAIN, "ABCDEFG")}) is None - assert device_registry.async_get_device({(DOMAIN, "HIJKLMN")}) is None + assert ( + device_registry.async_get_device_by_identifier( + (DOMAIN, "ABCDEFG"), config_entry.entry_id + ) + is None + ) + assert ( + device_registry.async_get_device_by_identifier( + (DOMAIN, "HIJKLMN"), config_entry.entry_id + ) + is None + ) diff --git a/tests/components/xiaomi_ble/test_device_trigger.py b/tests/components/xiaomi_ble/test_device_trigger.py index 2c0751bf56c6..19d45bac02a7 100644 --- a/tests/components/xiaomi_ble/test_device_trigger.py +++ b/tests/components/xiaomi_ble/test_device_trigger.py @@ -190,7 +190,9 @@ async def test_get_triggers_button( await hass.async_block_till_done() assert len(events) == 1 - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -231,7 +233,9 @@ async def test_get_triggers_double_button( await hass.async_block_till_done() assert len(events) == 1 - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -273,7 +277,9 @@ async def test_get_triggers_lock( await hass.async_block_till_done() assert len(events) == 1 - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -310,7 +316,9 @@ async def test_get_triggers_motion( await hass.async_block_till_done() assert len(events) == 1 - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -413,7 +421,9 @@ async def test_if_fires_on_button_press( # wait for the device being created await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) device_id = device.id assert await async_setup_component( @@ -476,7 +486,9 @@ async def test_if_fires_on_double_button_long_press( # wait for the device being created await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) device_id = device.id assert await async_setup_component( @@ -535,7 +547,9 @@ async def test_if_fires_on_motion_detected( # wait for the device being created await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) device_id = device.id assert await async_setup_component( @@ -591,7 +605,9 @@ async def test_automation_with_invalid_trigger_type( # wait for the event await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) device_id = device.id assert await async_setup_component( @@ -640,7 +656,9 @@ async def test_automation_with_invalid_trigger_event_property( # wait for the event await hass.async_block_till_done() - device = device_registry.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device_by_identifier( + get_device_id(mac), entry.entry_id + ) device_id = device.id assert await async_setup_component( diff --git a/tests/components/xthings_cloud/test_init.py b/tests/components/xthings_cloud/test_init.py index 9210a062c085..f7dfbe22adf2 100644 --- a/tests/components/xthings_cloud/test_init.py +++ b/tests/components/xthings_cloud/test_init.py @@ -24,7 +24,9 @@ async def test_devices( await setup_integration(hass, mock_config_entry) for device in mock_api_client.async_get_devices.return_value: - device_entry = device_registry.async_get_device({(DOMAIN, device["id"])}) + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, device["id"]), mock_config_entry.entry_id + ) assert device_entry is not None assert device_entry == snapshot(name=device["model"]) diff --git a/tests/components/yale/test_binary_sensor.py b/tests/components/yale/test_binary_sensor.py index 61416f44cac3..4bf76dd06ef5 100644 --- a/tests/components/yale/test_binary_sensor.py +++ b/tests/components/yale/test_binary_sensor.py @@ -309,9 +309,11 @@ async def test_doorbell_device_registry( ) -> None: """Test creation of a lock with doorsense and bridge ands up in the registry.""" doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json") - await _create_yale_with_devices(hass, [doorbell_one]) + config_entry, _ = await _create_yale_with_devices(hass, [doorbell_one]) - reg_device = device_registry.async_get_device(identifiers={("yale", "tmt100")}) + reg_device = device_registry.async_get_device_by_identifier( + ("yale", "tmt100"), config_entry.entry_id + ) assert reg_device == snapshot diff --git a/tests/components/yale/test_lock.py b/tests/components/yale/test_lock.py index ad5c5cd66732..684fae858836 100644 --- a/tests/components/yale/test_lock.py +++ b/tests/components/yale/test_lock.py @@ -40,10 +40,10 @@ async def test_lock_device_registry( ) -> None: """Test creation of a lock with doorsense and bridge ands up in the registry.""" lock_one = await _mock_doorsense_enabled_yale_lock_detail(hass) - await _create_yale_with_devices(hass, [lock_one]) + entry, _ = await _create_yale_with_devices(hass, [lock_one]) - reg_device = device_registry.async_get_device( - identifiers={("yale", "online_with_doorsense")} + reg_device = device_registry.async_get_device_by_identifier( + ("yale", "online_with_doorsense"), entry.entry_id ) assert reg_device == snapshot diff --git a/tests/components/yolink/test_device_trigger.py b/tests/components/yolink/test_device_trigger.py index c82c507940c8..2c526dd28c91 100644 --- a/tests/components/yolink/test_device_trigger.py +++ b/tests/components/yolink/test_device_trigger.py @@ -150,7 +150,9 @@ async def test_if_fires_on_event( }, ) - device = device_registry.async_get_device(connections={connection}) + device = device_registry.async_get_device_by_connection( + connection, config_entry.entry_id + ) assert device is not None # Fake remote button long press. hass.bus.async_fire( diff --git a/tests/components/yoto/test_init.py b/tests/components/yoto/test_init.py index 8fc92e4b7c4f..3f5ca9ba284e 100644 --- a/tests/components/yoto/test_init.py +++ b/tests/components/yoto/test_init.py @@ -397,7 +397,10 @@ async def test_stale_device_removed( """A player removed from the account has its device dropped.""" await setup_integration(hass, mock_config_entry) assert ( - device_registry.async_get_device(identifiers={(DOMAIN, PLAYER_ID)}) is not None + device_registry.async_get_device_by_identifier( + (DOMAIN, PLAYER_ID), mock_config_entry.entry_id + ) + is not None ) mock_yoto_client.players.clear() @@ -405,5 +408,10 @@ async def test_stale_device_removed( async_fire_time_changed(hass) await hass.async_block_till_done() - assert device_registry.async_get_device(identifiers={(DOMAIN, PLAYER_ID)}) is None + assert ( + device_registry.async_get_device_by_identifier( + (DOMAIN, PLAYER_ID), mock_config_entry.entry_id + ) + is None + ) mock_yoto_client.unsubscribe_player_events.assert_called_once_with(PLAYER_ID) diff --git a/tests/components/youtube/test_init.py b/tests/components/youtube/test_init.py index a7d2639902c5..bbcb86fc424e 100644 --- a/tests/components/youtube/test_init.py +++ b/tests/components/youtube/test_init.py @@ -130,8 +130,8 @@ async def test_device_info( entry = hass.config_entries.async_entries(DOMAIN)[0] channel_id = entry.options[CONF_CHANNELS][0] - device = device_registry.async_get_device( - identifiers={(DOMAIN, f"{entry.entry_id}_{channel_id}")} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, f"{entry.entry_id}_{channel_id}"), entry.entry_id ) assert device.entry_type is dr.DeviceEntryType.SERVICE diff --git a/tests/components/zeversolar/test_diagnostics.py b/tests/components/zeversolar/test_diagnostics.py index 384a8f7a42dc..6b12fe709dcc 100644 --- a/tests/components/zeversolar/test_diagnostics.py +++ b/tests/components/zeversolar/test_diagnostics.py @@ -37,8 +37,8 @@ async def test_device_diagnostics( init_integration: MockConfigEntry, ) -> None: """Test device diagnostics.""" - device = device_registry.async_get_device( - identifiers={(DOMAIN, MOCK_SERIAL_NUMBER)} + device = device_registry.async_get_device_by_identifier( + (DOMAIN, MOCK_SERIAL_NUMBER), init_integration.entry_id ) assert ( diff --git a/tests/components/zha/test_device_action.py b/tests/components/zha/test_device_action.py index 05211ce4ceee..3309292f4280 100644 --- a/tests/components/zha/test_device_action.py +++ b/tests/components/zha/test_device_action.py @@ -21,7 +21,11 @@ from homeassistant.setup import async_setup_component from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE -from tests.common import async_get_device_automations, async_mock_service +from tests.common import ( + MockConfigEntry, + async_get_device_automations, + async_mock_service, +) SHORT_PRESS = "remote_button_short_press" COMMAND = "command" @@ -52,6 +56,7 @@ async def test_get_actions( hass: HomeAssistant, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, + config_entry: MockConfigEntry, setup_zha: Callable[..., Coroutine[None]], zigpy_device_mock: Callable[..., Device], ) -> None: @@ -80,7 +85,9 @@ async def test_get_actions( await hass.async_block_till_done(wait_background_tasks=True) ieee_address = str(zigpy_device.ieee) - reg_device = device_registry.async_get_device(identifiers={(DOMAIN, ieee_address)}) + reg_device = device_registry.async_get_device_by_identifier( + (DOMAIN, ieee_address), config_entry.entry_id + ) siren_level_select = entity_registry.async_get( "select.fakemanufacturer_fakemodel_default_siren_level" ) @@ -138,6 +145,7 @@ async def test_get_actions( async def test_action( hass: HomeAssistant, device_registry: dr.DeviceRegistry, + config_entry: MockConfigEntry, setup_zha: Callable[..., Coroutine[None]], zigpy_device_mock: Callable[..., Device], ) -> None: @@ -168,7 +176,9 @@ async def test_action( await hass.async_block_till_done(wait_background_tasks=True) ieee_address = str(zigpy_device.ieee) - reg_device = device_registry.async_get_device(identifiers={(DOMAIN, ieee_address)}) + reg_device = device_registry.async_get_device_by_identifier( + (DOMAIN, ieee_address), config_entry.entry_id + ) with patch( "zigpy.zcl.Cluster.request", diff --git a/tests/components/zha/test_device_trigger.py b/tests/components/zha/test_device_trigger.py index 6afe6d063931..36934ff5d656 100644 --- a/tests/components/zha/test_device_trigger.py +++ b/tests/components/zha/test_device_trigger.py @@ -79,8 +79,9 @@ async def test_triggers( await gateway.async_device_initialized(zha_device.device) await hass.async_block_till_done(wait_background_tasks=True) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) triggers = await async_get_device_automations( @@ -160,8 +161,9 @@ async def test_no_triggers( await gateway.async_device_initialized(zha_device.device) await hass.async_block_till_done(wait_background_tasks=True) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) triggers = await async_get_device_automations( @@ -211,8 +213,9 @@ async def test_if_fires_on_event( await gateway.async_device_initialized(zha_device.device) await hass.async_block_till_done(wait_background_tasks=True) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) assert await async_setup_component( @@ -276,8 +279,9 @@ async def test_device_offline_fires( await gateway.async_device_initialized(zha_device.device) await hass.async_block_till_done(wait_background_tasks=True) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) assert await async_setup_component( @@ -332,8 +336,9 @@ async def test_exception_no_triggers( await gateway.async_device_initialized(zha_device.device) await hass.async_block_till_done(wait_background_tasks=True) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) await async_setup_component( @@ -392,8 +397,9 @@ async def test_exception_bad_trigger( await gateway.async_device_initialized(zha_device.device) await hass.async_block_till_done(wait_background_tasks=True) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) await async_setup_component( @@ -457,8 +463,8 @@ async def test_validate_trigger_config_missing_info( # it be pulled from the current device, making it impossible to validate triggers await hass.config_entries.async_unload(config_entry.entry_id) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), config_entry.entry_id ) assert await async_setup_component( @@ -532,8 +538,8 @@ async def test_validate_trigger_config_unloaded_bad_info( await hass.config_entries.async_unload(config_entry.entry_id) - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.ieee)), config_entry.entry_id ) assert await async_setup_component( diff --git a/tests/components/zha/test_diagnostics.py b/tests/components/zha/test_diagnostics.py index 55828532384e..72bdaec48367 100644 --- a/tests/components/zha/test_diagnostics.py +++ b/tests/components/zha/test_diagnostics.py @@ -129,8 +129,8 @@ async def test_diagnostics_for_device( security.IasZone.AttributeDefs.current_zone_sensitivity_level ) - device = device_registry.async_get_device( - identifiers={("zha", str(zha_device_proxy.device.ieee))} + device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device_proxy.device.ieee)), config_entry.entry_id ) assert device diagnostics_data = await get_diagnostics_for_device( diff --git a/tests/components/zha/test_logbook.py b/tests/components/zha/test_logbook.py index 4a4fc5caf545..a1d8953f3c27 100644 --- a/tests/components/zha/test_logbook.py +++ b/tests/components/zha/test_logbook.py @@ -98,7 +98,9 @@ async def test_zha_logbook_event_device_with_triggers( ieee_address = str(zha_device.device.ieee) - reg_device = device_registry.async_get_device(identifiers={("zha", ieee_address)}) + reg_device = device_registry.async_get_device_by_identifier( + ("zha", ieee_address), hass.config_entries.async_entries("zha")[0].entry_id + ) hass.config.components.add("recorder") assert await async_setup_component(hass, "logbook", {}) @@ -174,7 +176,9 @@ async def test_zha_logbook_event_device_no_triggers( _zigpy_device, zha_device = mock_devices ieee_address = str(zha_device.device.ieee) - reg_device = device_registry.async_get_device(identifiers={("zha", ieee_address)}) + reg_device = device_registry.async_get_device_by_identifier( + ("zha", ieee_address), hass.config_entries.async_entries("zha")[0].entry_id + ) hass.config.components.add("recorder") assert await async_setup_component(hass, "logbook", {}) diff --git a/tests/components/zha/test_update.py b/tests/components/zha/test_update.py index f5e30e84072d..d55bd8bd7f9d 100644 --- a/tests/components/zha/test_update.py +++ b/tests/components/zha/test_update.py @@ -715,13 +715,15 @@ async def test_update_version_sync_device_registry( zha_device, _, _, _ = await setup_test_data(hass, zigpy_device_mock) zha_device.device.async_update_firmware_version("0x12345678") - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) assert reg_device.sw_version == "0x12345678" zha_device.device.async_update_firmware_version("0xabcd1234") - reg_device = device_registry.async_get_device( - identifiers={("zha", str(zha_device.device.ieee))} + reg_device = device_registry.async_get_device_by_identifier( + ("zha", str(zha_device.device.ieee)), + hass.config_entries.async_entries("zha")[0].entry_id, ) assert reg_device.sw_version == "0xabcd1234" diff --git a/tests/components/zwave_me/test_remove_stale_devices.py b/tests/components/zwave_me/test_remove_stale_devices.py index 9f8607cf91e9..ae6c5dfff484 100644 --- a/tests/components/zwave_me/test_remove_stale_devices.py +++ b/tests/components/zwave_me/test_remove_stale_devices.py @@ -63,13 +63,12 @@ async def test_remove_stale_devices( await hass.config_entries.async_setup(config_entry.entry_id) assert ( bool( - device_registry.async_get_device( - identifiers={ - ( - "zwave_me", - f"{config_entry.unique_id}-{identifier}", - ) - } + device_registry.async_get_device_by_identifier( + ( + "zwave_me", + f"{config_entry.unique_id}-{identifier}", + ), + config_entry.entry_id, ) ) == should_exist diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index bf562c8c12be..1406a12206a2 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -1630,7 +1630,9 @@ async def test_friendly_name_updated( state = hass.states.async_all()[0] assert state.attributes.get(ATTR_FRIENDLY_NAME) == expected_friendly_name1 - device = device_registry.async_get_device(identifiers={("hue", "1234")}) + device = device_registry.async_get_device_by_identifier( + ("hue", "1234"), config_entry.entry_id + ) device_registry.async_update_device(device.id, name_by_user="Device Bla2") await hass.async_block_till_done() diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index acdb45687259..9d20a8770a42 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -1508,13 +1508,17 @@ async def test_device_info_called( assert len(hass.states.async_entity_ids()) == 3 - device = device_registry.async_get_device(identifiers={("hue", "1234")}) + device = device_registry.async_get_device_by_identifier( + ("hue", "1234"), config_entry.entry_id + ) assert device == snapshot assert device.config_entries == {config_entry.entry_id} assert device.config_entries_subentries == {config_entry.entry_id: {None}} assert device.primary_config_entry == config_entry.entry_id assert device.via_device_id == via.id - device = device_registry.async_get_device(identifiers={("hue", "efgh")}) + device = device_registry.async_get_device_by_identifier( + ("hue", "efgh"), config_entry.entry_id + ) assert device == snapshot assert device.config_entries == {config_entry.entry_id} assert device.config_entries_subentries == { @@ -1568,8 +1572,8 @@ async def test_device_info_not_overrides( assert await entity_platform.async_setup_entry(config_entry) await hass.async_block_till_done() - device2 = device_registry.async_get_device( - connections={(dr.CONNECTION_NETWORK_MAC, "abcd")} + device2 = device_registry.async_get_device_by_connection( + (dr.CONNECTION_NETWORK_MAC, "abcd"), config_entry.entry_id ) assert device2 is not None assert device.id == device2.id @@ -1622,7 +1626,9 @@ async def test_device_info_homeassistant_url( assert len(hass.states.async_entity_ids()) == 1 - device = device_registry.async_get_device(identifiers={("mqtt", "1234")}) + device = device_registry.async_get_device_by_identifier( + ("mqtt", "1234"), config_entry.entry_id + ) assert device is not None assert device.identifiers == {("mqtt", "1234")} assert device.configuration_url == "homeassistant://config/mqtt" @@ -1674,7 +1680,9 @@ async def test_device_info_change_to_no_url( assert len(hass.states.async_entity_ids()) == 1 - device = device_registry.async_get_device(identifiers={("mqtt", "1234")}) + device = device_registry.async_get_device_by_identifier( + ("mqtt", "1234"), config_entry.entry_id + ) assert device is not None assert device.identifiers == {("mqtt", "1234")} assert device.configuration_url is None @@ -2762,8 +2770,8 @@ async def test_device_name_defaulting_config_entry( assert await entity_platform.async_setup_entry(config_entry) await hass.async_block_till_done() - device = device_registry.async_get_device( - connections={(dr.CONNECTION_NETWORK_MAC, "1234")} + device = device_registry.async_get_device_by_connection( + (dr.CONNECTION_NETWORK_MAC, "1234"), config_entry.entry_id ) assert device is not None assert device.name == expected_device_name