diff --git a/tests/components/advantage_air/test_switch.py b/tests/components/advantage_air/test_switch.py index 4977a4cc31f..ecc652b3d9e 100644 --- a/tests/components/advantage_air/test_switch.py +++ b/tests/components/advantage_air/test_switch.py @@ -27,8 +27,6 @@ async def test_cover_async_setup_entry( await add_mock_config(hass) - registry = er.async_get(hass) - # Test Fresh Air Switch Entity entity_id = "switch.myzone_fresh_air" state = hass.states.get(entity_id) @@ -61,7 +59,7 @@ async def test_cover_async_setup_entry( entity_id = "switch.myzone_myfan" assert hass.states.get(entity_id) == snapshot(name=entity_id) - entry = registry.async_get(entity_id) + entry = entity_registry.async_get(entity_id) assert entry assert entry.unique_id == "uniqueid-ac1-myfan" diff --git a/tests/components/aladdin_connect/test_init.py b/tests/components/aladdin_connect/test_init.py index 704b57eeb59..bcc32101437 100644 --- a/tests/components/aladdin_connect/test_init.py +++ b/tests/components/aladdin_connect/test_init.py @@ -144,7 +144,9 @@ async def test_load_and_unload( async def test_stale_device_removal( - hass: HomeAssistant, mock_aladdinconnect_api: MagicMock + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_aladdinconnect_api: MagicMock, ) -> None: """Test component setup missing door device is removed.""" DEVICE_CONFIG_DOOR_2 = { @@ -172,7 +174,6 @@ async def test_stale_device_removal( ) config_entry_other.add_to_hass(hass) - device_registry = dr.async_get(hass) device_entry_other = device_registry.async_get_or_create( config_entry_id=config_entry_other.entry_id, identifiers={("OtherDomain", "533255-2")}, @@ -193,8 +194,6 @@ async def test_stale_device_removal( assert config_entry.state is ConfigEntryState.LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - device_registry = dr.async_get(hass) - device_entries = dr.async_entries_for_config_entry( device_registry, config_entry.entry_id ) diff --git a/tests/components/assist_pipeline/conftest.py b/tests/components/assist_pipeline/conftest.py index 9f098150288..f4c4ddf1730 100644 --- a/tests/components/assist_pipeline/conftest.py +++ b/tests/components/assist_pipeline/conftest.py @@ -378,13 +378,14 @@ async def init_components(hass: HomeAssistant, init_supporting_components): @pytest.fixture -async def assist_device(hass: HomeAssistant, init_components) -> dr.DeviceEntry: +async def assist_device( + hass: HomeAssistant, device_registry: dr.DeviceRegistry, init_components +) -> dr.DeviceEntry: """Create an assist device.""" config_entry = MockConfigEntry(domain="test_assist_device") config_entry.add_to_hass(hass) - dev_reg = dr.async_get(hass) - device = dev_reg.async_get_or_create( + device = device_registry.async_get_or_create( name="Test Device", config_entry_id=config_entry.entry_id, identifiers={("test_assist_device", "test")}, diff --git a/tests/components/blue_current/test_sensor.py b/tests/components/blue_current/test_sensor.py index 5213cc0ff72..cf20b7334b4 100644 --- a/tests/components/blue_current/test_sensor.py +++ b/tests/components/blue_current/test_sensor.py @@ -88,7 +88,9 @@ grid_entity_ids = { async def test_sensors_created( - hass: HomeAssistant, config_entry: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + config_entry: MockConfigEntry, ) -> None: """Test if all sensors are created.""" await init_integration( @@ -100,8 +102,6 @@ async def test_sensors_created( grid, ) - entity_registry = er.async_get(hass) - sensors = er.async_entries_for_config_entry(entity_registry, "uuid") assert len(charge_point_status) + len(charge_point_status_timestamps) + len( grid @@ -109,13 +109,16 @@ async def test_sensors_created( @pytest.mark.usefixtures("entity_registry_enabled_by_default") -async def test_sensors(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: +async def test_sensors( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + config_entry: MockConfigEntry, +) -> None: """Test the underlying sensors.""" await init_integration( hass, config_entry, "sensor", charge_point, charge_point_status, grid ) - entity_registry = er.async_get(hass) for entity_id, key in charge_point_entity_ids.items(): entry = entity_registry.async_get(f"sensor.101_{entity_id}") assert entry @@ -138,14 +141,15 @@ async def test_sensors(hass: HomeAssistant, config_entry: MockConfigEntry) -> No async def test_timestamp_sensors( - hass: HomeAssistant, config_entry: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + config_entry: MockConfigEntry, ) -> None: """Test the underlying sensors.""" await init_integration( hass, config_entry, "sensor", status=charge_point_status_timestamps ) - entity_registry = er.async_get(hass) for entity_id, key in charge_point_timestamp_entity_ids.items(): entry = entity_registry.async_get(f"sensor.101_{entity_id}") assert entry diff --git a/tests/components/counter/test_init.py b/tests/components/counter/test_init.py index c0bd6344adb..342c22baf24 100644 --- a/tests/components/counter/test_init.py +++ b/tests/components/counter/test_init.py @@ -532,7 +532,10 @@ async def test_ws_delete( async def test_update_min_max( - hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, + storage_setup, ) -> None: """Test updating min/max updates the state.""" @@ -549,7 +552,6 @@ async def test_update_min_max( input_id = "from_storage" input_entity_id = f"{DOMAIN}.{input_id}" - entity_registry = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is not None @@ -620,7 +622,10 @@ async def test_update_min_max( async def test_create( - hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, + storage_setup, ) -> None: """Test creating counter using WS.""" @@ -630,7 +635,6 @@ async def test_create( counter_id = "new_counter" input_entity_id = f"{DOMAIN}.{counter_id}" - entity_registry = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is None diff --git a/tests/components/enphase_envoy/test_sensor.py b/tests/components/enphase_envoy/test_sensor.py index 3d6a0ec5757..13727e29eac 100644 --- a/tests/components/enphase_envoy/test_sensor.py +++ b/tests/components/enphase_envoy/test_sensor.py @@ -38,14 +38,12 @@ async def setup_enphase_envoy_sensor_fixture(hass, config, mock_envoy): async def test_sensor( hass: HomeAssistant, + entity_registry: er.EntityRegistry, config_entry: MockConfigEntry, snapshot: SnapshotAssertion, setup_enphase_envoy_sensor, ) -> None: """Test enphase_envoy sensor entities.""" - entity_registry = er.async_get(hass) - assert entity_registry - # compare registered entities against snapshot of prior run entity_entries = er.async_entries_for_config_entry( entity_registry, config_entry.entry_id diff --git a/tests/components/esphome/test_entity.py b/tests/components/esphome/test_entity.py index bc633d87fae..296d61b664d 100644 --- a/tests/components/esphome/test_entity.py +++ b/tests/components/esphome/test_entity.py @@ -32,6 +32,7 @@ from .conftest import MockESPHomeDevice async def test_entities_removed( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_client: APIClient, hass_storage: dict[str, Any], mock_esphome_device: Callable[ @@ -40,7 +41,6 @@ async def test_entities_removed( ], ) -> None: """Test entities are removed when static info changes.""" - ent_reg = er.async_get(hass) entity_info = [ BinarySensorInfo( object_id="mybinary_sensor", @@ -86,7 +86,9 @@ async def test_entities_removed( assert state.attributes[ATTR_RESTORED] is True state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed") assert state is not None - reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed") + reg_entry = entity_registry.async_get( + "binary_sensor.test_mybinary_sensor_to_be_removed" + ) assert reg_entry is not None assert state.attributes[ATTR_RESTORED] is True @@ -114,7 +116,9 @@ async def test_entities_removed( assert state.state == STATE_ON state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed") assert state is None - reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed") + reg_entry = entity_registry.async_get( + "binary_sensor.test_mybinary_sensor_to_be_removed" + ) assert reg_entry is None await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() @@ -123,6 +127,7 @@ async def test_entities_removed( async def test_entities_removed_after_reload( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_client: APIClient, hass_storage: dict[str, Any], mock_esphome_device: Callable[ @@ -131,7 +136,6 @@ async def test_entities_removed_after_reload( ], ) -> None: """Test entities and their registry entry are removed when static info changes after a reload.""" - ent_reg = er.async_get(hass) entity_info = [ BinarySensorInfo( object_id="mybinary_sensor", @@ -167,7 +171,9 @@ async def test_entities_removed_after_reload( assert state is not None assert state.state == STATE_ON - reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed") + reg_entry = entity_registry.async_get( + "binary_sensor.test_mybinary_sensor_to_be_removed" + ) assert reg_entry is not None assert await hass.config_entries.async_unload(entry.entry_id) @@ -182,7 +188,9 @@ async def test_entities_removed_after_reload( assert state is not None assert state.attributes[ATTR_RESTORED] is True - reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed") + reg_entry = entity_registry.async_get( + "binary_sensor.test_mybinary_sensor_to_be_removed" + ) assert reg_entry is not None assert await hass.config_entries.async_setup(entry.entry_id) @@ -196,7 +204,9 @@ async def test_entities_removed_after_reload( state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed") assert state is not None assert ATTR_RESTORED not in state.attributes - reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed") + reg_entry = entity_registry.async_get( + "binary_sensor.test_mybinary_sensor_to_be_removed" + ) assert reg_entry is not None assert await hass.config_entries.async_unload(entry.entry_id) @@ -241,7 +251,9 @@ async def test_entities_removed_after_reload( await hass.async_block_till_done() - reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed") + reg_entry = entity_registry.async_get( + "binary_sensor.test_mybinary_sensor_to_be_removed" + ) assert reg_entry is None assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() diff --git a/tests/components/esphome/test_manager.py b/tests/components/esphome/test_manager.py index 7f7eed0ff04..a63f60e4dcb 100644 --- a/tests/components/esphome/test_manager.py +++ b/tests/components/esphome/test_manager.py @@ -968,6 +968,7 @@ async def test_esphome_user_services_changes( async def test_esphome_device_with_suggested_area( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, mock_client: APIClient, mock_esphome_device: Callable[ [APIClient, list[EntityInfo], list[UserService], list[EntityState]], @@ -983,9 +984,8 @@ async def test_esphome_device_with_suggested_area( states=[], ) await hass.async_block_till_done() - dev_reg = dr.async_get(hass) entry = device.entry - dev = dev_reg.async_get_device( + dev = device_registry.async_get_device( connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)} ) assert dev.suggested_area == "kitchen" @@ -993,6 +993,7 @@ async def test_esphome_device_with_suggested_area( async def test_esphome_device_with_project( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, mock_client: APIClient, mock_esphome_device: Callable[ [APIClient, list[EntityInfo], list[UserService], list[EntityState]], @@ -1008,9 +1009,8 @@ async def test_esphome_device_with_project( states=[], ) await hass.async_block_till_done() - dev_reg = dr.async_get(hass) entry = device.entry - dev = dev_reg.async_get_device( + dev = device_registry.async_get_device( connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)} ) assert dev.manufacturer == "mfr" @@ -1020,6 +1020,7 @@ async def test_esphome_device_with_project( async def test_esphome_device_with_manufacturer( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, mock_client: APIClient, mock_esphome_device: Callable[ [APIClient, list[EntityInfo], list[UserService], list[EntityState]], @@ -1035,9 +1036,8 @@ async def test_esphome_device_with_manufacturer( states=[], ) await hass.async_block_till_done() - dev_reg = dr.async_get(hass) entry = device.entry - dev = dev_reg.async_get_device( + dev = device_registry.async_get_device( connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)} ) assert dev.manufacturer == "acme" @@ -1045,6 +1045,7 @@ async def test_esphome_device_with_manufacturer( async def test_esphome_device_with_web_server( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, mock_client: APIClient, mock_esphome_device: Callable[ [APIClient, list[EntityInfo], list[UserService], list[EntityState]], @@ -1060,9 +1061,8 @@ async def test_esphome_device_with_web_server( states=[], ) await hass.async_block_till_done() - dev_reg = dr.async_get(hass) entry = device.entry - dev = dev_reg.async_get_device( + dev = device_registry.async_get_device( connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)} ) assert dev.configuration_url == "http://test.local:80" @@ -1070,6 +1070,7 @@ async def test_esphome_device_with_web_server( async def test_esphome_device_with_compilation_time( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, mock_client: APIClient, mock_esphome_device: Callable[ [APIClient, list[EntityInfo], list[UserService], list[EntityState]], @@ -1085,9 +1086,8 @@ async def test_esphome_device_with_compilation_time( states=[], ) await hass.async_block_till_done() - dev_reg = dr.async_get(hass) entry = device.entry - dev = dev_reg.async_get_device( + dev = device_registry.async_get_device( connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)} ) assert "comp_time" in dev.sw_version diff --git a/tests/components/esphome/test_sensor.py b/tests/components/esphome/test_sensor.py index 9f8e45ed64d..bebfaaa69d4 100644 --- a/tests/components/esphome/test_sensor.py +++ b/tests/components/esphome/test_sensor.py @@ -97,6 +97,7 @@ async def test_generic_numeric_sensor( async def test_generic_numeric_sensor_with_entity_category_and_icon( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_client: APIClient, mock_generic_device_entry, ) -> None: @@ -123,8 +124,7 @@ async def test_generic_numeric_sensor_with_entity_category_and_icon( assert state is not None assert state.state == "50" assert state.attributes[ATTR_ICON] == "mdi:leaf" - entity_reg = er.async_get(hass) - entry = entity_reg.async_get("sensor.test_mysensor") + entry = entity_registry.async_get("sensor.test_mysensor") assert entry is not None # Note that ESPHome includes the EntityInfo type in the unique id # as this is not a 1:1 mapping to the entity platform (ie. text_sensor) @@ -134,6 +134,7 @@ async def test_generic_numeric_sensor_with_entity_category_and_icon( async def test_generic_numeric_sensor_state_class_measurement( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_client: APIClient, mock_generic_device_entry, ) -> None: @@ -161,8 +162,7 @@ async def test_generic_numeric_sensor_state_class_measurement( assert state is not None assert state.state == "50" assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT - entity_reg = er.async_get(hass) - entry = entity_reg.async_get("sensor.test_mysensor") + entry = entity_registry.async_get("sensor.test_mysensor") assert entry is not None # Note that ESPHome includes the EntityInfo type in the unique id # as this is not a 1:1 mapping to the entity platform (ie. text_sensor) diff --git a/tests/components/home_connect/test_init.py b/tests/components/home_connect/test_init.py index e304e2947d5..6c12f5b6738 100644 --- a/tests/components/home_connect/test_init.py +++ b/tests/components/home_connect/test_init.py @@ -250,6 +250,7 @@ async def test_services( service_call: list[dict[str, Any]], bypass_throttle: Generator[None, Any, None], hass: HomeAssistant, + device_registry: dr.DeviceRegistry, config_entry: MockConfigEntry, integration_setup: Callable[[], Awaitable[bool]], setup_credentials: None, @@ -262,7 +263,6 @@ async def test_services( assert await integration_setup() assert config_entry.state == ConfigEntryState.LOADED - device_registry = dr.async_get(hass) device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, appliance.haId)}, diff --git a/tests/components/hyperion/test_sensor.py b/tests/components/hyperion/test_sensor.py index 8900db177fc..5ace34eaac0 100644 --- a/tests/components/hyperion/test_sensor.py +++ b/tests/components/hyperion/test_sensor.py @@ -52,14 +52,17 @@ async def test_sensor_has_correct_entities(hass: HomeAssistant) -> None: assert entity_state, f"Couldn't find entity: {entity_id}" -async def test_device_info(hass: HomeAssistant) -> None: +async def test_device_info( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, +) -> None: """Verify device information includes expected details.""" client = create_mock_client() client.components = TEST_COMPONENTS await setup_test_config_entry(hass, hyperion_client=client) device_identifer = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE) - device_registry = dr.async_get(hass) device = device_registry.async_get_device(identifiers={(DOMAIN, device_identifer)}) assert device @@ -69,7 +72,6 @@ async def test_device_info(hass: HomeAssistant) -> None: assert device.model == HYPERION_MODEL_NAME assert device.name == TEST_INSTANCE_1["friendly_name"] - entity_registry = er.async_get(hass) entities_from_device = [ entry.entity_id for entry in er.async_entries_for_device(entity_registry, device.id)