diff --git a/tests/components/samsungtv/test_remote.py b/tests/components/samsungtv/test_remote.py index efa4baf2c51..98cf712e0d2 100644 --- a/tests/components/samsungtv/test_remote.py +++ b/tests/components/samsungtv/test_remote.py @@ -32,12 +32,12 @@ async def test_setup(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("remoteencws", "rest_api") -async def test_unique_id(hass: HomeAssistant) -> None: +async def test_unique_id( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test unique id.""" await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS) - entity_registry = er.async_get(hass) - main = entity_registry.async_get(ENTITY_ID) assert main.unique_id == "any" diff --git a/tests/components/schedule/test_init.py b/tests/components/schedule/test_init.py index ddb98cee39d..a7e8449c845 100644 --- a/tests/components/schedule/test_init.py +++ b/tests/components/schedule/test_init.py @@ -569,16 +569,17 @@ async def test_ws_list( async def test_ws_delete( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, schedule_setup: Callable[..., Coroutine[Any, Any, bool]], ) -> None: """Test WS delete cleans up entity registry.""" - ent_reg = er.async_get(hass) - assert await schedule_setup() state = hass.states.get("schedule.from_storage") assert state is not None - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "from_storage") is not None + assert ( + entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "from_storage") is not None + ) client = await hass_ws_client(hass) await client.send_json( @@ -589,7 +590,7 @@ async def test_ws_delete( state = hass.states.get("schedule.from_storage") assert state is None - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "from_storage") is None + assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "from_storage") is None @pytest.mark.freeze_time("2022-08-10 20:10:00-07:00") @@ -604,14 +605,13 @@ async def test_ws_delete( async def test_update( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, schedule_setup: Callable[..., Coroutine[Any, Any, bool]], to: str, next_event: str, saved_to: str, ) -> None: """Test updating the schedule.""" - ent_reg = er.async_get(hass) - assert await schedule_setup() state = hass.states.get("schedule.from_storage") @@ -620,7 +620,9 @@ async def test_update( assert state.attributes[ATTR_FRIENDLY_NAME] == "from storage" assert state.attributes[ATTR_ICON] == "mdi:party-popper" assert state.attributes[ATTR_NEXT_EVENT].isoformat() == "2022-08-12T17:00:00-07:00" - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "from_storage") is not None + assert ( + entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "from_storage") is not None + ) client = await hass_ws_client(hass) @@ -674,6 +676,7 @@ async def test_update( async def test_ws_create( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, schedule_setup: Callable[..., Coroutine[Any, Any, bool]], freezer, to: str, @@ -683,13 +686,11 @@ async def test_ws_create( """Test create WS.""" freezer.move_to("2022-08-11 8:52:00-07:00") - ent_reg = er.async_get(hass) - assert await schedule_setup(items=[]) state = hass.states.get("schedule.party_mode") assert state is None - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "party_mode") is None + assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "party_mode") is None client = await hass_ws_client(hass) await client.send_json( diff --git a/tests/components/schlage/test_lock.py b/tests/components/schlage/test_lock.py index 5b26da7b27e..6c06f124693 100644 --- a/tests/components/schlage/test_lock.py +++ b/tests/components/schlage/test_lock.py @@ -14,10 +14,11 @@ from tests.common import async_fire_time_changed async def test_lock_device_registry( - hass: HomeAssistant, mock_added_config_entry: ConfigEntry + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_added_config_entry: ConfigEntry, ) -> None: """Test lock is added to device registry.""" - device_registry = dr.async_get(hass) device = device_registry.async_get_device(identifiers={("schlage", "test")}) assert device.model == "" assert device.sw_version == "1.0" diff --git a/tests/components/schlage/test_sensor.py b/tests/components/schlage/test_sensor.py index 775438795ff..2c0cabbb1e8 100644 --- a/tests/components/schlage/test_sensor.py +++ b/tests/components/schlage/test_sensor.py @@ -8,10 +8,11 @@ from homeassistant.helpers import device_registry as dr async def test_sensor_device_registry( - hass: HomeAssistant, mock_added_config_entry: ConfigEntry + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_added_config_entry: ConfigEntry, ) -> None: """Test sensor is added to device registry.""" - device_registry = dr.async_get(hass) device = device_registry.async_get_device(identifiers={("schlage", "test")}) assert device.model == "" assert device.sw_version == "1.0" diff --git a/tests/components/schlage/test_switch.py b/tests/components/schlage/test_switch.py index bf74a79b406..f1cded3ce22 100644 --- a/tests/components/schlage/test_switch.py +++ b/tests/components/schlage/test_switch.py @@ -10,10 +10,11 @@ from homeassistant.helpers import device_registry as dr async def test_switch_device_registry( - hass: HomeAssistant, mock_added_config_entry: ConfigEntry + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_added_config_entry: ConfigEntry, ) -> None: """Test switch is added to device registry.""" - device_registry = dr.async_get(hass) device = device_registry.async_get_device(identifiers={("schlage", "test")}) assert device.model == "" assert device.sw_version == "1.0" diff --git a/tests/components/scrape/test_init.py b/tests/components/scrape/test_init.py index 09036f213dc..363e30b9269 100644 --- a/tests/components/scrape/test_init.py +++ b/tests/components/scrape/test_init.py @@ -76,15 +76,16 @@ async def test_setup_no_data_fails_with_recovery( assert state.state == "Current Version: 2021.12.10" -async def test_setup_config_no_configuration(hass: HomeAssistant) -> None: +async def test_setup_config_no_configuration( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test setup from yaml missing configuration options.""" config = {DOMAIN: None} assert await async_setup_component(hass, DOMAIN, config) await hass.async_block_till_done() - entities = er.async_get(hass) - assert entities.entities == {} + assert entity_registry.entities == {} async def test_setup_config_no_sensors( @@ -131,15 +132,15 @@ async def test_unload_entry(hass: HomeAssistant, loaded_entry: MockConfigEntry) async def test_device_remove_devices( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, loaded_entry: MockConfigEntry, hass_ws_client: WebSocketGenerator, ) -> None: """Test we can only remove a device that no longer exists.""" assert await async_setup_component(hass, "config", {}) - registry: er.EntityRegistry = er.async_get(hass) - entity = registry.entities["sensor.current_version"] + entity = entity_registry.entities["sensor.current_version"] - device_registry = dr.async_get(hass) device_entry = device_registry.async_get(entity.device_id) client = await hass_ws_client(hass) response = await client.remove_device(device_entry.id, loaded_entry.entry_id) diff --git a/tests/components/scrape/test_sensor.py b/tests/components/scrape/test_sensor.py index 4d9c2b732dc..5b339b6a315 100644 --- a/tests/components/scrape/test_sensor.py +++ b/tests/components/scrape/test_sensor.py @@ -139,7 +139,9 @@ async def test_scrape_uom_and_classes(hass: HomeAssistant) -> None: assert state.attributes[CONF_STATE_CLASS] == SensorStateClass.MEASUREMENT -async def test_scrape_unique_id(hass: HomeAssistant) -> None: +async def test_scrape_unique_id( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test Scrape sensor for unique id.""" config = { DOMAIN: return_integration_config( @@ -165,8 +167,7 @@ async def test_scrape_unique_id(hass: HomeAssistant) -> None: state = hass.states.get("sensor.current_temp") assert state.state == "22.1" - registry = er.async_get(hass) - entry = registry.async_get("sensor.current_temp") + entry = entity_registry.async_get("sensor.current_temp") assert entry assert entry.unique_id == "very_unique_id" @@ -449,7 +450,9 @@ async def test_scrape_sensor_errors(hass: HomeAssistant) -> None: assert state2.state == STATE_UNKNOWN -async def test_scrape_sensor_unique_id(hass: HomeAssistant) -> None: +async def test_scrape_sensor_unique_id( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test Scrape sensor with unique_id.""" config = { DOMAIN: [ @@ -476,22 +479,22 @@ async def test_scrape_sensor_unique_id(hass: HomeAssistant) -> None: state = hass.states.get("sensor.ha_version") assert state.state == "Current Version: 2021.12.10" - entity_reg = er.async_get(hass) - entity = entity_reg.async_get("sensor.ha_version") + entity = entity_registry.async_get("sensor.ha_version") assert entity.unique_id == "ha_version_unique_id" async def test_setup_config_entry( - hass: HomeAssistant, loaded_entry: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + loaded_entry: MockConfigEntry, ) -> None: """Test setup from config entry.""" state = hass.states.get("sensor.current_version") assert state.state == "Current Version: 2021.12.10" - entity_reg = er.async_get(hass) - entity = entity_reg.async_get("sensor.current_version") + entity = entity_registry.async_get("sensor.current_version") assert entity.unique_id == "3699ef88-69e6-11ed-a1eb-0242ac120002" diff --git a/tests/components/screenlogic/test_data.py b/tests/components/screenlogic/test_data.py index d17db6c5b33..b0a8bf342f2 100644 --- a/tests/components/screenlogic/test_data.py +++ b/tests/components/screenlogic/test_data.py @@ -22,15 +22,13 @@ from tests.common import MockConfigEntry async def test_async_cleanup_entries( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, ) -> None: """Test cleanup of unused entities.""" - mock_config_entry.add_to_hass(hass) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) - device: dr.DeviceEntry = device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, MOCK_ADAPTER_MAC)}, diff --git a/tests/components/screenlogic/test_diagnostics.py b/tests/components/screenlogic/test_diagnostics.py index 0b587bcd0e5..c6d6ea60e87 100644 --- a/tests/components/screenlogic/test_diagnostics.py +++ b/tests/components/screenlogic/test_diagnostics.py @@ -23,14 +23,13 @@ from tests.typing import ClientSessionGenerator async def test_diagnostics( hass: HomeAssistant, hass_client: ClientSessionGenerator, + device_registry: dr.DeviceRegistry, mock_config_entry: MockConfigEntry, snapshot: SnapshotAssertion, ) -> None: """Test diagnostics.""" mock_config_entry.add_to_hass(hass) - device_registry = dr.async_get(hass) - device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, MOCK_ADAPTER_MAC)}, diff --git a/tests/components/screenlogic/test_init.py b/tests/components/screenlogic/test_init.py index 6aab9ecec93..6416c93f779 100644 --- a/tests/components/screenlogic/test_init.py +++ b/tests/components/screenlogic/test_init.py @@ -115,17 +115,15 @@ def _migration_connect(*args, **kwargs): ) async def test_async_migrate_entries( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, entity_def: dict, ent_data: EntityMigrationData, ) -> None: """Test migration to new entity names.""" - mock_config_entry.add_to_hass(hass) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) - device: dr.DeviceEntry = device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, MOCK_ADAPTER_MAC)}, @@ -181,15 +179,13 @@ async def test_async_migrate_entries( async def test_entity_migration_data( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, ) -> None: """Test ENTITY_MIGRATION data guards.""" - mock_config_entry.add_to_hass(hass) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) - device: dr.DeviceEntry = device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, MOCK_ADAPTER_MAC)}, diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index ca1d8006637..96275d80228 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -888,7 +888,9 @@ async def test_extraction_functions( assert script.blueprint_in_script(hass, "script.test3") is None -async def test_config_basic(hass: HomeAssistant) -> None: +async def test_config_basic( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test passing info in config.""" assert await async_setup_component( hass, @@ -908,8 +910,7 @@ async def test_config_basic(hass: HomeAssistant) -> None: assert test_script.name == "Script Name" assert test_script.attributes["icon"] == "mdi:party" - registry = er.async_get(hass) - entry = registry.async_get("script.test_script") + entry = entity_registry.async_get("script.test_script") assert entry assert entry.unique_id == "test_script" @@ -1503,11 +1504,12 @@ async def test_websocket_config( assert msg["error"]["code"] == "not_found" -async def test_script_service_changed_entity_id(hass: HomeAssistant) -> None: +async def test_script_service_changed_entity_id( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test the script service works for scripts with overridden entity_id.""" - entity_reg = er.async_get(hass) - entry = entity_reg.async_get_or_create("script", "script", "test") - entry = entity_reg.async_update_entity( + entry = entity_registry.async_get_or_create("script", "script", "test") + entry = entity_registry.async_update_entity( entry.entity_id, new_entity_id="script.custom_entity_id" ) assert entry.entity_id == "script.custom_entity_id" @@ -1545,7 +1547,7 @@ async def test_script_service_changed_entity_id(hass: HomeAssistant) -> None: assert calls[0].data["entity_id"] == "script.custom_entity_id" # Change entity while the script entity is loaded, and make sure the service still works - entry = entity_reg.async_update_entity( + entry = entity_registry.async_update_entity( entry.entity_id, new_entity_id="script.custom_entity_id_2" ) assert entry.entity_id == "script.custom_entity_id_2" diff --git a/tests/components/season/test_sensor.py b/tests/components/season/test_sensor.py index dd42ad6ce1c..ffc8e9f1a07 100644 --- a/tests/components/season/test_sensor.py +++ b/tests/components/season/test_sensor.py @@ -75,6 +75,7 @@ def idfn(val): @pytest.mark.parametrize(("type", "day", "expected"), NORTHERN_PARAMETERS, ids=idfn) async def test_season_northern_hemisphere( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, type: str, day: datetime, @@ -97,7 +98,6 @@ async def test_season_northern_hemisphere( assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENUM assert state.attributes[ATTR_OPTIONS] == ["spring", "summer", "autumn", "winter"] - entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.season") assert entry assert entry.unique_id == mock_config_entry.entry_id @@ -107,6 +107,8 @@ async def test_season_northern_hemisphere( @pytest.mark.parametrize(("type", "day", "expected"), SOUTHERN_PARAMETERS, ids=idfn) async def test_season_southern_hemisphere( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, type: str, day: datetime, @@ -129,13 +131,11 @@ async def test_season_southern_hemisphere( assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENUM assert state.attributes[ATTR_OPTIONS] == ["spring", "summer", "autumn", "winter"] - entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.season") assert entry assert entry.unique_id == mock_config_entry.entry_id assert entry.translation_key == "season" - device_registry = dr.async_get(hass) assert entry.device_id device_entry = device_registry.async_get(entry.device_id) assert device_entry @@ -146,6 +146,7 @@ async def test_season_southern_hemisphere( async def test_season_equator( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, ) -> None: """Test that season should be unknown for equator.""" @@ -160,7 +161,6 @@ async def test_season_equator( assert state assert state.state == STATE_UNKNOWN - entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.season") assert entry assert entry.unique_id == mock_config_entry.entry_id diff --git a/tests/components/sensibo/test_entity.py b/tests/components/sensibo/test_entity.py index 071e5473e5c..e17877b63b1 100644 --- a/tests/components/sensibo/test_entity.py +++ b/tests/components/sensibo/test_entity.py @@ -21,24 +21,26 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er async def test_entity( - hass: HomeAssistant, load_int: ConfigEntry, get_data: SensiboData + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + load_int: ConfigEntry, + get_data: SensiboData, ) -> None: """Test the Sensibo climate.""" state1 = hass.states.get("climate.hallway") assert state1 - dr_reg = dr.async_get(hass) - dr_entries = dr.async_entries_for_config_entry(dr_reg, load_int.entry_id) + dr_entries = dr.async_entries_for_config_entry(device_registry, load_int.entry_id) dr_entry: dr.DeviceEntry for dr_entry in dr_entries: if dr_entry.name == "Hallway": assert dr_entry.identifiers == {("sensibo", "ABC999111")} device_id = dr_entry.id - er_reg = er.async_get(hass) er_entries = er.async_entries_for_device( - er_reg, device_id, include_disabled_entities=True + entity_registry, device_id, include_disabled_entities=True ) er_entry: er.RegistryEntry for er_entry in er_entries: diff --git a/tests/components/sensibo/test_init.py b/tests/components/sensibo/test_init.py index 7138da9191f..2938d4ede0e 100644 --- a/tests/components/sensibo/test_init.py +++ b/tests/components/sensibo/test_init.py @@ -154,15 +154,15 @@ async def test_unload_entry(hass: HomeAssistant, get_data: SensiboData) -> None: async def test_device_remove_devices( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, load_int: ConfigEntry, hass_ws_client: WebSocketGenerator, ) -> None: """Test we can only remove a device that no longer exists.""" assert await async_setup_component(hass, "config", {}) - registry: er.EntityRegistry = er.async_get(hass) - entity = registry.entities["climate.hallway"] + entity = entity_registry.entities["climate.hallway"] - device_registry = dr.async_get(hass) device_entry = device_registry.async_get(entity.device_id) client = await hass_ws_client(hass) response = await client.remove_device(device_entry.id, load_int.entry_id) diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index 079984476b0..100b7ec7186 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -603,6 +603,7 @@ async def test_restore_sensor_restore_state( ) async def test_custom_unit( hass: HomeAssistant, + entity_registry: er.EntityRegistry, device_class, native_unit, custom_unit, @@ -611,8 +612,6 @@ async def test_custom_unit( custom_state, ) -> None: """Test custom unit.""" - entity_registry = er.async_get(hass) - entry = entity_registry.async_get_or_create("sensor", "test", "very_unique") entity_registry.async_update_entity_options( entry.entity_id, "sensor", {"unit_of_measurement": custom_unit} @@ -863,6 +862,7 @@ async def test_custom_unit( ) async def test_custom_unit_change( hass: HomeAssistant, + entity_registry: er.EntityRegistry, native_unit, custom_unit, state_unit, @@ -872,7 +872,6 @@ async def test_custom_unit_change( device_class, ) -> None: """Test custom unit changes are picked up.""" - entity_registry = er.async_get(hass) entity0 = MockSensor( name="Test", native_value=str(native_value), @@ -948,6 +947,7 @@ async def test_custom_unit_change( ) async def test_unit_conversion_priority( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system, native_unit, automatic_unit, @@ -964,8 +964,6 @@ async def test_unit_conversion_priority( hass.config.units = unit_system - entity_registry = er.async_get(hass) - entity0 = MockSensor( name="Test", device_class=device_class, @@ -1095,6 +1093,7 @@ async def test_unit_conversion_priority( ) async def test_unit_conversion_priority_precision( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system, native_unit, automatic_unit, @@ -1112,8 +1111,6 @@ async def test_unit_conversion_priority_precision( hass.config.units = unit_system - entity_registry = er.async_get(hass) - entity0 = MockSensor( name="Test", device_class=device_class, @@ -1280,6 +1277,7 @@ async def test_unit_conversion_priority_precision( ) async def test_unit_conversion_priority_suggested_unit_change( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system, native_unit, original_unit, @@ -1292,8 +1290,6 @@ async def test_unit_conversion_priority_suggested_unit_change( hass.config.units = unit_system - entity_registry = er.async_get(hass) - # Pre-register entities entry = entity_registry.async_get_or_create( "sensor", "test", "very_unique", unit_of_measurement=original_unit @@ -1387,6 +1383,7 @@ async def test_unit_conversion_priority_suggested_unit_change( ) async def test_unit_conversion_priority_suggested_unit_change_2( hass: HomeAssistant, + entity_registry: er.EntityRegistry, native_unit_1, native_unit_2, suggested_unit, @@ -1398,8 +1395,6 @@ async def test_unit_conversion_priority_suggested_unit_change_2( hass.config.units = METRIC_SYSTEM - entity_registry = er.async_get(hass) - # Pre-register entities entity_registry.async_get_or_create( "sensor", "test", "very_unique", unit_of_measurement=native_unit_1 @@ -1486,6 +1481,7 @@ async def test_unit_conversion_priority_suggested_unit_change_2( ) async def test_suggested_precision_option( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system, native_unit, integration_suggested_precision, @@ -1498,7 +1494,6 @@ async def test_suggested_precision_option( hass.config.units = unit_system - entity_registry = er.async_get(hass) entity0 = MockSensor( name="Test", device_class=device_class, @@ -1560,6 +1555,7 @@ async def test_suggested_precision_option( ) async def test_suggested_precision_option_update( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system, native_unit, suggested_unit, @@ -1574,8 +1570,6 @@ async def test_suggested_precision_option_update( hass.config.units = unit_system - entity_registry = er.async_get(hass) - # Pre-register entities entry = entity_registry.async_get_or_create("sensor", "test", "very_unique") entity_registry.async_update_entity_options( @@ -1620,11 +1614,9 @@ async def test_suggested_precision_option_update( async def test_suggested_precision_option_removal( hass: HomeAssistant, + entity_registry: er.EntityRegistry, ) -> None: """Test suggested precision stored in the registry is removed.""" - - entity_registry = er.async_get(hass) - # Pre-register entities entry = entity_registry.async_get_or_create("sensor", "test", "very_unique") entity_registry.async_update_entity_options( @@ -1684,6 +1676,7 @@ async def test_suggested_precision_option_removal( ) async def test_unit_conversion_priority_legacy_conversion_removed( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system, native_unit, original_unit, @@ -1695,8 +1688,6 @@ async def test_unit_conversion_priority_legacy_conversion_removed( hass.config.units = unit_system - entity_registry = er.async_get(hass) - # Pre-register entities entity_registry.async_get_or_create( "sensor", "test", "very_unique", unit_of_measurement=original_unit @@ -2187,6 +2178,7 @@ async def test_numeric_state_expected_helper( ) async def test_unit_conversion_update( hass: HomeAssistant, + entity_registry: er.EntityRegistry, unit_system_1, unit_system_2, native_unit, @@ -2205,8 +2197,6 @@ async def test_unit_conversion_update( hass.config.units = unit_system_1 - entity_registry = er.async_get(hass) - entity0 = MockSensor( name="Test 0", device_class=device_class, @@ -2491,13 +2481,12 @@ def test_async_rounded_state_unregistered_entity_is_passthrough( def test_async_rounded_state_registered_entity_with_display_precision( hass: HomeAssistant, + entity_registry: er.EntityRegistry, ) -> None: """Test async_rounded_state on registered with display precision. The -0 should be dropped. """ - entity_registry = er.async_get(hass) - entry = entity_registry.async_get_or_create("sensor", "test", "very_unique") entity_registry.async_update_entity_options( entry.entity_id, @@ -2618,6 +2607,7 @@ def test_deprecated_constants_sensor_device_class( ) async def test_suggested_unit_guard_invalid_unit( hass: HomeAssistant, + entity_registry: er.EntityRegistry, caplog: pytest.LogCaptureFixture, device_class: SensorDeviceClass, native_unit: str, @@ -2626,8 +2616,6 @@ async def test_suggested_unit_guard_invalid_unit( An invalid suggested unit creates a log entry and the suggested unit will be ignored. """ - entity_registry = er.async_get(hass) - state_value = 10 invalid_suggested_unit = "invalid_unit" @@ -2685,6 +2673,7 @@ async def test_suggested_unit_guard_invalid_unit( ) async def test_suggested_unit_guard_valid_unit( hass: HomeAssistant, + entity_registry: er.EntityRegistry, device_class: SensorDeviceClass, native_unit: str, native_value: int, @@ -2696,8 +2685,6 @@ async def test_suggested_unit_guard_valid_unit( Suggested unit is valid and therefore should be used for unit conversion and stored in the entity registry. """ - entity_registry = er.async_get(hass) - entity = MockSensor( name="Valid", device_class=device_class, diff --git a/tests/components/sharkiq/test_vacuum.py b/tests/components/sharkiq/test_vacuum.py index a3d03ecf4f7..edf27101d6e 100644 --- a/tests/components/sharkiq/test_vacuum.py +++ b/tests/components/sharkiq/test_vacuum.py @@ -151,11 +151,12 @@ async def setup_integration(hass): await hass.async_block_till_done() -async def test_simple_properties(hass: HomeAssistant) -> None: +async def test_simple_properties( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test that simple properties work as intended.""" state = hass.states.get(VAC_ENTITY_ID) - registry = er.async_get(hass) - entity = registry.async_get(VAC_ENTITY_ID) + entity = entity_registry.async_get(VAC_ENTITY_ID) assert entity assert state @@ -225,11 +226,13 @@ async def test_fan_speed(hass: HomeAssistant, fan_speed: str) -> None: ], ) async def test_device_properties( - hass: HomeAssistant, device_property: str, target_value: str + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + device_property: str, + target_value: str, ) -> None: """Test device properties.""" - registry = dr.async_get(hass) - device = registry.async_get_device(identifiers={(DOMAIN, "AC000Wxxxxxxxxx")}) + device = device_registry.async_get_device(identifiers={(DOMAIN, "AC000Wxxxxxxxxx")}) assert getattr(device, device_property) == target_value diff --git a/tests/components/shelly/test_valve.py b/tests/components/shelly/test_valve.py index b588cd28906..58b55e4f2dd 100644 --- a/tests/components/shelly/test_valve.py +++ b/tests/components/shelly/test_valve.py @@ -24,14 +24,16 @@ GAS_VALVE_BLOCK_ID = 6 async def test_block_device_gas_valve( - hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_block_device: Mock, + monkeypatch: pytest.MonkeyPatch, ) -> None: """Test block device Shelly Gas with Valve addon.""" - registry = er.async_get(hass) await init_integration(hass, 1, MODEL_GAS) entity_id = "valve.test_name_valve" - entry = registry.async_get(entity_id) + entry = entity_registry.async_get(entity_id) assert entry assert entry.unique_id == "123456789ABC-valve_0-valve" diff --git a/tests/components/simplisafe/test_init.py b/tests/components/simplisafe/test_init.py index f626f479a2f..130ce59cd4a 100644 --- a/tests/components/simplisafe/test_init.py +++ b/tests/components/simplisafe/test_init.py @@ -9,13 +9,12 @@ from homeassistant.setup import async_setup_component async def test_base_station_migration( - hass: HomeAssistant, api, config, config_entry + hass: HomeAssistant, device_registry: dr.DeviceRegistry, api, config, config_entry ) -> None: """Test that errors are shown when duplicates are added.""" old_identifers = (DOMAIN, 12345) new_identifiers = (DOMAIN, "12345") - device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={old_identifers}, diff --git a/tests/components/sleepiq/test_binary_sensor.py b/tests/components/sleepiq/test_binary_sensor.py index bbb0200dd23..65654de74ac 100644 --- a/tests/components/sleepiq/test_binary_sensor.py +++ b/tests/components/sleepiq/test_binary_sensor.py @@ -24,10 +24,11 @@ from .conftest import ( ) -async def test_binary_sensors(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_binary_sensors( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ binary sensors.""" await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"binary_sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_is_in_bed" diff --git a/tests/components/sleepiq/test_button.py b/tests/components/sleepiq/test_button.py index 0979d01ba7b..33ad4d72b46 100644 --- a/tests/components/sleepiq/test_button.py +++ b/tests/components/sleepiq/test_button.py @@ -8,10 +8,11 @@ from homeassistant.helpers import entity_registry as er from .conftest import BED_ID, BED_NAME, BED_NAME_LOWER, setup_platform -async def test_button_calibrate(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_button_calibrate( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ calibrate button.""" await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get(f"button.sleepnumber_{BED_NAME_LOWER}_calibrate") assert ( @@ -33,10 +34,11 @@ async def test_button_calibrate(hass: HomeAssistant, mock_asyncsleepiq) -> None: mock_asyncsleepiq.beds[BED_ID].calibrate.assert_called_once() -async def test_button_stop_pump(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_button_stop_pump( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ stop pump button.""" await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get(f"button.sleepnumber_{BED_NAME_LOWER}_stop_pump") assert ( diff --git a/tests/components/sleepiq/test_light.py b/tests/components/sleepiq/test_light.py index e261115c415..9564bca7a99 100644 --- a/tests/components/sleepiq/test_light.py +++ b/tests/components/sleepiq/test_light.py @@ -12,10 +12,11 @@ from .conftest import BED_ID, BED_NAME, BED_NAME_LOWER, setup_platform from tests.common import async_fire_time_changed -async def test_setup(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_setup( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test for successfully setting up the SleepIQ platform.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) assert len(entity_registry.entities) == 2 diff --git a/tests/components/sleepiq/test_number.py b/tests/components/sleepiq/test_number.py index f3a38cc89e5..52df2eb27aa 100644 --- a/tests/components/sleepiq/test_number.py +++ b/tests/components/sleepiq/test_number.py @@ -26,10 +26,11 @@ from .conftest import ( ) -async def test_firmness(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_firmness( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ firmness number values for a bed with two sides.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_firmness" @@ -84,10 +85,11 @@ async def test_firmness(hass: HomeAssistant, mock_asyncsleepiq) -> None: mock_asyncsleepiq.beds[BED_ID].sleepers[0].set_sleepnumber.assert_called_with(42) -async def test_actuators(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_actuators( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ actuator position values for a bed with adjustable head and foot.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get(f"number.sleepnumber_{BED_NAME_LOWER}_right_head_position") assert state.state == "60.0" @@ -159,10 +161,11 @@ async def test_actuators(hass: HomeAssistant, mock_asyncsleepiq) -> None: ].set_position.assert_called_with(42) -async def test_foot_warmer_timer(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_foot_warmer_timer( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ foot warmer number values for a bed with two sides.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warming_timer" diff --git a/tests/components/sleepiq/test_select.py b/tests/components/sleepiq/test_select.py index cc61494689e..ef4c7fb6df0 100644 --- a/tests/components/sleepiq/test_select.py +++ b/tests/components/sleepiq/test_select.py @@ -32,11 +32,12 @@ from .conftest import ( async def test_split_foundation_preset( - hass: HomeAssistant, mock_asyncsleepiq: MagicMock + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_asyncsleepiq: MagicMock, ) -> None: """Test the SleepIQ select entity for split foundation presets.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset_right" @@ -88,11 +89,12 @@ async def test_split_foundation_preset( async def test_single_foundation_preset( - hass: HomeAssistant, mock_asyncsleepiq_single_foundation: MagicMock + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_asyncsleepiq_single_foundation: MagicMock, ) -> None: """Test the SleepIQ select entity for single foundation presets.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get(f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset") assert state.state == PRESET_R_STATE @@ -127,10 +129,13 @@ async def test_single_foundation_preset( ].set_preset.assert_called_with("Zero G") -async def test_foot_warmer(hass: HomeAssistant, mock_asyncsleepiq: MagicMock) -> None: +async def test_foot_warmer( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_asyncsleepiq: MagicMock, +) -> None: """Test the SleepIQ select entity for foot warmers.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warmer" diff --git a/tests/components/sleepiq/test_sensor.py b/tests/components/sleepiq/test_sensor.py index c027aaee87b..ae25958419c 100644 --- a/tests/components/sleepiq/test_sensor.py +++ b/tests/components/sleepiq/test_sensor.py @@ -18,10 +18,11 @@ from .conftest import ( ) -async def test_sleepnumber_sensors(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_sleepnumber_sensors( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ sleepnumber for a bed with two sides.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_sleepnumber" @@ -56,10 +57,11 @@ async def test_sleepnumber_sensors(hass: HomeAssistant, mock_asyncsleepiq) -> No assert entry.unique_id == f"{SLEEPER_R_ID}_sleep_number" -async def test_pressure_sensors(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_pressure_sensors( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test the SleepIQ pressure for a bed with two sides.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) state = hass.states.get( f"sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_pressure" diff --git a/tests/components/sleepiq/test_switch.py b/tests/components/sleepiq/test_switch.py index 8ab865663dc..7c41b6b9d19 100644 --- a/tests/components/sleepiq/test_switch.py +++ b/tests/components/sleepiq/test_switch.py @@ -12,10 +12,11 @@ from .conftest import BED_ID, BED_NAME, BED_NAME_LOWER, setup_platform from tests.common import async_fire_time_changed -async def test_setup(hass: HomeAssistant, mock_asyncsleepiq) -> None: +async def test_setup( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq +) -> None: """Test for successfully setting up the SleepIQ platform.""" entry = await setup_platform(hass, DOMAIN) - entity_registry = er.async_get(hass) assert len(entity_registry.entities) == 1 diff --git a/tests/components/smartthings/test_binary_sensor.py b/tests/components/smartthings/test_binary_sensor.py index 9d704cdf8c9..52fd5d28aa7 100644 --- a/tests/components/smartthings/test_binary_sensor.py +++ b/tests/components/smartthings/test_binary_sensor.py @@ -47,7 +47,10 @@ async def test_entity_state(hass: HomeAssistant, device_factory) -> None: async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -62,8 +65,6 @@ async def test_entity_and_device_attributes( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, BINARY_SENSOR_DOMAIN, devices=[device]) # Assert @@ -117,7 +118,9 @@ async def test_unload_config_entry(hass: HomeAssistant, device_factory) -> None: ) -async def test_entity_category(hass: HomeAssistant, device_factory) -> None: +async def test_entity_category( + hass: HomeAssistant, entity_registry: er.EntityRegistry, device_factory +) -> None: """Tests the state attributes properly match the light types.""" device1 = device_factory( "Motion Sensor 1", [Capability.motion_sensor], {Attribute.motion: "inactive"} @@ -127,7 +130,6 @@ async def test_entity_category(hass: HomeAssistant, device_factory) -> None: ) await setup_platform(hass, BINARY_SENSOR_DOMAIN, devices=[device1, device2]) - entity_registry = er.async_get(hass) entry = entity_registry.async_get("binary_sensor.motion_sensor_1_motion") assert entry assert entry.entity_category is None diff --git a/tests/components/smartthings/test_climate.py b/tests/components/smartthings/test_climate.py index 3fb293e587f..b5fcc9f7647 100644 --- a/tests/components/smartthings/test_climate.py +++ b/tests/components/smartthings/test_climate.py @@ -597,11 +597,14 @@ async def test_set_turn_on(hass: HomeAssistant, air_conditioner) -> None: assert state.state == HVACMode.HEAT_COOL -async def test_entity_and_device_attributes(hass: HomeAssistant, thermostat) -> None: +async def test_entity_and_device_attributes( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + thermostat, +) -> None: """Test the attributes of the entries are correct.""" await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat]) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) entry = entity_registry.async_get("climate.thermostat") assert entry diff --git a/tests/components/smartthings/test_cover.py b/tests/components/smartthings/test_cover.py index e19ac403e5d..bb292b53ee8 100644 --- a/tests/components/smartthings/test_cover.py +++ b/tests/components/smartthings/test_cover.py @@ -29,7 +29,10 @@ from .conftest import setup_platform async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -44,8 +47,6 @@ async def test_entity_and_device_attributes( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, COVER_DOMAIN, devices=[device]) # Assert diff --git a/tests/components/smartthings/test_fan.py b/tests/components/smartthings/test_fan.py index b8928ef5247..043c022b225 100644 --- a/tests/components/smartthings/test_fan.py +++ b/tests/components/smartthings/test_fan.py @@ -44,7 +44,10 @@ async def test_entity_state(hass: HomeAssistant, device_factory) -> None: async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -62,8 +65,6 @@ async def test_entity_and_device_attributes( ) # Act await setup_platform(hass, FAN_DOMAIN, devices=[device]) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Assert entry = entity_registry.async_get("fan.fan_1") assert entry diff --git a/tests/components/smartthings/test_light.py b/tests/components/smartthings/test_light.py index 53de2273707..22b181a3645 100644 --- a/tests/components/smartthings/test_light.py +++ b/tests/components/smartthings/test_light.py @@ -106,7 +106,10 @@ async def test_entity_state(hass: HomeAssistant, light_devices) -> None: async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -120,8 +123,6 @@ async def test_entity_and_device_attributes( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, LIGHT_DOMAIN, devices=[device]) # Assert diff --git a/tests/components/smartthings/test_lock.py b/tests/components/smartthings/test_lock.py index 2e149df6213..3c2a2651fb9 100644 --- a/tests/components/smartthings/test_lock.py +++ b/tests/components/smartthings/test_lock.py @@ -19,7 +19,10 @@ from .conftest import setup_platform async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -34,8 +37,6 @@ async def test_entity_and_device_attributes( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, LOCK_DOMAIN, devices=[device]) # Assert diff --git a/tests/components/smartthings/test_scene.py b/tests/components/smartthings/test_scene.py index d33db0a1dd9..a20db1aaae8 100644 --- a/tests/components/smartthings/test_scene.py +++ b/tests/components/smartthings/test_scene.py @@ -13,10 +13,10 @@ from homeassistant.helpers import entity_registry as er from .conftest import setup_platform -async def test_entity_and_device_attributes(hass: HomeAssistant, scene) -> None: +async def test_entity_and_device_attributes( + hass: HomeAssistant, entity_registry: er.EntityRegistry, scene +) -> None: """Test the attributes of the entity are correct.""" - # Arrange - entity_registry = er.async_get(hass) # Act await setup_platform(hass, SCENE_DOMAIN, scenes=[scene]) # Assert diff --git a/tests/components/smartthings/test_sensor.py b/tests/components/smartthings/test_sensor.py index 6529a7f25f0..021ee9cc810 100644 --- a/tests/components/smartthings/test_sensor.py +++ b/tests/components/smartthings/test_sensor.py @@ -87,7 +87,10 @@ async def test_entity_three_axis_invalid_state( async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -102,8 +105,6 @@ async def test_entity_and_device_attributes( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) # Assert @@ -123,7 +124,10 @@ async def test_entity_and_device_attributes( async def test_energy_sensors_for_switch_device( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -140,8 +144,6 @@ async def test_energy_sensors_for_switch_device( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) # Assert @@ -180,7 +182,12 @@ async def test_energy_sensors_for_switch_device( assert entry.sw_version == "v7.89" -async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> None: +async def test_power_consumption_sensor( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, +) -> None: """Test the attributes of the entity are correct.""" # Arrange device = device_factory( @@ -203,8 +210,6 @@ async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) # Assert @@ -253,8 +258,6 @@ async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) # Assert diff --git a/tests/components/smartthings/test_switch.py b/tests/components/smartthings/test_switch.py index d858a9eea5a..fadd7600e87 100644 --- a/tests/components/smartthings/test_switch.py +++ b/tests/components/smartthings/test_switch.py @@ -18,7 +18,10 @@ from .conftest import setup_platform async def test_entity_and_device_attributes( - hass: HomeAssistant, device_factory + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + device_factory, ) -> None: """Test the attributes of the entity are correct.""" # Arrange @@ -33,8 +36,6 @@ async def test_entity_and_device_attributes( Attribute.mnfv: "v7.89", }, ) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) # Act await setup_platform(hass, SWITCH_DOMAIN, devices=[device]) # Assert diff --git a/tests/components/smhi/test_weather.py b/tests/components/smhi/test_weather.py index e5b8155f9ca..0794148915c 100644 --- a/tests/components/smhi/test_weather.py +++ b/tests/components/smhi/test_weather.py @@ -349,7 +349,10 @@ def test_condition_class() -> None: async def test_custom_speed_unit( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, api_response: str + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + aioclient_mock: AiohttpClientMocker, + api_response: str, ) -> None: """Test Wind Gust speed with custom unit.""" uri = APIURL_TEMPLATE.format( @@ -369,8 +372,7 @@ async def test_custom_speed_unit( assert state.name == "test" assert state.attributes[ATTR_WEATHER_WIND_GUST_SPEED] == 22.32 - entity_reg = er.async_get(hass) - entity_reg.async_update_entity_options( + entity_registry.async_update_entity_options( state.entity_id, WEATHER_DOMAIN, {ATTR_WEATHER_WIND_SPEED_UNIT: UnitOfSpeed.METERS_PER_SECOND}, diff --git a/tests/components/snmp/test_float_sensor.py b/tests/components/snmp/test_float_sensor.py index 0e11ee03968..a4f6e21dad7 100644 --- a/tests/components/snmp/test_float_sensor.py +++ b/tests/components/snmp/test_float_sensor.py @@ -41,7 +41,9 @@ async def test_basic_config(hass: HomeAssistant) -> None: assert state.attributes == {"friendly_name": "SNMP"} -async def test_entity_config(hass: HomeAssistant) -> None: +async def test_entity_config( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test entity configuration.""" config = { @@ -64,7 +66,6 @@ async def test_entity_config(hass: HomeAssistant) -> None: assert await async_setup_component(hass, SENSOR_DOMAIN, config) await hass.async_block_till_done() - entity_registry = er.async_get(hass) assert entity_registry.async_get("sensor.snmp_sensor").unique_id == "very_unique" state = hass.states.get("sensor.snmp_sensor") diff --git a/tests/components/snmp/test_integer_sensor.py b/tests/components/snmp/test_integer_sensor.py index 0ea9ac4d434..dab2b080c97 100644 --- a/tests/components/snmp/test_integer_sensor.py +++ b/tests/components/snmp/test_integer_sensor.py @@ -41,7 +41,9 @@ async def test_basic_config(hass: HomeAssistant) -> None: assert state.attributes == {"friendly_name": "SNMP"} -async def test_entity_config(hass: HomeAssistant) -> None: +async def test_entity_config( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test entity configuration.""" config = { @@ -64,7 +66,6 @@ async def test_entity_config(hass: HomeAssistant) -> None: assert await async_setup_component(hass, SENSOR_DOMAIN, config) await hass.async_block_till_done() - entity_registry = er.async_get(hass) assert entity_registry.async_get("sensor.snmp_sensor").unique_id == "very_unique" state = hass.states.get("sensor.snmp_sensor") diff --git a/tests/components/snmp/test_negative_sensor.py b/tests/components/snmp/test_negative_sensor.py index c5ac6460841..dba09ea75bd 100644 --- a/tests/components/snmp/test_negative_sensor.py +++ b/tests/components/snmp/test_negative_sensor.py @@ -41,7 +41,9 @@ async def test_basic_config(hass: HomeAssistant) -> None: assert state.attributes == {"friendly_name": "SNMP"} -async def test_entity_config(hass: HomeAssistant) -> None: +async def test_entity_config( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test entity configuration.""" config = { @@ -64,7 +66,6 @@ async def test_entity_config(hass: HomeAssistant) -> None: assert await async_setup_component(hass, SENSOR_DOMAIN, config) await hass.async_block_till_done() - entity_registry = er.async_get(hass) assert entity_registry.async_get("sensor.snmp_sensor").unique_id == "very_unique" state = hass.states.get("sensor.snmp_sensor") diff --git a/tests/components/snmp/test_string_sensor.py b/tests/components/snmp/test_string_sensor.py index 536b819b711..5362e79c98d 100644 --- a/tests/components/snmp/test_string_sensor.py +++ b/tests/components/snmp/test_string_sensor.py @@ -41,7 +41,9 @@ async def test_basic_config(hass: HomeAssistant) -> None: assert state.attributes == {"friendly_name": "SNMP"} -async def test_entity_config(hass: HomeAssistant) -> None: +async def test_entity_config( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test entity configuration.""" config = { @@ -61,7 +63,6 @@ async def test_entity_config(hass: HomeAssistant) -> None: assert await async_setup_component(hass, SENSOR_DOMAIN, config) await hass.async_block_till_done() - entity_registry = er.async_get(hass) assert entity_registry.async_get("sensor.snmp_sensor").unique_id == "very_unique" state = hass.states.get("sensor.snmp_sensor") diff --git a/tests/components/sonarr/test_sensor.py b/tests/components/sonarr/test_sensor.py index 3641ae95de8..1221cc86df3 100644 --- a/tests/components/sonarr/test_sensor.py +++ b/tests/components/sonarr/test_sensor.py @@ -24,13 +24,12 @@ UPCOMING_ENTITY_ID = f"{SENSOR_DOMAIN}.sonarr_upcoming" async def test_sensors( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, mock_sonarr: MagicMock, entity_registry_enabled_by_default: None, ) -> None: """Test the creation and values of the sensors.""" - registry = er.async_get(hass) - sensors = { "commands": "sonarr_commands", "diskspace": "sonarr_disk_space", @@ -44,7 +43,7 @@ async def test_sensors( await hass.async_block_till_done() for unique, oid in sensors.items(): - entity = registry.async_get(f"sensor.{oid}") + entity = entity_registry.async_get(f"sensor.{oid}") assert entity assert entity.unique_id == f"{mock_config_entry.entry_id}_{unique}" @@ -100,16 +99,15 @@ async def test_sensors( ) async def test_disabled_by_default_sensors( hass: HomeAssistant, + entity_registry: er.EntityRegistry, init_integration: MockConfigEntry, entity_id: str, ) -> None: """Test the disabled by default sensors.""" - registry = er.async_get(hass) - state = hass.states.get(entity_id) assert state is None - entry = registry.async_get(entity_id) + entry = entity_registry.async_get(entity_id) assert entry assert entry.disabled assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION diff --git a/tests/components/songpal/test_media_player.py b/tests/components/songpal/test_media_player.py index 88443bf58b9..ea2812c60f6 100644 --- a/tests/components/songpal/test_media_player.py +++ b/tests/components/songpal/test_media_player.py @@ -122,7 +122,11 @@ async def test_setup_failed( assert not any(x.levelno == logging.ERROR for x in caplog.records) -async def test_state(hass: HomeAssistant) -> None: +async def test_state( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, +) -> None: """Test state of the entity.""" mocked_device = _create_mocked_device() entry = MockConfigEntry(domain=songpal.DOMAIN, data=CONF_DATA) @@ -144,7 +148,6 @@ async def test_state(hass: HomeAssistant) -> None: assert attributes["sound_mode"] == "Sound Mode 2" assert attributes["supported_features"] == SUPPORT_SONGPAL - device_registry = dr.async_get(hass) device = device_registry.async_get_device(identifiers={(songpal.DOMAIN, MAC)}) assert device.connections == {(dr.CONNECTION_NETWORK_MAC, MAC)} assert device.manufacturer == "Sony Corporation" @@ -152,12 +155,15 @@ async def test_state(hass: HomeAssistant) -> None: assert device.sw_version == SW_VERSION assert device.model == MODEL - entity_registry = er.async_get(hass) entity = entity_registry.async_get(ENTITY_ID) assert entity.unique_id == MAC -async def test_state_wireless(hass: HomeAssistant) -> None: +async def test_state_wireless( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, +) -> None: """Test state of the entity with only Wireless MAC.""" mocked_device = _create_mocked_device(wired_mac=None, wireless_mac=WIRELESS_MAC) entry = MockConfigEntry(domain=songpal.DOMAIN, data=CONF_DATA) @@ -179,7 +185,6 @@ async def test_state_wireless(hass: HomeAssistant) -> None: assert attributes["sound_mode"] == "Sound Mode 2" assert attributes["supported_features"] == SUPPORT_SONGPAL - device_registry = dr.async_get(hass) device = device_registry.async_get_device( identifiers={(songpal.DOMAIN, WIRELESS_MAC)} ) @@ -189,12 +194,15 @@ async def test_state_wireless(hass: HomeAssistant) -> None: assert device.sw_version == SW_VERSION assert device.model == MODEL - entity_registry = er.async_get(hass) entity = entity_registry.async_get(ENTITY_ID) assert entity.unique_id == WIRELESS_MAC -async def test_state_both(hass: HomeAssistant) -> None: +async def test_state_both( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, +) -> None: """Test state of the entity with both Wired and Wireless MAC.""" mocked_device = _create_mocked_device(wired_mac=MAC, wireless_mac=WIRELESS_MAC) entry = MockConfigEntry(domain=songpal.DOMAIN, data=CONF_DATA) @@ -216,7 +224,6 @@ async def test_state_both(hass: HomeAssistant) -> None: assert attributes["sound_mode"] == "Sound Mode 2" assert attributes["supported_features"] == SUPPORT_SONGPAL - device_registry = dr.async_get(hass) device = device_registry.async_get_device(identifiers={(songpal.DOMAIN, MAC)}) assert device.connections == { (dr.CONNECTION_NETWORK_MAC, MAC), @@ -227,7 +234,6 @@ async def test_state_both(hass: HomeAssistant) -> None: assert device.sw_version == SW_VERSION assert device.model == MODEL - entity_registry = er.async_get(hass) entity = entity_registry.async_get(ENTITY_ID) # We prefer the wired mac if present. assert entity.unique_id == MAC diff --git a/tests/components/statistics/test_sensor.py b/tests/components/statistics/test_sensor.py index b9dad806d28..6508ccd608e 100644 --- a/tests/components/statistics/test_sensor.py +++ b/tests/components/statistics/test_sensor.py @@ -42,7 +42,9 @@ VALUES_BINARY = ["on", "off", "on", "off", "on", "off", "on", "off", "on"] VALUES_NUMERIC = [17, 20, 15.2, 5, 3.8, 9.2, 6.7, 14, 6] -async def test_unique_id(hass: HomeAssistant) -> None: +async def test_unique_id( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test configuration defined unique_id.""" assert await async_setup_component( hass, @@ -62,8 +64,7 @@ async def test_unique_id(hass: HomeAssistant) -> None: ) await hass.async_block_till_done() - entity_reg = er.async_get(hass) - entity_id = entity_reg.async_get_entity_id( + entity_id = entity_registry.async_get_entity_id( "sensor", STATISTICS_DOMAIN, "uniqueid_sensor_test" ) assert entity_id == "sensor.test" diff --git a/tests/components/steam_online/test_config_flow.py b/tests/components/steam_online/test_config_flow.py index 9292f58d231..a5bce80d890 100644 --- a/tests/components/steam_online/test_config_flow.py +++ b/tests/components/steam_online/test_config_flow.py @@ -166,7 +166,9 @@ async def test_options_flow(hass: HomeAssistant) -> None: assert result["data"] == CONF_OPTIONS_2 -async def test_options_flow_deselect(hass: HomeAssistant) -> None: +async def test_options_flow_deselect( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test deselecting user.""" entry = create_entry(hass) with ( @@ -198,7 +200,7 @@ async def test_options_flow_deselect(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.CREATE_ENTRY assert result["data"] == {CONF_ACCOUNTS: {}} - assert len(er.async_get(hass).entities) == 0 + assert len(entity_registry.entities) == 0 async def test_options_flow_timeout(hass: HomeAssistant) -> None: diff --git a/tests/components/steam_online/test_init.py b/tests/components/steam_online/test_init.py index ccc7690aae3..73daac0296c 100644 --- a/tests/components/steam_online/test_init.py +++ b/tests/components/steam_online/test_init.py @@ -37,12 +37,13 @@ async def test_async_setup_entry_auth_failed(hass: HomeAssistant) -> None: assert not hass.data.get(DOMAIN) -async def test_device_info(hass: HomeAssistant) -> None: +async def test_device_info( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test device info.""" entry = create_entry(hass) with patch_interface(): await hass.config_entries.async_setup(entry.entry_id) - device_registry = dr.async_get(hass) await hass.async_block_till_done() device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)}) diff --git a/tests/components/steamist/test_init.py b/tests/components/steamist/test_init.py index 96ea59afda2..0ef8edca9a8 100644 --- a/tests/components/steamist/test_init.py +++ b/tests/components/steamist/test_init.py @@ -70,6 +70,7 @@ async def test_config_entry_retry_later(hass: HomeAssistant) -> None: async def test_config_entry_fills_unique_id_with_directed_discovery( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, ) -> None: """Test that the unique id is added if its missing via directed (not broadcast) discovery.""" config_entry = MockConfigEntry( @@ -107,7 +108,6 @@ async def test_config_entry_fills_unique_id_with_directed_discovery( assert config_entry.data[CONF_NAME] == DEVICE_NAME assert config_entry.title == DEVICE_NAME - device_registry = dr.async_get(hass) device_entry = device_registry.async_get_device( connections={(dr.CONNECTION_NETWORK_MAC, FORMATTED_MAC_ADDRESS)} ) diff --git a/tests/components/subaru/test_device_tracker.py b/tests/components/subaru/test_device_tracker.py index b8a970007ab..d4cb8e642f4 100644 --- a/tests/components/subaru/test_device_tracker.py +++ b/tests/components/subaru/test_device_tracker.py @@ -15,9 +15,10 @@ from .conftest import MOCK_API_FETCH, MOCK_API_GET_DATA, advance_time_to_next_fe DEVICE_ID = "device_tracker.test_vehicle_2" -async def test_device_tracker(hass: HomeAssistant, ev_entry) -> None: +async def test_device_tracker( + hass: HomeAssistant, entity_registry: er.EntityRegistry, ev_entry +) -> None: """Test subaru device tracker entity exists and has correct info.""" - entity_registry = er.async_get(hass) entry = entity_registry.async_get(DEVICE_ID) assert entry actual = hass.states.get(DEVICE_ID) diff --git a/tests/components/subaru/test_diagnostics.py b/tests/components/subaru/test_diagnostics.py index 95287b94a7a..651689330b1 100644 --- a/tests/components/subaru/test_diagnostics.py +++ b/tests/components/subaru/test_diagnostics.py @@ -45,6 +45,7 @@ async def test_config_entry_diagnostics( async def test_device_diagnostics( hass: HomeAssistant, hass_client: ClientSessionGenerator, + device_registry: dr.DeviceRegistry, snapshot: SnapshotAssertion, ev_entry, ) -> None: @@ -52,7 +53,6 @@ async def test_device_diagnostics( config_entry = hass.config_entries.async_entries(DOMAIN)[0] - device_registry = dr.async_get(hass) reg_device = device_registry.async_get_device( identifiers={(DOMAIN, TEST_VIN_2_EV)}, ) @@ -70,13 +70,15 @@ async def test_device_diagnostics( async def test_device_diagnostics_vehicle_not_found( - hass: HomeAssistant, hass_client: ClientSessionGenerator, ev_entry + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + device_registry: dr.DeviceRegistry, + ev_entry, ) -> None: """Test device diagnostics when the vehicle cannot be found.""" config_entry = hass.config_entries.async_entries(DOMAIN)[0] - device_registry = dr.async_get(hass) reg_device = device_registry.async_get_device( identifiers={(DOMAIN, TEST_VIN_2_EV)}, ) diff --git a/tests/components/subaru/test_lock.py b/tests/components/subaru/test_lock.py index 4d19d49579e..34bbd7da9e2 100644 --- a/tests/components/subaru/test_lock.py +++ b/tests/components/subaru/test_lock.py @@ -24,9 +24,10 @@ MOCK_API_UNLOCK = f"{MOCK_API}unlock" DEVICE_ID = "lock.test_vehicle_2_door_locks" -async def test_device_exists(hass: HomeAssistant, ev_entry) -> None: +async def test_device_exists( + hass: HomeAssistant, entity_registry: er.EntityRegistry, ev_entry +) -> None: """Test subaru lock entity exists.""" - entity_registry = er.async_get(hass) entry = entity_registry.async_get(DEVICE_ID) assert entry diff --git a/tests/components/subaru/test_sensor.py b/tests/components/subaru/test_sensor.py index 418c03dcecd..a468a2442e1 100644 --- a/tests/components/subaru/test_sensor.py +++ b/tests/components/subaru/test_sensor.py @@ -57,10 +57,14 @@ async def test_sensors_missing_vin_data(hass: HomeAssistant, ev_entry) -> None: ], ) async def test_sensor_migrate_unique_ids( - hass: HomeAssistant, entitydata, old_unique_id, new_unique_id, subaru_config_entry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + entitydata, + old_unique_id, + new_unique_id, + subaru_config_entry, ) -> None: """Test successful migration of entity unique_ids.""" - entity_registry = er.async_get(hass) entity: er.RegistryEntry = entity_registry.async_get_or_create( **entitydata, config_entry=subaru_config_entry, @@ -89,10 +93,14 @@ async def test_sensor_migrate_unique_ids( ], ) async def test_sensor_migrate_unique_ids_duplicate( - hass: HomeAssistant, entitydata, old_unique_id, new_unique_id, subaru_config_entry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + entitydata, + old_unique_id, + new_unique_id, + subaru_config_entry, ) -> None: """Test unsuccessful migration of entity unique_ids due to duplicate.""" - entity_registry = er.async_get(hass) entity: er.RegistryEntry = entity_registry.async_get_or_create( **entitydata, config_entry=subaru_config_entry, diff --git a/tests/components/sun/test_sensor.py b/tests/components/sun/test_sensor.py index 13de0dffbdd..5cc91f79076 100644 --- a/tests/components/sun/test_sensor.py +++ b/tests/components/sun/test_sensor.py @@ -17,6 +17,7 @@ import homeassistant.util.dt as dt_util async def test_setting_rising( hass: HomeAssistant, + entity_registry: er.EntityRegistry, freezer: FrozenDateTimeFactory, entity_registry_enabled_by_default: None, ) -> None: @@ -112,8 +113,7 @@ async def test_setting_rising( entry_ids = hass.config_entries.async_entries("sun") - entity_reg = er.async_get(hass) - entity = entity_reg.async_get("sensor.sun_next_dawn") + entity = entity_registry.async_get("sensor.sun_next_dawn") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC @@ -140,42 +140,42 @@ async def test_setting_rising( solar_azimuth_state.state != hass.states.get("sensor.sun_solar_azimuth").state ) - entity = entity_reg.async_get("sensor.sun_next_dusk") + entity = entity_registry.async_get("sensor.sun_next_dusk") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-next_dusk" - entity = entity_reg.async_get("sensor.sun_next_midnight") + entity = entity_registry.async_get("sensor.sun_next_midnight") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-next_midnight" - entity = entity_reg.async_get("sensor.sun_next_noon") + entity = entity_registry.async_get("sensor.sun_next_noon") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-next_noon" - entity = entity_reg.async_get("sensor.sun_next_rising") + entity = entity_registry.async_get("sensor.sun_next_rising") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-next_rising" - entity = entity_reg.async_get("sensor.sun_next_setting") + entity = entity_registry.async_get("sensor.sun_next_setting") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-next_setting" - entity = entity_reg.async_get("sensor.sun_solar_elevation") + entity = entity_registry.async_get("sensor.sun_solar_elevation") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-solar_elevation" - entity = entity_reg.async_get("sensor.sun_solar_azimuth") + entity = entity_registry.async_get("sensor.sun_solar_azimuth") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-solar_azimuth" - entity = entity_reg.async_get("sensor.sun_solar_rising") + entity = entity_registry.async_get("sensor.sun_solar_rising") assert entity assert entity.entity_category is EntityCategory.DIAGNOSTIC assert entity.unique_id == f"{entry_ids[0].entry_id}-solar_rising" diff --git a/tests/components/surepetcare/test_binary_sensor.py b/tests/components/surepetcare/test_binary_sensor.py index 106cf2f9155..0f5a9486073 100644 --- a/tests/components/surepetcare/test_binary_sensor.py +++ b/tests/components/surepetcare/test_binary_sensor.py @@ -17,10 +17,12 @@ EXPECTED_ENTITY_IDS = { async def test_binary_sensors( - hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + surepetcare, + mock_config_entry_setup: MockConfigEntry, ) -> None: """Test the generation of unique ids.""" - entity_registry = er.async_get(hass) state_entity_ids = hass.states.async_entity_ids() for entity_id, unique_id in EXPECTED_ENTITY_IDS.items(): diff --git a/tests/components/surepetcare/test_lock.py b/tests/components/surepetcare/test_lock.py index d4275e8385c..a47c4a336dc 100644 --- a/tests/components/surepetcare/test_lock.py +++ b/tests/components/surepetcare/test_lock.py @@ -21,10 +21,12 @@ EXPECTED_ENTITY_IDS = { async def test_locks( - hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + surepetcare, + mock_config_entry_setup: MockConfigEntry, ) -> None: """Test the generation of unique ids.""" - entity_registry = er.async_get(hass) state_entity_ids = hass.states.async_entity_ids() for entity_id, unique_id in EXPECTED_ENTITY_IDS.items(): diff --git a/tests/components/surepetcare/test_sensor.py b/tests/components/surepetcare/test_sensor.py index f543cdb9d35..ecf8a5cfc4f 100644 --- a/tests/components/surepetcare/test_sensor.py +++ b/tests/components/surepetcare/test_sensor.py @@ -16,10 +16,12 @@ EXPECTED_ENTITY_IDS = { async def test_sensors( - hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + surepetcare, + mock_config_entry_setup: MockConfigEntry, ) -> None: """Test the generation of unique ids.""" - entity_registry = er.async_get(hass) state_entity_ids = hass.states.async_entity_ids() for entity_id, unique_id in EXPECTED_ENTITY_IDS.items(): diff --git a/tests/components/switch_as_x/test_config_flow.py b/tests/components/switch_as_x/test_config_flow.py index 206ae232d56..2da4c52c7f9 100644 --- a/tests/components/switch_as_x/test_config_flow.py +++ b/tests/components/switch_as_x/test_config_flow.py @@ -75,18 +75,18 @@ async def test_config_flow( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_config_flow_registered_entity( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, mock_setup_entry: AsyncMock, hidden_by_before: er.RegistryEntryHider | None, hidden_by_after: er.RegistryEntryHider, ) -> None: """Test the config flow hides a registered entity.""" - registry = er.async_get(hass) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", suggested_object_id="ceiling" ) assert switch_entity_entry.entity_id == "switch.ceiling" - registry.async_update_entity("switch.ceiling", hidden_by=hidden_by_before) + entity_registry.async_update_entity("switch.ceiling", hidden_by=hidden_by_before) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -122,7 +122,7 @@ async def test_config_flow_registered_entity( CONF_TARGET_DOMAIN: target_domain, } - switch_entity_entry = registry.async_get("switch.ceiling") + switch_entity_entry = entity_registry.async_get("switch.ceiling") assert switch_entity_entry.hidden_by == hidden_by_after diff --git a/tests/components/switch_as_x/test_init.py b/tests/components/switch_as_x/test_init.py index 266d0fd0409..b1ebbbb9322 100644 --- a/tests/components/switch_as_x/test_init.py +++ b/tests/components/switch_as_x/test_init.py @@ -80,11 +80,14 @@ async def test_config_entry_unregistered_uuid( ], ) async def test_entity_registry_events( - hass: HomeAssistant, target_domain: str, state_on: str, state_off: str + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + target_domain: str, + state_on: str, + state_off: str, ) -> None: """Test entity registry events are tracked.""" - registry = er.async_get(hass) - registry_entry = registry.async_get_or_create( + registry_entry = entity_registry.async_get_or_create( "switch", "test", "unique", original_name="ABC" ) switch_entity_id = registry_entry.entity_id @@ -112,7 +115,9 @@ async def test_entity_registry_events( # Change entity_id new_switch_entity_id = f"{switch_entity_id}_new" - registry.async_update_entity(switch_entity_id, new_entity_id=new_switch_entity_id) + entity_registry.async_update_entity( + switch_entity_id, new_entity_id=new_switch_entity_id + ) hass.states.async_set(new_switch_entity_id, STATE_OFF) await hass.async_block_till_done() @@ -129,27 +134,27 @@ async def test_entity_registry_events( with patch( "homeassistant.components.switch_as_x.async_unload_entry", ) as mock_setup_entry: - registry.async_update_entity(new_switch_entity_id, name="New name") + entity_registry.async_update_entity(new_switch_entity_id, name="New name") await hass.async_block_till_done() mock_setup_entry.assert_not_called() # Check removing the entity removes the config entry - registry.async_remove(new_switch_entity_id) + entity_registry.async_remove(new_switch_entity_id) await hass.async_block_till_done() assert hass.states.get(f"{target_domain}.abc") is None - assert registry.async_get(f"{target_domain}.abc") is None + assert entity_registry.async_get(f"{target_domain}.abc") is None assert len(hass.config_entries.async_entries("switch_as_x")) == 0 @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_device_registry_config_entry_1( - hass: HomeAssistant, target_domain: str + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + target_domain: str, ) -> None: """Test we add our config entry to the tracked switch's device.""" - device_registry = dr.async_get(hass) - entity_registry = er.async_get(hass) - switch_config_entry = MockConfigEntry() switch_config_entry.add_to_hass(hass) @@ -206,12 +211,12 @@ async def test_device_registry_config_entry_1( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_device_registry_config_entry_2( - hass: HomeAssistant, target_domain: str + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + target_domain: str, ) -> None: """Test we add our config entry to the tracked switch's device.""" - device_registry = dr.async_get(hass) - entity_registry = er.async_get(hass) - switch_config_entry = MockConfigEntry() switch_config_entry.add_to_hass(hass) @@ -262,7 +267,7 @@ async def test_device_registry_config_entry_2( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_config_entry_entity_id( - hass: HomeAssistant, target_domain: Platform + hass: HomeAssistant, entity_registry: er.EntityRegistry, target_domain: Platform ) -> None: """Test light switch setup from config entry with entity id.""" config_entry = MockConfigEntry( @@ -292,17 +297,17 @@ async def test_config_entry_entity_id( assert state.name == "ABC" # Check the light is added to the entity registry - registry = er.async_get(hass) - entity_entry = registry.async_get(f"{target_domain}.abc") + entity_entry = entity_registry.async_get(f"{target_domain}.abc") assert entity_entry assert entity_entry.unique_id == config_entry.entry_id @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) -async def test_config_entry_uuid(hass: HomeAssistant, target_domain: Platform) -> None: +async def test_config_entry_uuid( + hass: HomeAssistant, entity_registry: er.EntityRegistry, target_domain: Platform +) -> None: """Test light switch setup from config entry with entity registry id.""" - registry = er.async_get(hass) - registry_entry = registry.async_get_or_create( + registry_entry = entity_registry.async_get_or_create( "switch", "test", "unique", original_name="ABC" ) @@ -328,11 +333,13 @@ async def test_config_entry_uuid(hass: HomeAssistant, target_domain: Platform) - @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) -async def test_device(hass: HomeAssistant, target_domain: Platform) -> None: +async def test_device( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + target_domain: Platform, +) -> None: """Test the entity is added to the wrapped entity's device.""" - device_registry = dr.async_get(hass) - entity_registry = er.async_get(hass) - test_config_entry = MockConfigEntry() test_config_entry.add_to_hass(hass) @@ -370,11 +377,10 @@ async def test_device(hass: HomeAssistant, target_domain: Platform) -> None: @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_setup_and_remove_config_entry( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test removing a config entry.""" - registry = er.async_get(hass) - # Setup the config entry switch_as_x_config_entry = MockConfigEntry( data={}, @@ -394,7 +400,7 @@ async def test_setup_and_remove_config_entry( # Check the state and entity registry entry are present assert hass.states.get(f"{target_domain}.abc") is not None - assert registry.async_get(f"{target_domain}.abc") is not None + assert entity_registry.async_get(f"{target_domain}.abc") is not None # Remove the config entry assert await hass.config_entries.async_remove(switch_as_x_config_entry.entry_id) @@ -402,7 +408,7 @@ async def test_setup_and_remove_config_entry( # Check the state and entity registry entry are removed assert hass.states.get(f"{target_domain}.abc") is None - assert registry.async_get(f"{target_domain}.abc") is None + assert entity_registry.async_get(f"{target_domain}.abc") is None @pytest.mark.parametrize( @@ -415,15 +421,16 @@ async def test_setup_and_remove_config_entry( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_reset_hidden_by( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, hidden_by_before: er.RegistryEntryHider | None, hidden_by_after: er.RegistryEntryHider, ) -> None: """Test removing a config entry resets hidden by.""" - registry = er.async_get(hass) - - switch_entity_entry = registry.async_get_or_create("switch", "test", "unique") - registry.async_update_entity( + switch_entity_entry = entity_registry.async_get_or_create( + "switch", "test", "unique" + ) + entity_registry.async_update_entity( switch_entity_entry.entity_id, hidden_by=hidden_by_before ) @@ -447,22 +454,21 @@ async def test_reset_hidden_by( await hass.async_block_till_done() # Check hidden by is reset - switch_entity_entry = registry.async_get(switch_entity_entry.entity_id) + switch_entity_entry = entity_registry.async_get(switch_entity_entry.entity_id) assert switch_entity_entry.hidden_by == hidden_by_after @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_entity_category_inheritance( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test the entity category is inherited from source device.""" - registry = er.async_get(hass) - - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", original_name="ABC" ) - registry.async_update_entity( + entity_registry.async_update_entity( switch_entity_entry.entity_id, entity_category=EntityCategory.CONFIG ) @@ -484,7 +490,7 @@ async def test_entity_category_inheritance( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get(f"{target_domain}.abc") + entity_entry = entity_registry.async_get(f"{target_domain}.abc") assert entity_entry assert entity_entry.device_id == switch_entity_entry.device_id assert entity_entry.entity_category is EntityCategory.CONFIG @@ -493,15 +499,14 @@ async def test_entity_category_inheritance( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_entity_options( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test the source entity is stored as an entity option.""" - registry = er.async_get(hass) - - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", original_name="ABC" ) - registry.async_update_entity( + entity_registry.async_update_entity( switch_entity_entry.entity_id, entity_category=EntityCategory.CONFIG ) @@ -523,7 +528,7 @@ async def test_entity_options( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get(f"{target_domain}.abc") + entity_entry = entity_registry.async_get(f"{target_domain}.abc") assert entity_entry assert entity_entry.device_id == switch_entity_entry.device_id assert entity_entry.options == { @@ -534,12 +539,11 @@ async def test_entity_options( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_entity_name( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test the source entity has entity_name set to True.""" - registry = er.async_get(hass) - device_registry = dr.async_get(hass) - switch_config_entry = MockConfigEntry() switch_config_entry.add_to_hass(hass) @@ -549,14 +553,14 @@ async def test_entity_name( name="Device name", ) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", device_id=device_entry.id, has_entity_name=True, ) - switch_entity_entry = registry.async_update_entity( + switch_entity_entry = entity_registry.async_update_entity( switch_entity_entry.entity_id, config_entry_id=switch_config_entry.entry_id, ) @@ -579,7 +583,7 @@ async def test_entity_name( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get(f"{target_domain}.device_name") + entity_entry = entity_registry.async_get(f"{target_domain}.device_name") assert entity_entry assert entity_entry.device_id == switch_entity_entry.device_id assert entity_entry.has_entity_name is True @@ -593,12 +597,11 @@ async def test_entity_name( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_custom_name_1( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test the source entity has a custom name.""" - registry = er.async_get(hass) - device_registry = dr.async_get(hass) - switch_config_entry = MockConfigEntry() switch_config_entry.add_to_hass(hass) @@ -608,7 +611,7 @@ async def test_custom_name_1( name="Device name", ) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", @@ -616,7 +619,7 @@ async def test_custom_name_1( has_entity_name=True, original_name="Original entity name", ) - switch_entity_entry = registry.async_update_entity( + switch_entity_entry = entity_registry.async_update_entity( switch_entity_entry.entity_id, config_entry_id=switch_config_entry.entry_id, name="Custom entity name", @@ -640,7 +643,7 @@ async def test_custom_name_1( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get( + entity_entry = entity_registry.async_get( f"{target_domain}.device_name_original_entity_name" ) assert entity_entry @@ -656,6 +659,8 @@ async def test_custom_name_1( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_custom_name_2( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test the source entity has a custom name. @@ -663,9 +668,6 @@ async def test_custom_name_2( This tests the custom name is only copied from the source device when the switch_as_x config entry is setup the first time. """ - registry = er.async_get(hass) - device_registry = dr.async_get(hass) - switch_config_entry = MockConfigEntry() switch_config_entry.add_to_hass(hass) @@ -675,7 +677,7 @@ async def test_custom_name_2( name="Device name", ) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", @@ -683,7 +685,7 @@ async def test_custom_name_2( has_entity_name=True, original_name="Original entity name", ) - switch_entity_entry = registry.async_update_entity( + switch_entity_entry = entity_registry.async_update_entity( switch_entity_entry.entity_id, config_entry_id=switch_config_entry.entry_id, name="New custom entity name", @@ -706,13 +708,13 @@ async def test_custom_name_2( # Register the switch as x entity in the entity registry, this means # the entity has been setup before - switch_as_x_entity_entry = registry.async_get_or_create( + switch_as_x_entity_entry = entity_registry.async_get_or_create( target_domain, "switch_as_x", switch_as_x_config_entry.entry_id, suggested_object_id="device_name_original_entity_name", ) - switch_as_x_entity_entry = registry.async_update_entity( + switch_as_x_entity_entry = entity_registry.async_update_entity( switch_as_x_entity_entry.entity_id, config_entry_id=switch_config_entry.entry_id, name="Old custom entity name", @@ -721,7 +723,7 @@ async def test_custom_name_2( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get( + entity_entry = entity_registry.async_get( f"{target_domain}.device_name_original_entity_name" ) assert entity_entry @@ -738,13 +740,13 @@ async def test_custom_name_2( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_import_expose_settings_1( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test importing assistant expose settings.""" await async_setup_component(hass, "homeassistant", {}) - registry = er.async_get(hass) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", @@ -773,7 +775,7 @@ async def test_import_expose_settings_1( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get(f"{target_domain}.abc") + entity_entry = entity_registry.async_get(f"{target_domain}.abc") assert entity_entry # Check switch_as_x expose settings were copied from the switch @@ -794,6 +796,7 @@ async def test_import_expose_settings_1( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_import_expose_settings_2( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test importing assistant expose settings. @@ -803,9 +806,8 @@ async def test_import_expose_settings_2( """ await async_setup_component(hass, "homeassistant", {}) - registry = er.async_get(hass) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", @@ -833,7 +835,7 @@ async def test_import_expose_settings_2( # Register the switch as x entity in the entity registry, this means # the entity has been setup before - switch_as_x_entity_entry = registry.async_get_or_create( + switch_as_x_entity_entry = entity_registry.async_get_or_create( target_domain, "switch_as_x", switch_as_x_config_entry.entry_id, @@ -847,7 +849,7 @@ async def test_import_expose_settings_2( assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id) await hass.async_block_till_done() - entity_entry = registry.async_get(f"{target_domain}.abc") + entity_entry = entity_registry.async_get(f"{target_domain}.abc") assert entity_entry # Check switch_as_x expose settings were not copied from the switch @@ -871,13 +873,13 @@ async def test_import_expose_settings_2( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_restore_expose_settings( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test removing a config entry restores assistant expose settings.""" await async_setup_component(hass, "homeassistant", {}) - registry = er.async_get(hass) - switch_entity_entry = registry.async_get_or_create( + switch_entity_entry = entity_registry.async_get_or_create( "switch", "test", "unique", @@ -900,7 +902,7 @@ async def test_restore_expose_settings( switch_as_x_config_entry.add_to_hass(hass) # Register the switch as x entity - switch_as_x_entity_entry = registry.async_get_or_create( + switch_as_x_entity_entry = entity_registry.async_get_or_create( target_domain, "switch_as_x", switch_as_x_config_entry.entry_id, @@ -927,11 +929,10 @@ async def test_restore_expose_settings( @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_migrate( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test migration.""" - registry = er.async_get(hass) - # Setup the config entry config_entry = MockConfigEntry( data={}, @@ -960,17 +961,16 @@ async def test_migrate( # Check the state and entity registry entry are present assert hass.states.get(f"{target_domain}.abc") is not None - assert registry.async_get(f"{target_domain}.abc") is not None + assert entity_registry.async_get(f"{target_domain}.abc") is not None @pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST) async def test_migrate_from_future( hass: HomeAssistant, + entity_registry: er.EntityRegistry, target_domain: Platform, ) -> None: """Test migration.""" - registry = er.async_get(hass) - # Setup the config entry config_entry = MockConfigEntry( data={}, @@ -998,4 +998,4 @@ async def test_migrate_from_future( # Check the state and entity registry entry are not present assert hass.states.get(f"{target_domain}.abc") is None - assert registry.async_get(f"{target_domain}.abc") is None + assert entity_registry.async_get(f"{target_domain}.abc") is None diff --git a/tests/components/switcher_kis/test_sensor.py b/tests/components/switcher_kis/test_sensor.py index bfe1b2c84dd..1be2efed987 100644 --- a/tests/components/switcher_kis/test_sensor.py +++ b/tests/components/switcher_kis/test_sensor.py @@ -44,7 +44,9 @@ async def test_sensor_platform(hass: HomeAssistant, mock_bridge) -> None: assert state.state == str(getattr(device, field)) -async def test_sensor_disabled(hass: HomeAssistant, mock_bridge) -> None: +async def test_sensor_disabled( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_bridge +) -> None: """Test sensor disabled by default.""" await init_integration(hass) assert mock_bridge @@ -52,11 +54,10 @@ async def test_sensor_disabled(hass: HomeAssistant, mock_bridge) -> None: mock_bridge.mock_callbacks([DUMMY_WATER_HEATER_DEVICE]) await hass.async_block_till_done() - registry = er.async_get(hass) device = DUMMY_WATER_HEATER_DEVICE unique_id = f"{device.device_id}-{device.mac_address}-auto_off_set" entity_id = f"sensor.{slugify(device.name)}_auto_shutdown" - entry = registry.async_get(entity_id) + entry = entity_registry.async_get(entity_id) assert entry assert entry.unique_id == unique_id @@ -64,7 +65,9 @@ async def test_sensor_disabled(hass: HomeAssistant, mock_bridge) -> None: assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION # Test enabling entity - updated_entry = registry.async_update_entity(entry.entity_id, disabled_by=None) + updated_entry = entity_registry.async_update_entity( + entry.entity_id, disabled_by=None + ) assert updated_entry != entry assert updated_entry.disabled is False