diff --git a/tests/components/bayesian/test_binary_sensor.py b/tests/components/bayesian/test_binary_sensor.py index 8dedce0c297..aaade6da2f4 100644 --- a/tests/components/bayesian/test_binary_sensor.py +++ b/tests/components/bayesian/test_binary_sensor.py @@ -20,15 +20,16 @@ from homeassistant.const import ( STATE_UNKNOWN, ) from homeassistant.core import Context, HomeAssistant, callback -from homeassistant.helpers import issue_registry as ir -from homeassistant.helpers.entity_registry import async_get as async_get_entities +from homeassistant.helpers import entity_registry as er, issue_registry as ir from homeassistant.helpers.event import async_track_state_change_event from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_load_values_when_added_to_hass(hass: HomeAssistant) -> None: +async def test_load_values_when_added_to_hass( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test that sensor initializes with observations of relevant entities.""" config = { @@ -57,7 +58,6 @@ async def test_load_values_when_added_to_hass(hass: HomeAssistant) -> None: assert await async_setup_component(hass, "binary_sensor", config) await hass.async_block_till_done() - entity_registry = async_get_entities(hass) assert ( entity_registry.entities["binary_sensor.test_binary"].unique_id == "bayesian-3b4c9563-5e84-4167-8fe7-8f507e796d72" diff --git a/tests/components/bthome/test_device_trigger.py b/tests/components/bthome/test_device_trigger.py index 496f191c434..f847ffb9c0a 100644 --- a/tests/components/bthome/test_device_trigger.py +++ b/tests/components/bthome/test_device_trigger.py @@ -6,10 +6,7 @@ from homeassistant.components.bthome.const import CONF_SUBTYPE, DOMAIN from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE from homeassistant.core import HomeAssistant, ServiceCall, callback -from homeassistant.helpers.device_registry import ( - CONNECTION_NETWORK_MAC, - async_get as async_get_dev_reg, -) +from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component from . import make_bthome_v2_adv @@ -87,7 +84,9 @@ async def test_event_rotate_dimmer(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_button(hass: HomeAssistant) -> None: +async def test_get_triggers_button( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we get the expected triggers from a BTHome BLE sensor.""" mac = "A4:C1:38:8D:18:B2" entry = await _async_setup_bthome_device(hass, mac) @@ -103,8 +102,7 @@ async def test_get_triggers_button(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(events) == 1 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -123,7 +121,9 @@ async def test_get_triggers_button(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_dimmer(hass: HomeAssistant) -> None: +async def test_get_triggers_dimmer( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we get the expected triggers from a BTHome BLE sensor.""" mac = "A4:C1:38:8D:18:B2" entry = await _async_setup_bthome_device(hass, mac) @@ -139,8 +139,7 @@ async def test_get_triggers_dimmer(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(events) == 1 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -159,7 +158,9 @@ async def test_get_triggers_dimmer(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_for_invalid_bthome_ble_device(hass: HomeAssistant) -> None: +async def test_get_triggers_for_invalid_bthome_ble_device( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we don't get triggers for an invalid device.""" mac = "A4:C1:38:8D:18:B2" entry = await _async_setup_bthome_device(hass, mac) @@ -175,8 +176,7 @@ async def test_get_triggers_for_invalid_bthome_ble_device(hass: HomeAssistant) - await hass.async_block_till_done() assert len(events) == 0 - dev_reg = async_get_dev_reg(hass) - invalid_device = dev_reg.async_get_or_create( + invalid_device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, "invdevmac")}, ) @@ -190,7 +190,9 @@ async def test_get_triggers_for_invalid_bthome_ble_device(hass: HomeAssistant) - await hass.async_block_till_done() -async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None: +async def test_get_triggers_for_invalid_device_id( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we don't get triggers when using an invalid device_id.""" mac = "DE:70:E8:B2:39:0C" entry = await _async_setup_bthome_device(hass, mac) @@ -204,11 +206,9 @@ async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None: # wait for the event await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - - invalid_device = dev_reg.async_get_or_create( + invalid_device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, - connections={(CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, + connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, ) assert invalid_device triggers = await async_get_device_automations( @@ -221,7 +221,9 @@ async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None: async def test_if_fires_on_motion_detected( - hass: HomeAssistant, service_calls: list[ServiceCall] + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + service_calls: list[ServiceCall], ) -> None: """Test for motion event trigger firing.""" mac = "DE:70:E8:B2:39:0C" @@ -236,8 +238,7 @@ async def test_if_fires_on_motion_detected( # # wait for the event await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) device_id = device.id assert await async_setup_component( diff --git a/tests/components/buienradar/test_camera.py b/tests/components/buienradar/test_camera.py index 799fa37c7e3..9ef986b094c 100644 --- a/tests/components/buienradar/test_camera.py +++ b/tests/components/buienradar/test_camera.py @@ -10,7 +10,7 @@ from aiohttp.client_exceptions import ClientResponseError from homeassistant.components.buienradar.const import CONF_DELTA, DOMAIN from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from homeassistant.util import dt as dt_util from tests.common import MockConfigEntry @@ -32,7 +32,7 @@ def radar_map_url(country_code: str = "NL") -> str: async def _setup_config_entry(hass, entry): - entity_registry = async_get(hass) + entity_registry = er.async_get(hass) entity_registry.async_get_or_create( domain="camera", platform="buienradar", diff --git a/tests/components/buienradar/test_sensor.py b/tests/components/buienradar/test_sensor.py index ea5ef74f72e..09121a885c0 100644 --- a/tests/components/buienradar/test_sensor.py +++ b/tests/components/buienradar/test_sensor.py @@ -5,7 +5,7 @@ from http import HTTPStatus from homeassistant.components.buienradar.const import DOMAIN from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry from tests.test_util.aiohttp import AiohttpClientMocker @@ -18,7 +18,9 @@ TEST_CFG_DATA = {CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE} async def test_smoke_test_setup_component( - aioclient_mock: AiohttpClientMocker, hass: HomeAssistant + aioclient_mock: AiohttpClientMocker, + hass: HomeAssistant, + entity_registry: er.EntityRegistry, ) -> None: """Smoke test for successfully set-up with default config.""" aioclient_mock.get( @@ -28,7 +30,6 @@ async def test_smoke_test_setup_component( mock_entry.add_to_hass(hass) - entity_registry = async_get(hass) for cond in CONDITIONS: entity_registry.async_get_or_create( domain="sensor", diff --git a/tests/components/config/test_entity_registry.py b/tests/components/config/test_entity_registry.py index d61d9d7f892..813ec654abb 100644 --- a/tests/components/config/test_entity_registry.py +++ b/tests/components/config/test_entity_registry.py @@ -6,13 +6,12 @@ from pytest_unordered import unordered from homeassistant.components.config import entity_registry from homeassistant.const import ATTR_ICON, EntityCategory from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.device_registry import DeviceEntryDisabler from homeassistant.helpers.entity_registry import ( RegistryEntry, RegistryEntryDisabler, RegistryEntryHider, - async_get as async_get_entity_registry, ) from tests.common import ( @@ -863,6 +862,7 @@ async def test_enable_entity_disabled_device( hass: HomeAssistant, client: MockHAClientWebSocket, device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, ) -> None: """Test enabling entity of disabled device.""" entity_id = "test_domain.test_platform_1234" @@ -889,8 +889,7 @@ async def test_enable_entity_disabled_device( state = hass.states.get(entity_id) assert state is None - entity_reg = async_get_entity_registry(hass) - entity_entry = entity_reg.async_get(entity_id) + entity_entry = entity_registry.async_get(entity_id) assert entity_entry.config_entry_id == config_entry.entry_id assert entity_entry.device_id == device.id assert entity_entry.disabled_by == RegistryEntryDisabler.DEVICE diff --git a/tests/components/deconz/test_binary_sensor.py b/tests/components/deconz/test_binary_sensor.py index 9fd57926f44..6ab5f2f5477 100644 --- a/tests/components/deconz/test_binary_sensor.py +++ b/tests/components/deconz/test_binary_sensor.py @@ -21,7 +21,6 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er -from homeassistant.helpers.entity_registry import async_entries_for_config_entry from .test_gateway import ( DECONZ_WEB_REQUEST, @@ -687,7 +686,8 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call( assert not hass.states.get("binary_sensor.presence_sensor") assert ( - len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0 + len(er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)) + == 0 ) aioclient_mock.clear_requests() @@ -738,7 +738,8 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_options_change( assert not hass.states.get("binary_sensor.presence_sensor") assert ( - len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0 + len(er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)) + == 0 ) aioclient_mock.clear_requests() diff --git a/tests/components/deconz/test_services.py b/tests/components/deconz/test_services.py index 9c5c21bc0ff..de061fc4e8c 100644 --- a/tests/components/deconz/test_services.py +++ b/tests/components/deconz/test_services.py @@ -22,7 +22,6 @@ from homeassistant.components.deconz.services import ( from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er -from homeassistant.helpers.entity_registry import async_entries_for_config_entry from .test_gateway import ( BRIDGEID, @@ -368,7 +367,7 @@ async def test_remove_orphaned_entries_service( ) assert ( - len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) + len(er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 3 # Light, switch battery and orphan ) @@ -391,6 +390,6 @@ async def test_remove_orphaned_entries_service( ) assert ( - len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) + len(er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 2 # Light and switch battery ) diff --git a/tests/components/diagnostics/test_init.py b/tests/components/diagnostics/test_init.py index 40a8f5ab744..eeb4f420225 100644 --- a/tests/components/diagnostics/test_init.py +++ b/tests/components/diagnostics/test_init.py @@ -7,7 +7,7 @@ import pytest from homeassistant.components.websocket_api import TYPE_RESULT from homeassistant.core import HomeAssistant -from homeassistant.helpers.device_registry import async_get +from homeassistant.helpers import device_registry as dr from homeassistant.helpers.system_info import async_get_system_info from homeassistant.loader import async_get_integration from homeassistant.setup import async_setup_component @@ -82,7 +82,9 @@ async def test_websocket( @pytest.mark.usefixtures("enable_custom_integrations") async def test_download_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + device_registry: dr.DeviceRegistry, ) -> None: """Test download diagnostics.""" config_entry = MockConfigEntry(domain="fake_integration") @@ -178,8 +180,7 @@ async def test_download_diagnostics( "data": {"config_entry": "info"}, } - dev_reg = async_get(hass) - device = dev_reg.async_get_or_create( + device = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={("test", "test")} ) diff --git a/tests/components/dlna_dmr/test_media_player.py b/tests/components/dlna_dmr/test_media_player.py index ad67530e605..9a60ce244dc 100644 --- a/tests/components/dlna_dmr/test_media_player.py +++ b/tests/components/dlna_dmr/test_media_player.py @@ -45,16 +45,8 @@ from homeassistant.const import ( CONF_URL, ) from homeassistant.core import CoreState, HomeAssistant -from homeassistant.helpers.device_registry import ( - CONNECTION_NETWORK_MAC, - CONNECTION_UPNP, - async_get as async_get_dr, -) +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.entity_component import async_update_entity -from homeassistant.helpers.entity_registry import ( - async_entries_for_config_entry, - async_get as async_get_er, -) from homeassistant.setup import async_setup_component from .conftest import ( @@ -80,7 +72,8 @@ async def setup_mock_component(hass: HomeAssistant, mock_entry: MockConfigEntry) assert await hass.config_entries.async_setup(mock_entry.entry_id) is True await hass.async_block_till_done() - entries = async_entries_for_config_entry(async_get_er(hass), mock_entry.entry_id) + entity_registry = er.async_get(hass) + entries = er.async_entries_for_config_entry(entity_registry, mock_entry.entry_id) assert len(entries) == 1 return entries[0].entity_id @@ -345,6 +338,7 @@ async def test_setup_entry_with_options( async def test_setup_entry_mac_address( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, domain_data_mock: Mock, config_entry_mock: MockConfigEntry, ssdp_scanner_mock: Mock, @@ -356,17 +350,17 @@ async def test_setup_entry_mac_address( await async_update_entity(hass, mock_entity_id) await hass.async_block_till_done() # Check the device registry connections for MAC address - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None - assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) in device.connections + assert (dr.CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) in device.connections async def test_setup_entry_no_mac_address( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, domain_data_mock: Mock, config_entry_mock_no_mac: MockConfigEntry, ssdp_scanner_mock: Mock, @@ -378,13 +372,12 @@ async def test_setup_entry_no_mac_address( await async_update_entity(hass, mock_entity_id) await hass.async_block_till_done() # Check the device registry connections does not include the MAC address - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None - assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) not in device.connections + assert (dr.CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) not in device.connections async def test_event_subscribe_failure( @@ -445,15 +438,17 @@ async def test_event_subscribe_rejected( async def test_available_device( - hass: HomeAssistant, dmr_device_mock: Mock, mock_entity_id: str + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + dmr_device_mock: Mock, + mock_entity_id: str, ) -> None: """Test a DlnaDmrEntity with a connected DmrDevice.""" # Check hass device information is filled in await async_update_entity(hass, mock_entity_id) await hass.async_block_till_done() - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None @@ -1260,6 +1255,7 @@ async def test_playback_update_state( ) async def test_unavailable_device( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, domain_data_mock: Mock, ssdp_scanner_mock: Mock, config_entry_mock: MockConfigEntry, @@ -1357,9 +1353,8 @@ async def test_unavailable_device( ) # Check hass device information has not been filled in yet - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None @@ -1387,6 +1382,7 @@ async def test_unavailable_device( ) async def test_become_available( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, domain_data_mock: Mock, ssdp_scanner_mock: Mock, config_entry_mock: MockConfigEntry, @@ -1404,9 +1400,8 @@ async def test_become_available( assert mock_state.state == ha_const.STATE_UNAVAILABLE # Check hass device information has not been filled in yet - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None @@ -1446,9 +1441,8 @@ async def test_become_available( assert mock_state is not None assert mock_state.state == MediaPlayerState.IDLE # Check hass device information is now filled in - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None @@ -2281,6 +2275,7 @@ async def test_config_update_poll_availability( async def test_config_update_mac_address( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, domain_data_mock: Mock, config_entry_mock_no_mac: MockConfigEntry, ssdp_scanner_mock: Mock, @@ -2293,13 +2288,12 @@ async def test_config_update_mac_address( domain_data_mock.upnp_factory.async_create_device.reset_mock() # Check the device registry connections does not include the MAC address - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None - assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) not in device.connections + assert (dr.CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) not in device.connections # MAC address discovered and set by config flow hass.config_entries.async_update_entry( @@ -2314,12 +2308,12 @@ async def test_config_update_mac_address( await hass.async_block_till_done() # Device registry connections should now include the MAC address - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None - assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) in device.connections + assert (dr.CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) in device.connections @pytest.mark.parametrize( @@ -2328,6 +2322,8 @@ async def test_config_update_mac_address( ) async def test_connections_restored( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, domain_data_mock: Mock, ssdp_scanner_mock: Mock, config_entry_mock: MockConfigEntry, @@ -2345,9 +2341,8 @@ async def test_connections_restored( assert mock_state.state == ha_const.STATE_UNAVAILABLE # Check hass device information has not been filled in yet - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None @@ -2387,9 +2382,8 @@ async def test_connections_restored( assert mock_state is not None assert mock_state.state == MediaPlayerState.IDLE # Check hass device information is now filled in - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None @@ -2410,17 +2404,15 @@ async def test_connections_restored( dmr_device_mock.async_unsubscribe_services.assert_awaited_once() # Check hass device information has not been filled in yet - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_device( - connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)}, + device = device_registry.async_get_device( + connections={(dr.CONNECTION_UPNP, MOCK_DEVICE_UDN)}, identifiers=set(), ) assert device is not None assert device.connections == previous_connections # Verify the entity remains linked to the device - ent_reg = async_get_er(hass) - entry = ent_reg.async_get(mock_entity_id) + entry = entity_registry.async_get(mock_entity_id) assert entry is not None assert entry.device_id == device.id @@ -2435,6 +2427,8 @@ async def test_connections_restored( async def test_udn_upnp_connection_added_if_missing( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, domain_data_mock: Mock, ssdp_scanner_mock: Mock, config_entry_mock: MockConfigEntry, @@ -2449,8 +2443,7 @@ async def test_udn_upnp_connection_added_if_missing( config_entry_mock.add_to_hass(hass) # Cause connection attempts to fail before adding entity - ent_reg = async_get_er(hass) - entry = ent_reg.async_get_or_create( + entry = entity_registry.async_get_or_create( mp.DOMAIN, DOMAIN, MOCK_DEVICE_UDN, @@ -2458,14 +2451,13 @@ async def test_udn_upnp_connection_added_if_missing( ) mock_entity_id = entry.entity_id - dev_reg = async_get_dr(hass) - device = dev_reg.async_get_or_create( + device = device_registry.async_get_or_create( config_entry_id=config_entry_mock.entry_id, - connections={(CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS)}, + connections={(dr.CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS)}, identifiers=set(), ) - ent_reg.async_update_entity(mock_entity_id, device_id=device.id) + entity_registry.async_update_entity(mock_entity_id, device_id=device.id) domain_data_mock.upnp_factory.async_create_device.side_effect = UpnpConnectionError assert await hass.config_entries.async_setup(config_entry_mock.entry_id) is True @@ -2476,7 +2468,6 @@ async def test_udn_upnp_connection_added_if_missing( assert mock_state.state == ha_const.STATE_UNAVAILABLE # Check hass device information has not been filled in yet - dev_reg = async_get_dr(hass) - device = dev_reg.async_get(device.id) + device = device_registry.async_get(device.id) assert device is not None - assert (CONNECTION_UPNP, MOCK_DEVICE_UDN) in device.connections + assert (dr.CONNECTION_UPNP, MOCK_DEVICE_UDN) in device.connections diff --git a/tests/components/fritz/test_image.py b/tests/components/fritz/test_image.py index a22ab76fdb6..9097aab1762 100644 --- a/tests/components/fritz/test_image.py +++ b/tests/components/fritz/test_image.py @@ -13,7 +13,7 @@ from homeassistant.components.image import DOMAIN as IMAGE_DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNKNOWN, Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry +from homeassistant.helpers import entity_registry as er from homeassistant.util.dt import utcnow from .const import MOCK_FB_SERVICES, MOCK_USER_DATA @@ -89,6 +89,7 @@ GUEST_WIFI_DISABLED: dict[str, dict] = { async def test_image_entity( hass: HomeAssistant, hass_client: ClientSessionGenerator, + entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion, fc_class_mock, fh_class_mock, @@ -122,7 +123,6 @@ async def test_image_entity( "friendly_name": "Mock Title GuestWifi", } - entity_registry = async_get_entity_registry(hass) entity_entry = entity_registry.async_get("image.mock_title_guestwifi") assert entity_entry.unique_id == "1c_ed_6f_12_34_11_guestwifi_qr_code" diff --git a/tests/components/greeneye_monitor/conftest.py b/tests/components/greeneye_monitor/conftest.py index add823237c5..975a0119313 100644 --- a/tests/components/greeneye_monitor/conftest.py +++ b/tests/components/greeneye_monitor/conftest.py @@ -10,10 +10,7 @@ from homeassistant.components.greeneye_monitor import DOMAIN from homeassistant.components.sensor import SensorDeviceClass from homeassistant.const import UnitOfElectricPotential, UnitOfPower from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import ( - RegistryEntry, - async_get as get_entity_registry, -) +from homeassistant.helpers import entity_registry as er from .common import add_listeners @@ -82,15 +79,15 @@ def assert_sensor_registered( sensor_type: str, number: int, name: str, -) -> RegistryEntry: +) -> er.RegistryEntry: """Assert that a sensor entity of a given type was registered properly.""" - registry = get_entity_registry(hass) + entity_registry = er.async_get(hass) unique_id = f"{serial_number}-{sensor_type}-{number}" - entity_id = registry.async_get_entity_id("sensor", DOMAIN, unique_id) + entity_id = entity_registry.async_get_entity_id("sensor", DOMAIN, unique_id) assert entity_id is not None - sensor = registry.async_get(entity_id) + sensor = entity_registry.async_get(entity_id) assert sensor assert sensor.unique_id == unique_id assert sensor.original_name == name diff --git a/tests/components/greeneye_monitor/test_sensor.py b/tests/components/greeneye_monitor/test_sensor.py index 35d515a4877..cd4243f4f6d 100644 --- a/tests/components/greeneye_monitor/test_sensor.py +++ b/tests/components/greeneye_monitor/test_sensor.py @@ -8,10 +8,7 @@ from homeassistant.components.greeneye_monitor.sensor import ( ) from homeassistant.const import STATE_UNKNOWN from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import ( - RegistryEntryDisabler, - async_get as get_entity_registry, -) +from homeassistant.helpers import entity_registry as er from .common import ( MULTI_MONITOR_CONFIG, @@ -27,7 +24,7 @@ from .conftest import assert_sensor_state async def test_sensor_does_not_exist_before_monitor_connected( - hass: HomeAssistant, monitors: AsyncMock + hass: HomeAssistant, entity_registry: er.EntityRegistry, monitors: AsyncMock ) -> None: """Test that a sensor does not exist before its monitor is connected.""" # The sensor base class handles connecting the monitor, so we test this with a single voltage sensor for ease @@ -35,7 +32,6 @@ async def test_sensor_does_not_exist_before_monitor_connected( hass, SINGLE_MONITOR_CONFIG_VOLTAGE_SENSORS ) - entity_registry = get_entity_registry(hass) assert entity_registry.async_get("sensor.voltage_1") is None @@ -204,8 +200,8 @@ async def test_multi_monitor_sensors(hass: HomeAssistant, monitors: AsyncMock) - async def disable_entity(hass: HomeAssistant, entity_id: str) -> None: """Disable the given entity.""" - entity_registry = get_entity_registry(hass) + entity_registry = er.async_get(hass) entity_registry.async_update_entity( - entity_id, disabled_by=RegistryEntryDisabler.USER + entity_id, disabled_by=er.RegistryEntryDisabler.USER ) await hass.async_block_till_done() diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index 2971bdbb675..0246b557ee4 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -24,7 +24,7 @@ from homeassistant.components.hassio.const import REQUEST_REFRESH_DELAY from homeassistant.components.hassio.handler import HassioAPIError from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.core import HomeAssistant -from homeassistant.helpers.device_registry import async_get +from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util @@ -773,9 +773,10 @@ async def test_migration_off_hassio(hass: HomeAssistant) -> None: assert hass.config_entries.async_entries(DOMAIN) == [] -async def test_device_registry_calls(hass: HomeAssistant) -> None: +async def test_device_registry_calls( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test device registry entries for hassio.""" - dev_reg = async_get(hass) supervisor_mock_data = { "version": "1.0.0", "version_latest": "1.0.0", @@ -829,7 +830,7 @@ async def test_device_registry_calls(hass: HomeAssistant) -> None: config_entry.add_to_hass(hass) assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done(wait_background_tasks=True) - assert len(dev_reg.devices) == 6 + assert len(device_registry.devices) == 6 supervisor_mock_data = { "version": "1.0.0", @@ -863,11 +864,11 @@ async def test_device_registry_calls(hass: HomeAssistant) -> None: ): async_fire_time_changed(hass, dt_util.now() + timedelta(hours=1)) await hass.async_block_till_done(wait_background_tasks=True) - assert len(dev_reg.devices) == 5 + assert len(device_registry.devices) == 5 async_fire_time_changed(hass, dt_util.now() + timedelta(hours=2)) await hass.async_block_till_done(wait_background_tasks=True) - assert len(dev_reg.devices) == 5 + assert len(device_registry.devices) == 5 supervisor_mock_data = { "version": "1.0.0", @@ -921,7 +922,7 @@ async def test_device_registry_calls(hass: HomeAssistant) -> None: ): async_fire_time_changed(hass, dt_util.now() + timedelta(hours=3)) await hass.async_block_till_done() - assert len(dev_reg.devices) == 5 + assert len(device_registry.devices) == 5 async def test_coordinator_updates( diff --git a/tests/components/hue/test_sensor_v1.py b/tests/components/hue/test_sensor_v1.py index 6e620ded365..b1ef94f8ed0 100644 --- a/tests/components/hue/test_sensor_v1.py +++ b/tests/components/hue/test_sensor_v1.py @@ -10,7 +10,7 @@ from homeassistant.components.hue.const import ATTR_HUE_EVENT from homeassistant.components.hue.v1 import sensor_base from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from .conftest import create_mock_bridge, setup_platform @@ -314,7 +314,9 @@ async def test_sensors_with_multiple_bridges( assert len(hass.states.async_all()) == 10 -async def test_sensors(hass: HomeAssistant, mock_bridge_v1) -> None: +async def test_sensors( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_bridge_v1 +) -> None: """Test the update_items function with some sensors.""" mock_bridge_v1.mock_sensor_responses.append(SENSOR_RESPONSE) await setup_platform(hass, mock_bridge_v1, ["binary_sensor", "sensor"]) @@ -351,9 +353,10 @@ async def test_sensors(hass: HomeAssistant, mock_bridge_v1) -> None: assert battery_remote_1.state == "100" assert battery_remote_1.name == "Hue dimmer switch 1 battery level" - ent_reg = async_get(hass) assert ( - ent_reg.async_get("sensor.hue_dimmer_switch_1_battery_level").entity_category + entity_registry.async_get( + "sensor.hue_dimmer_switch_1_battery_level" + ).entity_category == EntityCategory.DIAGNOSTIC ) diff --git a/tests/components/kostal_plenticore/test_number.py b/tests/components/kostal_plenticore/test_number.py index bb401898de5..9d94c6f9951 100644 --- a/tests/components/kostal_plenticore/test_number.py +++ b/tests/components/kostal_plenticore/test_number.py @@ -16,7 +16,7 @@ from homeassistant.components.number import ( ) from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from homeassistant.util import dt as dt_util from tests.common import MockConfigEntry, async_fire_time_changed @@ -95,6 +95,7 @@ def mock_get_setting_values(mock_plenticore_client: ApiClient) -> list: @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_setup_all_entries( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, @@ -106,14 +107,16 @@ async def test_setup_all_entries( assert await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - ent_reg = async_get(hass) - assert ent_reg.async_get("number.scb_battery_min_soc") is not None - assert ent_reg.async_get("number.scb_battery_min_home_consumption") is not None + assert entity_registry.async_get("number.scb_battery_min_soc") is not None + assert ( + entity_registry.async_get("number.scb_battery_min_home_consumption") is not None + ) @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_setup_no_entries( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, @@ -140,9 +143,8 @@ async def test_setup_no_entries( assert await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - ent_reg = async_get(hass) - assert ent_reg.async_get("number.scb_battery_min_soc") is None - assert ent_reg.async_get("number.scb_battery_min_home_consumption") is None + assert entity_registry.async_get("number.scb_battery_min_soc") is None + assert entity_registry.async_get("number.scb_battery_min_home_consumption") is None @pytest.mark.usefixtures("entity_registry_enabled_by_default") diff --git a/tests/components/metoffice/test_sensor.py b/tests/components/metoffice/test_sensor.py index 6bddd1d2596..db84e85075e 100644 --- a/tests/components/metoffice/test_sensor.py +++ b/tests/components/metoffice/test_sensor.py @@ -8,7 +8,7 @@ import requests_mock from homeassistant.components.metoffice.const import ATTRIBUTION, DOMAIN from homeassistant.core import HomeAssistant -from homeassistant.helpers.device_registry import async_get as get_dev_reg +from homeassistant.helpers import device_registry as dr from .const import ( DEVICE_KEY_KINGSLYNN, @@ -27,7 +27,9 @@ from tests.common import MockConfigEntry, load_fixture @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) async def test_one_sensor_site_running( - hass: HomeAssistant, requests_mock: requests_mock.Mocker + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + requests_mock: requests_mock.Mocker, ) -> None: """Test the Met Office sensor platform.""" # all metoffice test data encapsulated in here @@ -54,9 +56,10 @@ async def test_one_sensor_site_running( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - dev_reg = get_dev_reg(hass) - assert len(dev_reg.devices) == 1 - device_wavertree = dev_reg.async_get_device(identifiers=DEVICE_KEY_WAVERTREE) + assert len(device_registry.devices) == 1 + device_wavertree = device_registry.async_get_device( + identifiers=DEVICE_KEY_WAVERTREE + ) assert device_wavertree.name == "Met Office Wavertree" running_sensor_ids = hass.states.async_entity_ids("sensor") @@ -75,7 +78,9 @@ async def test_one_sensor_site_running( @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) async def test_two_sensor_sites_running( - hass: HomeAssistant, requests_mock: requests_mock.Mocker + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + requests_mock: requests_mock.Mocker, ) -> None: """Test we handle two sets of sensors running for two different sites.""" @@ -115,11 +120,14 @@ async def test_two_sensor_sites_running( await hass.config_entries.async_setup(entry2.entry_id) await hass.async_block_till_done() - dev_reg = get_dev_reg(hass) - assert len(dev_reg.devices) == 2 - device_kingslynn = dev_reg.async_get_device(identifiers=DEVICE_KEY_KINGSLYNN) + assert len(device_registry.devices) == 2 + device_kingslynn = device_registry.async_get_device( + identifiers=DEVICE_KEY_KINGSLYNN + ) assert device_kingslynn.name == "Met Office King's Lynn" - device_wavertree = dev_reg.async_get_device(identifiers=DEVICE_KEY_WAVERTREE) + device_wavertree = device_registry.async_get_device( + identifiers=DEVICE_KEY_WAVERTREE + ) assert device_wavertree.name == "Met Office Wavertree" running_sensor_ids = hass.states.async_entity_ids("sensor") diff --git a/tests/components/metoffice/test_weather.py b/tests/components/metoffice/test_weather.py index 64a85897738..64e6ef65ec2 100644 --- a/tests/components/metoffice/test_weather.py +++ b/tests/components/metoffice/test_weather.py @@ -19,8 +19,7 @@ from homeassistant.components.weather import ( ) from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry as er -from homeassistant.helpers.device_registry import async_get as get_dev_reg +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.util import utcnow from .const import ( @@ -73,7 +72,9 @@ async def wavertree_data(requests_mock: requests_mock.Mocker) -> dict[str, _Matc @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) async def test_site_cannot_connect( - hass: HomeAssistant, requests_mock: requests_mock.Mocker + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + requests_mock: requests_mock.Mocker, ) -> None: """Test we handle cannot connect error.""" @@ -89,8 +90,7 @@ async def test_site_cannot_connect( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - dev_reg = get_dev_reg(hass) - assert len(dev_reg.devices) == 0 + assert len(device_registry.devices) == 0 assert hass.states.get("weather.met_office_wavertree_3hourly") is None assert hass.states.get("weather.met_office_wavertree_daily") is None @@ -103,7 +103,6 @@ async def test_site_cannot_connect( @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) async def test_site_cannot_update( hass: HomeAssistant, - entity_registry: er.EntityRegistry, requests_mock: requests_mock.Mocker, wavertree_data, ) -> None: @@ -134,7 +133,7 @@ async def test_site_cannot_update( @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) async def test_one_weather_site_running( hass: HomeAssistant, - entity_registry: er.EntityRegistry, + device_registry: dr.DeviceRegistry, requests_mock: requests_mock.Mocker, wavertree_data, ) -> None: @@ -148,9 +147,10 @@ async def test_one_weather_site_running( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - dev_reg = get_dev_reg(hass) - assert len(dev_reg.devices) == 1 - device_wavertree = dev_reg.async_get_device(identifiers=DEVICE_KEY_WAVERTREE) + assert len(device_registry.devices) == 1 + device_wavertree = device_registry.async_get_device( + identifiers=DEVICE_KEY_WAVERTREE + ) assert device_wavertree.name == "Met Office Wavertree" # Wavertree daily weather platform expected results @@ -167,7 +167,7 @@ async def test_one_weather_site_running( @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) async def test_two_weather_sites_running( hass: HomeAssistant, - entity_registry: er.EntityRegistry, + device_registry: dr.DeviceRegistry, requests_mock: requests_mock.Mocker, wavertree_data, ) -> None: @@ -199,11 +199,14 @@ async def test_two_weather_sites_running( await hass.config_entries.async_setup(entry2.entry_id) await hass.async_block_till_done() - dev_reg = get_dev_reg(hass) - assert len(dev_reg.devices) == 2 - device_kingslynn = dev_reg.async_get_device(identifiers=DEVICE_KEY_KINGSLYNN) + assert len(device_registry.devices) == 2 + device_kingslynn = device_registry.async_get_device( + identifiers=DEVICE_KEY_KINGSLYNN + ) assert device_kingslynn.name == "Met Office King's Lynn" - device_wavertree = dev_reg.async_get_device(identifiers=DEVICE_KEY_WAVERTREE) + device_wavertree = device_registry.async_get_device( + identifiers=DEVICE_KEY_WAVERTREE + ) assert device_wavertree.name == "Met Office Wavertree" # Wavertree daily weather platform expected results @@ -371,7 +374,6 @@ async def test_legacy_config_entry_is_removed( async def test_forecast_subscription( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, - entity_registry: er.EntityRegistry, freezer: FrozenDateTimeFactory, snapshot: SnapshotAssertion, no_sensor, diff --git a/tests/components/octoprint/test_servics.py b/tests/components/octoprint/test_servics.py index 2b5a89970e8..21a4ede8845 100644 --- a/tests/components/octoprint/test_servics.py +++ b/tests/components/octoprint/test_servics.py @@ -8,20 +8,19 @@ from homeassistant.components.octoprint.const import ( SERVICE_CONNECT, ) from homeassistant.const import ATTR_DEVICE_ID, CONF_PORT, CONF_PROFILE_NAME -from homeassistant.helpers.device_registry import ( - async_entries_for_config_entry, - async_get as async_get_dev_reg, -) +from homeassistant.core import HomeAssistant +from homeassistant.helpers import device_registry as dr from . import init_integration -async def test_connect_default(hass) -> None: +async def test_connect_default( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test the connect to printer service.""" await init_integration(hass, "sensor") - dev_reg = async_get_dev_reg(hass) - device = async_entries_for_config_entry(dev_reg, "uuid")[0] + device = dr.async_entries_for_config_entry(device_registry, "uuid")[0] # Test pausing the printer when it is printing with patch("pyoctoprintapi.OctoprintClient.connect") as connect_command: @@ -40,12 +39,13 @@ async def test_connect_default(hass) -> None: ) -async def test_connect_all_arguments(hass) -> None: +async def test_connect_all_arguments( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test the connect to printer service.""" await init_integration(hass, "sensor") - dev_reg = async_get_dev_reg(hass) - device = async_entries_for_config_entry(dev_reg, "uuid")[0] + device = dr.async_entries_for_config_entry(device_registry, "uuid")[0] # Test pausing the printer when it is printing with patch("pyoctoprintapi.OctoprintClient.connect") as connect_command: diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index 53de5f8c64a..9a20a37824d 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -5,8 +5,8 @@ from unittest.mock import MagicMock from homeassistant.components.plugwise.const import DOMAIN from homeassistant.const import Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_component import async_update_entity -from homeassistant.helpers.entity_registry import async_get from tests.common import MockConfigEntry @@ -49,13 +49,13 @@ async def test_adam_climate_sensor_entity_2( async def test_unique_id_migration_humidity( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_smile_adam_4: MagicMock, mock_config_entry: MockConfigEntry, ) -> None: """Test unique ID migration of -relative_humidity to -humidity.""" mock_config_entry.add_to_hass(hass) - entity_registry = async_get(hass) # Entry to migrate entity_registry.async_get_or_create( Platform.SENSOR, @@ -136,7 +136,10 @@ async def test_p1_dsmr_sensor_entities( async def test_p1_3ph_dsmr_sensor_entities( - hass: HomeAssistant, mock_smile_p1_2: MagicMock, init_integration: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_smile_p1_2: MagicMock, + init_integration: MockConfigEntry, ) -> None: """Test creation of power related sensor entities.""" state = hass.states.get("sensor.p1_electricity_phase_one_consumed") @@ -155,7 +158,6 @@ async def test_p1_3ph_dsmr_sensor_entities( state = hass.states.get(entity_id) assert not state - entity_registry = async_get(hass) entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None) await hass.async_block_till_done() diff --git a/tests/components/samsungtv/test_device_trigger.py b/tests/components/samsungtv/test_device_trigger.py index 19e7f3ca88a..e16ea718cbb 100644 --- a/tests/components/samsungtv/test_device_trigger.py +++ b/tests/components/samsungtv/test_device_trigger.py @@ -11,7 +11,7 @@ from homeassistant.components.samsungtv import DOMAIN, device_trigger from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.device_registry import async_get as get_dev_reg +from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component from . import setup_samsungtv_entry @@ -21,12 +21,13 @@ from tests.common import MockConfigEntry, async_get_device_automations @pytest.mark.usefixtures("remoteencws", "rest_api") -async def test_get_triggers(hass: HomeAssistant) -> None: +async def test_get_triggers( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test we get the expected triggers.""" await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS) - device_reg = get_dev_reg(hass) - device = device_reg.async_get_device(identifiers={(DOMAIN, "any")}) + device = device_registry.async_get_device(identifiers={(DOMAIN, "any")}) turn_on_trigger = { "platform": "device", @@ -44,14 +45,13 @@ async def test_get_triggers(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("remoteencws", "rest_api") async def test_if_fires_on_turn_on_request( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall] ) -> None: """Test for turn_on and turn_off triggers firing.""" await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS) entity_id = "media_player.fake" - device_reg = get_dev_reg(hass) - device = device_reg.async_get_device(identifiers={(DOMAIN, "any")}) + device = device_registry.async_get_device(identifiers={(DOMAIN, "any")}) assert await async_setup_component( hass, @@ -103,7 +103,9 @@ async def test_if_fires_on_turn_on_request( @pytest.mark.usefixtures("remoteencws", "rest_api") -async def test_failure_scenarios(hass: HomeAssistant) -> None: +async def test_failure_scenarios( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test failure scenarios.""" await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS) @@ -127,9 +129,8 @@ async def test_failure_scenarios(hass: HomeAssistant) -> None: entry = MockConfigEntry(domain="fake", state=ConfigEntryState.LOADED, data={}) entry.add_to_hass(hass) - device_reg = get_dev_reg(hass) - device = device_reg.async_get_or_create( + device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={("fake", "fake")} ) diff --git a/tests/components/smhi/test_init.py b/tests/components/smhi/test_init.py index aefbccb64ec..cfb386c8f6f 100644 --- a/tests/components/smhi/test_init.py +++ b/tests/components/smhi/test_init.py @@ -6,7 +6,7 @@ from smhi.smhi_lib import APIURL_TEMPLATE from homeassistant.components.smhi.const import DOMAIN from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from . import ENTITY_ID, TEST_CONFIG, TEST_CONFIG_MIGRATE @@ -57,7 +57,10 @@ async def test_remove_entry( async def test_migrate_entry( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, api_response: str + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + aioclient_mock: AiohttpClientMocker, + api_response: str, ) -> None: """Test migrate entry data.""" uri = APIURL_TEMPLATE.format( @@ -68,8 +71,7 @@ async def test_migrate_entry( entry.add_to_hass(hass) assert entry.version == 1 - entity_reg = async_get(hass) - entity = entity_reg.async_get_or_create( + entity = entity_registry.async_get_or_create( domain="weather", config_entry=entry, original_name="Weather", @@ -87,7 +89,7 @@ async def test_migrate_entry( assert entry.version == 2 assert entry.unique_id == "17.84197-17.84197" - entity_get = entity_reg.async_get(entity.entity_id) + entity_get = entity_registry.async_get(entity.entity_id) assert entity_get.unique_id == "17.84197, 17.84197" diff --git a/tests/components/template/test_button.py b/tests/components/template/test_button.py index 989ca8e1287..c861c7874d4 100644 --- a/tests/components/template/test_button.py +++ b/tests/components/template/test_button.py @@ -15,7 +15,7 @@ from homeassistant.const import ( STATE_UNKNOWN, ) from homeassistant.core import HomeAssistant, ServiceCall -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from tests.common import assert_setup_component @@ -62,7 +62,10 @@ async def test_missing_required_keys(hass: HomeAssistant) -> None: async def test_all_optional_config( - hass: HomeAssistant, freezer: FrozenDateTimeFactory, calls: list[ServiceCall] + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + freezer: FrozenDateTimeFactory, + calls: list[ServiceCall], ) -> None: """Test: including all optional templates is ok.""" with assert_setup_component(1, "template"): @@ -124,8 +127,7 @@ async def test_all_optional_config( _TEST_OPTIONS_BUTTON, ) - er = async_get(hass) - assert er.async_get_entity_id("button", "template", "test-test") + assert entity_registry.async_get_entity_id("button", "template", "test-test") async def test_name_template(hass: HomeAssistant) -> None: diff --git a/tests/components/template/test_image.py b/tests/components/template/test_image.py index 6162276fcec..bda9e2530ca 100644 --- a/tests/components/template/test_image.py +++ b/tests/components/template/test_image.py @@ -17,7 +17,7 @@ from homeassistant.components.input_text import ( ) from homeassistant.const import ATTR_ENTITY_PICTURE, CONF_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from homeassistant.util import dt as dt_util from tests.common import assert_setup_component @@ -211,7 +211,9 @@ async def test_missing_required_keys(hass: HomeAssistant) -> None: assert hass.states.async_all("image") == [] -async def test_unique_id(hass: HomeAssistant) -> None: +async def test_unique_id( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test unique_id configuration.""" with assert_setup_component(1, "template"): assert await setup.async_setup_component( @@ -232,8 +234,7 @@ async def test_unique_id(hass: HomeAssistant) -> None: await hass.async_start() await hass.async_block_till_done() - ent_reg = async_get(hass) - entry = ent_reg.async_get(_TEST_IMAGE) + entry = entity_registry.async_get(_TEST_IMAGE) assert entry assert entry.unique_id == "b-a" diff --git a/tests/components/template/test_number.py b/tests/components/template/test_number.py index d715a6aed0b..bf04151fd36 100644 --- a/tests/components/template/test_number.py +++ b/tests/components/template/test_number.py @@ -16,7 +16,7 @@ from homeassistant.components.number import ( ) from homeassistant.const import ATTR_ICON, CONF_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import Context, HomeAssistant, ServiceCall -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from tests.common import assert_setup_component, async_capture_events @@ -128,7 +128,7 @@ async def test_all_optional_config(hass: HomeAssistant) -> None: async def test_templates_with_entities( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, entity_registry: er.EntityRegistry, calls: list[ServiceCall] ) -> None: """Test templates with values from other entities.""" with assert_setup_component(4, "input_number"): @@ -208,8 +208,7 @@ async def test_templates_with_entities( await hass.async_start() await hass.async_block_till_done() - ent_reg = async_get(hass) - entry = ent_reg.async_get(_TEST_NUMBER) + entry = entity_registry.async_get(_TEST_NUMBER) assert entry assert entry.unique_id == "b-a" diff --git a/tests/components/template/test_select.py b/tests/components/template/test_select.py index 5f6561d3953..4106abdd469 100644 --- a/tests/components/template/test_select.py +++ b/tests/components/template/test_select.py @@ -16,7 +16,7 @@ from homeassistant.components.select import ( ) from homeassistant.const import ATTR_ICON, CONF_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import Context, HomeAssistant, ServiceCall -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from tests.common import assert_setup_component, async_capture_events @@ -133,7 +133,7 @@ async def test_missing_required_keys(hass: HomeAssistant) -> None: async def test_templates_with_entities( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, entity_registry: er.EntityRegistry, calls: list[ServiceCall] ) -> None: """Test templates with values from other entities.""" with assert_setup_component(1, "input_select"): @@ -189,8 +189,7 @@ async def test_templates_with_entities( await hass.async_start() await hass.async_block_till_done() - ent_reg = async_get(hass) - entry = ent_reg.async_get(_TEST_SELECT) + entry = entity_registry.async_get(_TEST_SELECT) assert entry assert entry.unique_id == "b-a" diff --git a/tests/components/tomorrowio/test_sensor.py b/tests/components/tomorrowio/test_sensor.py index b0e2fba3123..43b0e33aed4 100644 --- a/tests/components/tomorrowio/test_sensor.py +++ b/tests/components/tomorrowio/test_sensor.py @@ -24,7 +24,7 @@ from homeassistant.components.tomorrowio.sensor import TomorrowioSensorEntityDes from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY, SOURCE_USER from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME from homeassistant.core import HomeAssistant, State, callback -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from homeassistant.util import dt as dt_util from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM @@ -103,7 +103,7 @@ V4_FIELDS = [ @callback def _enable_entity(hass: HomeAssistant, entity_name: str) -> None: """Enable disabled entity.""" - ent_reg = async_get(hass) + ent_reg = er.async_get(hass) entry = ent_reg.async_get(entity_name) updated_entry = ent_reg.async_update_entity(entry.entity_id, disabled_by=None) assert updated_entry != entry diff --git a/tests/components/tomorrowio/test_weather.py b/tests/components/tomorrowio/test_weather.py index 88a8d0d0c89..09f871896d3 100644 --- a/tests/components/tomorrowio/test_weather.py +++ b/tests/components/tomorrowio/test_weather.py @@ -43,7 +43,6 @@ from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY, SOURCE_USER from homeassistant.const import ATTR_ATTRIBUTION, ATTR_FRIENDLY_NAME, CONF_NAME from homeassistant.core import HomeAssistant, State, callback from homeassistant.helpers import entity_registry as er -from homeassistant.helpers.entity_registry import async_get from homeassistant.util import dt as dt_util from .const import API_V4_ENTRY_DATA @@ -55,7 +54,7 @@ from tests.typing import WebSocketGenerator @callback def _enable_entity(hass: HomeAssistant, entity_name: str) -> None: """Enable disabled entity.""" - ent_reg = async_get(hass) + ent_reg = er.async_get(hass) entry = ent_reg.async_get(entity_name) updated_entry = ent_reg.async_update_entity(entry.entity_id, disabled_by=None) assert updated_entry != entry diff --git a/tests/components/uvc/test_camera.py b/tests/components/uvc/test_camera.py index 522448ecfc4..5ce8baf9919 100644 --- a/tests/components/uvc/test_camera.py +++ b/tests/components/uvc/test_camera.py @@ -18,7 +18,7 @@ from homeassistant.components.camera import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow @@ -111,7 +111,9 @@ def camera_v313_fixture(): yield camera -async def test_setup_full_config(hass: HomeAssistant, mock_remote, camera_info) -> None: +async def test_setup_full_config( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_remote, camera_info +) -> None: """Test the setup with full configuration.""" config = { "platform": "uvc", @@ -153,7 +155,6 @@ async def test_setup_full_config(hass: HomeAssistant, mock_remote, camera_info) assert state assert state.name == "Back" - entity_registry = async_get_entity_registry(hass) entity_entry = entity_registry.async_get("camera.front") assert entity_entry.unique_id == "id1" @@ -163,7 +164,9 @@ async def test_setup_full_config(hass: HomeAssistant, mock_remote, camera_info) assert entity_entry.unique_id == "id2" -async def test_setup_partial_config(hass: HomeAssistant, mock_remote) -> None: +async def test_setup_partial_config( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_remote +) -> None: """Test the setup with partial configuration.""" config = {"platform": "uvc", "nvr": "foo", "key": "secret"} @@ -187,7 +190,6 @@ async def test_setup_partial_config(hass: HomeAssistant, mock_remote) -> None: assert state assert state.name == "Back" - entity_registry = async_get_entity_registry(hass) entity_entry = entity_registry.async_get("camera.front") assert entity_entry.unique_id == "id1" @@ -197,7 +199,9 @@ async def test_setup_partial_config(hass: HomeAssistant, mock_remote) -> None: assert entity_entry.unique_id == "id2" -async def test_setup_partial_config_v31x(hass: HomeAssistant, mock_remote) -> None: +async def test_setup_partial_config_v31x( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_remote +) -> None: """Test the setup with a v3.1.x server.""" config = {"platform": "uvc", "nvr": "foo", "key": "secret"} mock_remote.return_value.server_version = (3, 1, 3) @@ -222,7 +226,6 @@ async def test_setup_partial_config_v31x(hass: HomeAssistant, mock_remote) -> No assert state assert state.name == "Back" - entity_registry = async_get_entity_registry(hass) entity_entry = entity_registry.async_get("camera.front") assert entity_entry.unique_id == "one" diff --git a/tests/components/xiaomi_ble/test_device_trigger.py b/tests/components/xiaomi_ble/test_device_trigger.py index 7b4624d1025..404eb6a4258 100644 --- a/tests/components/xiaomi_ble/test_device_trigger.py +++ b/tests/components/xiaomi_ble/test_device_trigger.py @@ -8,10 +8,7 @@ from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.xiaomi_ble.const import CONF_SUBTYPE, DOMAIN from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE from homeassistant.core import HomeAssistant, ServiceCall, callback -from homeassistant.helpers.device_registry import ( - CONNECTION_NETWORK_MAC, - async_get as async_get_dev_reg, -) +from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component from . import make_advertisement @@ -176,7 +173,9 @@ async def test_event_dimmer_rotate(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_button(hass: HomeAssistant) -> None: +async def test_get_triggers_button( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we get the expected triggers from a Xiaomi BLE button sensor.""" mac = "54:EF:44:E3:9C:BC" data = {"bindkey": "5b51a7c91cde6707c9ef18dfda143a58"} @@ -196,8 +195,7 @@ async def test_get_triggers_button(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(events) == 1 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -216,7 +214,9 @@ async def test_get_triggers_button(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_double_button(hass: HomeAssistant) -> None: +async def test_get_triggers_double_button( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we get the expected triggers from a Xiaomi BLE switch with 2 buttons.""" mac = "DC:ED:83:87:12:73" data = {"bindkey": "b93eb3787eabda352edd94b667f5d5a9"} @@ -236,8 +236,7 @@ async def test_get_triggers_double_button(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(events) == 1 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -256,7 +255,9 @@ async def test_get_triggers_double_button(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_lock(hass: HomeAssistant) -> None: +async def test_get_triggers_lock( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we get the expected triggers from a Xiaomi BLE lock with fingerprint scanner.""" mac = "98:0C:33:A3:04:3D" data = {"bindkey": "54d84797cb77f9538b224b305c877d1e"} @@ -277,8 +278,7 @@ async def test_get_triggers_lock(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(events) == 1 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -297,7 +297,9 @@ async def test_get_triggers_lock(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_motion(hass: HomeAssistant) -> None: +async def test_get_triggers_motion( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we get the expected triggers from a Xiaomi BLE motion sensor.""" mac = "DE:70:E8:B2:39:0C" entry = await _async_setup_xiaomi_device(hass, mac) @@ -313,8 +315,7 @@ async def test_get_triggers_motion(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(events) == 1 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) assert device expected_trigger = { CONF_PLATFORM: "device", @@ -333,7 +334,9 @@ async def test_get_triggers_motion(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def test_get_triggers_for_invalid_xiami_ble_device(hass: HomeAssistant) -> None: +async def test_get_triggers_for_invalid_xiami_ble_device( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we don't get triggers for an device that does not emit events.""" mac = "C4:7C:8D:6A:3E:7A" entry = await _async_setup_xiaomi_device(hass, mac) @@ -349,8 +352,7 @@ async def test_get_triggers_for_invalid_xiami_ble_device(hass: HomeAssistant) -> await hass.async_block_till_done() assert len(events) == 0 - dev_reg = async_get_dev_reg(hass) - invalid_device = dev_reg.async_get_or_create( + invalid_device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, "invdevmac")}, ) @@ -364,7 +366,9 @@ async def test_get_triggers_for_invalid_xiami_ble_device(hass: HomeAssistant) -> await hass.async_block_till_done() -async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None: +async def test_get_triggers_for_invalid_device_id( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test that we don't get triggers when using an invalid device_id.""" mac = "DE:70:E8:B2:39:0C" entry = await _async_setup_xiaomi_device(hass, mac) @@ -378,11 +382,9 @@ async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None: # wait for the event await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - - invalid_device = dev_reg.async_get_or_create( + invalid_device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, - connections={(CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, + connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, ) assert invalid_device triggers = await async_get_device_automations( @@ -395,7 +397,7 @@ async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None: async def test_if_fires_on_button_press( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall] ) -> None: """Test for button press event trigger firing.""" mac = "54:EF:44:E3:9C:BC" @@ -414,8 +416,7 @@ async def test_if_fires_on_button_press( # wait for the device being created await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) device_id = device.id assert await async_setup_component( @@ -457,7 +458,7 @@ async def test_if_fires_on_button_press( async def test_if_fires_on_double_button_long_press( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall] ) -> None: """Test for button press event trigger firing.""" mac = "DC:ED:83:87:12:73" @@ -476,8 +477,7 @@ async def test_if_fires_on_double_button_long_press( # wait for the device being created await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) device_id = device.id assert await async_setup_component( @@ -519,7 +519,7 @@ async def test_if_fires_on_double_button_long_press( async def test_if_fires_on_motion_detected( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall] ) -> None: """Test for motion event trigger firing.""" mac = "DE:70:E8:B2:39:0C" @@ -534,8 +534,7 @@ async def test_if_fires_on_motion_detected( # wait for the device being created await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) device_id = device.id assert await async_setup_component( @@ -575,6 +574,7 @@ async def test_if_fires_on_motion_detected( async def test_automation_with_invalid_trigger_type( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, caplog: pytest.LogCaptureFixture, ) -> None: """Test for automation with invalid trigger type.""" @@ -590,8 +590,7 @@ async def test_automation_with_invalid_trigger_type( # wait for the event await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) device_id = device.id assert await async_setup_component( @@ -624,6 +623,7 @@ async def test_automation_with_invalid_trigger_type( async def test_automation_with_invalid_trigger_event_property( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, caplog: pytest.LogCaptureFixture, ) -> None: """Test for automation with invalid trigger event property.""" @@ -639,8 +639,7 @@ async def test_automation_with_invalid_trigger_event_property( # wait for the event await hass.async_block_till_done() - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device(identifiers={get_device_id(mac)}) + device = device_registry.async_get_device(identifiers={get_device_id(mac)}) device_id = device.id assert await async_setup_component( @@ -675,7 +674,7 @@ async def test_automation_with_invalid_trigger_event_property( async def test_triggers_for_invalid__model( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall] ) -> None: """Test invalid model doesn't return triggers.""" mac = "DE:70:E8:B2:39:0C" @@ -691,8 +690,7 @@ async def test_triggers_for_invalid__model( await hass.async_block_till_done() # modify model to invalid model - dev_reg = async_get_dev_reg(hass) - invalid_model = dev_reg.async_get_or_create( + invalid_model = device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, mac)}, model="invalid model", diff --git a/tests/components/zha/test_diagnostics.py b/tests/components/zha/test_diagnostics.py index 50b07b70e8d..4bb30a5fc8c 100644 --- a/tests/components/zha/test_diagnostics.py +++ b/tests/components/zha/test_diagnostics.py @@ -12,7 +12,7 @@ from homeassistant.components.zha.core.helpers import get_zha_gateway from homeassistant.components.zha.diagnostics import KEYS_TO_REDACT from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers.device_registry import async_get +from homeassistant.helpers import device_registry as dr from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE @@ -104,6 +104,7 @@ async def test_diagnostics_for_config_entry( async def test_diagnostics_for_device( hass: HomeAssistant, hass_client: ClientSessionGenerator, + device_registry: dr.DeviceRegistry, config_entry: MockConfigEntry, zha_device_joined, zigpy_device, @@ -126,8 +127,9 @@ async def test_diagnostics_for_device( } ) - dev_reg = async_get(hass) - device = dev_reg.async_get_device(identifiers={("zha", str(zha_device.ieee))}) + device = device_registry.async_get_device( + identifiers={("zha", str(zha_device.ieee))} + ) assert device diagnostics_data = await get_diagnostics_for_device( hass, hass_client, config_entry, device