From 9ab1cb83d801ee0460e73604ba535829fdce8f13 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Sun, 12 Nov 2023 19:45:30 +0100 Subject: [PATCH] Update a-c* tests to use entity & device registry fixtures (#103793) * Update a-c* tests to use entity & device registry fixtures * Revert some changes * Revert formatting * retrigger CI --- tests/components/asuswrt/test_sensor.py | 16 ++- tests/components/blebox/test_binary_sensor.py | 5 +- tests/components/blebox/test_climate.py | 5 +- tests/components/blebox/test_cover.py | 15 +- tests/components/blebox/test_light.py | 15 +- tests/components/blebox/test_sensor.py | 10 +- tests/components/blebox/test_switch.py | 11 +- .../bmw_connected_drive/test_diagnostics.py | 4 +- .../bmw_connected_drive/test_init.py | 5 +- tests/components/brother/test_sensor.py | 82 ++++++----- tests/components/camera/test_init.py | 16 ++- tests/components/cast/test_media_player.py | 135 ++++++++++++------ tests/components/cloud/test_client.py | 12 +- tests/components/cloud/test_google_config.py | 25 ++-- tests/components/config/test_automation.py | 6 +- tests/components/config/test_scene.py | 6 +- tests/components/config/test_script.py | 10 +- tests/components/counter/test_init.py | 18 +-- tests/components/cpuspeed/test_sensor.py | 4 +- 19 files changed, 239 insertions(+), 161 deletions(-) diff --git a/tests/components/asuswrt/test_sensor.py b/tests/components/asuswrt/test_sensor.py index 92f40dd8511..f0e21124fe3 100644 --- a/tests/components/asuswrt/test_sensor.py +++ b/tests/components/asuswrt/test_sensor.py @@ -30,14 +30,15 @@ SENSORS_ALL_LEGACY = [*SENSORS_DEFAULT, *SENSORS_LOAD_AVG, *SENSORS_TEMPERATURES @pytest.fixture(name="create_device_registry_devices") -def create_device_registry_devices_fixture(hass: HomeAssistant): +def create_device_registry_devices_fixture( + hass: HomeAssistant, device_registry: dr.DeviceRegistry +): """Create device registry devices so the device tracker entities are enabled when added.""" - dev_reg = dr.async_get(hass) config_entry = MockConfigEntry(domain="something_else") config_entry.add_to_hass(hass) for idx, device in enumerate((MOCK_MACS[2], MOCK_MACS[3])): - dev_reg.async_get_or_create( + device_registry.async_get_or_create( name=f"Device {idx}", config_entry_id=config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, dr.format_mac(device))}, @@ -274,7 +275,9 @@ async def test_options_reload(hass: HomeAssistant, connect_legacy) -> None: assert connect_legacy.return_value.connection.async_connect.call_count == 2 -async def test_unique_id_migration(hass: HomeAssistant, connect_legacy) -> None: +async def test_unique_id_migration( + hass: HomeAssistant, entity_registry: er.EntityRegistry, connect_legacy +) -> None: """Test AsusWRT entities unique id format migration.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -283,9 +286,8 @@ async def test_unique_id_migration(hass: HomeAssistant, connect_legacy) -> None: ) config_entry.add_to_hass(hass) - entity_reg = er.async_get(hass) obj_entity_id = slugify(f"{HOST} Upload") - entity_reg.async_get_or_create( + entity_registry.async_get_or_create( sensor.DOMAIN, DOMAIN, f"{DOMAIN} {ROUTER_MAC_ADDR} Upload", @@ -297,6 +299,6 @@ async def test_unique_id_migration(hass: HomeAssistant, connect_legacy) -> None: assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - migr_entity = entity_reg.async_get(f"{sensor.DOMAIN}.{obj_entity_id}") + migr_entity = entity_registry.async_get(f"{sensor.DOMAIN}.{obj_entity_id}") assert migr_entity is not None assert migr_entity.unique_id == slugify(f"{ROUTER_MAC_ADDR}_sensor_tx_bytes") diff --git a/tests/components/blebox/test_binary_sensor.py b/tests/components/blebox/test_binary_sensor.py index 25ab8cab8cb..3c05a425b12 100644 --- a/tests/components/blebox/test_binary_sensor.py +++ b/tests/components/blebox/test_binary_sensor.py @@ -28,7 +28,9 @@ def airsensor_fixture() -> tuple[AsyncMock, str]: return feature, "binary_sensor.windrainsensor_0_rain" -async def test_init(rainsensor: AsyncMock, hass: HomeAssistant) -> None: +async def test_init( + rainsensor: AsyncMock, device_registry: dr.DeviceRegistry, hass: HomeAssistant +) -> None: """Test binary_sensor initialisation.""" _, entity_id = rainsensor entry = await async_setup_entity(hass, entity_id) @@ -40,7 +42,6 @@ async def test_init(rainsensor: AsyncMock, hass: HomeAssistant) -> None: assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.MOISTURE assert state.state == STATE_ON - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My rain sensor" diff --git a/tests/components/blebox/test_climate.py b/tests/components/blebox/test_climate.py index 2e6e5de4573..6ea6d995900 100644 --- a/tests/components/blebox/test_climate.py +++ b/tests/components/blebox/test_climate.py @@ -76,7 +76,9 @@ def thermobox_fixture(): return (feature, "climate.thermobox_thermostat") -async def test_init(saunabox, hass: HomeAssistant) -> None: +async def test_init( + saunabox, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test default state.""" _, entity_id = saunabox @@ -102,7 +104,6 @@ async def test_init(saunabox, hass: HomeAssistant) -> None: assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My sauna" diff --git a/tests/components/blebox/test_cover.py b/tests/components/blebox/test_cover.py index cbf8f5e589b..8691c886faa 100644 --- a/tests/components/blebox/test_cover.py +++ b/tests/components/blebox/test_cover.py @@ -98,7 +98,9 @@ def gate_fixture(): return (feature, "cover.gatecontroller_position") -async def test_init_gatecontroller(gatecontroller, hass: HomeAssistant) -> None: +async def test_init_gatecontroller( + gatecontroller, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test gateController default state.""" _, entity_id = gatecontroller @@ -118,7 +120,6 @@ async def test_init_gatecontroller(gatecontroller, hass: HomeAssistant) -> None: assert ATTR_CURRENT_POSITION not in state.attributes assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My gate controller" @@ -128,7 +129,9 @@ async def test_init_gatecontroller(gatecontroller, hass: HomeAssistant) -> None: assert device.sw_version == "1.23" -async def test_init_shutterbox(shutterbox, hass: HomeAssistant) -> None: +async def test_init_shutterbox( + shutterbox, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test gateBox default state.""" _, entity_id = shutterbox @@ -148,7 +151,6 @@ async def test_init_shutterbox(shutterbox, hass: HomeAssistant) -> None: assert ATTR_CURRENT_POSITION not in state.attributes assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My shutter" @@ -158,7 +160,9 @@ async def test_init_shutterbox(shutterbox, hass: HomeAssistant) -> None: assert device.sw_version == "1.23" -async def test_init_gatebox(gatebox, hass: HomeAssistant) -> None: +async def test_init_gatebox( + gatebox, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test cover default state.""" _, entity_id = gatebox @@ -180,7 +184,6 @@ async def test_init_gatebox(gatebox, hass: HomeAssistant) -> None: assert ATTR_CURRENT_POSITION not in state.attributes assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My gatebox" diff --git a/tests/components/blebox/test_light.py b/tests/components/blebox/test_light.py index e2184df9820..47f38ba815b 100644 --- a/tests/components/blebox/test_light.py +++ b/tests/components/blebox/test_light.py @@ -50,7 +50,9 @@ def dimmer_fixture(): return (feature, "light.dimmerbox_brightness") -async def test_dimmer_init(dimmer, hass: HomeAssistant) -> None: +async def test_dimmer_init( + dimmer, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test cover default state.""" _, entity_id = dimmer @@ -66,7 +68,6 @@ async def test_dimmer_init(dimmer, hass: HomeAssistant) -> None: assert state.attributes[ATTR_BRIGHTNESS] == 65 assert state.state == STATE_ON - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My dimmer" @@ -223,7 +224,9 @@ def wlightboxs_fixture(): return (feature, "light.wlightboxs_color") -async def test_wlightbox_s_init(wlightbox_s, hass: HomeAssistant) -> None: +async def test_wlightbox_s_init( + wlightbox_s, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test cover default state.""" _, entity_id = wlightbox_s @@ -239,7 +242,6 @@ async def test_wlightbox_s_init(wlightbox_s, hass: HomeAssistant) -> None: assert state.attributes[ATTR_BRIGHTNESS] is None assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My wLightBoxS" @@ -326,7 +328,9 @@ def wlightbox_fixture(): return (feature, "light.wlightbox_color") -async def test_wlightbox_init(wlightbox, hass: HomeAssistant) -> None: +async def test_wlightbox_init( + wlightbox, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test cover default state.""" _, entity_id = wlightbox @@ -343,7 +347,6 @@ async def test_wlightbox_init(wlightbox, hass: HomeAssistant) -> None: assert state.attributes[ATTR_RGBW_COLOR] is None assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My wLightBox" diff --git a/tests/components/blebox/test_sensor.py b/tests/components/blebox/test_sensor.py index 1cfe36e70b6..68990a09a32 100644 --- a/tests/components/blebox/test_sensor.py +++ b/tests/components/blebox/test_sensor.py @@ -56,7 +56,9 @@ def tempsensor_fixture(): return (feature, "sensor.tempsensor_0_temperature") -async def test_init(tempsensor, hass: HomeAssistant) -> None: +async def test_init( + tempsensor, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test sensor default state.""" _, entity_id = tempsensor @@ -70,7 +72,6 @@ async def test_init(tempsensor, hass: HomeAssistant) -> None: assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My temperature sensor" @@ -110,7 +111,9 @@ async def test_update_failure( assert f"Updating '{feature_mock.full_name}' failed: " in caplog.text -async def test_airsensor_init(airsensor, hass: HomeAssistant) -> None: +async def test_airsensor_init( + airsensor, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test airSensor default state.""" _, entity_id = airsensor @@ -123,7 +126,6 @@ async def test_airsensor_init(airsensor, hass: HomeAssistant) -> None: assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.PM1 assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My air sensor" diff --git a/tests/components/blebox/test_switch.py b/tests/components/blebox/test_switch.py index 5a425e799c3..db98a2705b2 100644 --- a/tests/components/blebox/test_switch.py +++ b/tests/components/blebox/test_switch.py @@ -44,7 +44,9 @@ def switchbox_fixture(): return (feature, "switch.switchbox_0_relay") -async def test_switchbox_init(switchbox, hass: HomeAssistant, config) -> None: +async def test_switchbox_init( + switchbox, hass: HomeAssistant, device_registry: dr.DeviceRegistry, config +) -> None: """Test switch default state.""" feature_mock, entity_id = switchbox @@ -60,7 +62,6 @@ async def test_switchbox_init(switchbox, hass: HomeAssistant, config) -> None: assert state.state == STATE_OFF - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My switch box" @@ -189,7 +190,9 @@ def switchbox_d_fixture(): return (features, ["switch.switchboxd_0_relay", "switch.switchboxd_1_relay"]) -async def test_switchbox_d_init(switchbox_d, hass: HomeAssistant) -> None: +async def test_switchbox_d_init( + switchbox_d, hass: HomeAssistant, device_registry: dr.DeviceRegistry +) -> None: """Test switch default state.""" feature_mocks, entity_ids = switchbox_d @@ -206,7 +209,6 @@ async def test_switchbox_d_init(switchbox_d, hass: HomeAssistant) -> None: assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My relays" @@ -223,7 +225,6 @@ async def test_switchbox_d_init(switchbox_d, hass: HomeAssistant) -> None: assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH assert state.state == STATE_UNKNOWN - device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.name == "My relays" diff --git a/tests/components/bmw_connected_drive/test_diagnostics.py b/tests/components/bmw_connected_drive/test_diagnostics.py index 0509409ad0a..11c2b055f6d 100644 --- a/tests/components/bmw_connected_drive/test_diagnostics.py +++ b/tests/components/bmw_connected_drive/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, bmw_fixture, snapshot: SnapshotAssertion, ) -> None: @@ -56,7 +57,6 @@ async def test_device_diagnostics( mock_config_entry = await setup_mocked_integration(hass) - device_registry = dr.async_get(hass) reg_device = device_registry.async_get_device( identifiers={(DOMAIN, "WBY00000000REXI01")}, ) @@ -73,6 +73,7 @@ async def test_device_diagnostics( async def test_device_diagnostics_vehicle_not_found( hass: HomeAssistant, hass_client: ClientSessionGenerator, + device_registry: dr.DeviceRegistry, bmw_fixture, snapshot: SnapshotAssertion, ) -> None: @@ -84,7 +85,6 @@ async def test_device_diagnostics_vehicle_not_found( mock_config_entry = await setup_mocked_integration(hass) - device_registry = dr.async_get(hass) reg_device = device_registry.async_get_device( identifiers={(DOMAIN, "WBY00000000REXI01")}, ) diff --git a/tests/components/bmw_connected_drive/test_init.py b/tests/components/bmw_connected_drive/test_init.py index aab41bf6339..bc02437f5ba 100644 --- a/tests/components/bmw_connected_drive/test_init.py +++ b/tests/components/bmw_connected_drive/test_init.py @@ -49,12 +49,12 @@ async def test_migrate_unique_ids( entitydata: dict, old_unique_id: str, new_unique_id: str, + entity_registry: er.EntityRegistry, ) -> None: """Test successful migration of entity unique_ids.""" mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY) mock_config_entry.add_to_hass(hass) - entity_registry = er.async_get(hass) entity: er.RegistryEntry = entity_registry.async_get_or_create( **entitydata, config_entry=mock_config_entry, @@ -95,13 +95,12 @@ async def test_dont_migrate_unique_ids( entitydata: dict, old_unique_id: str, new_unique_id: str, + entity_registry: er.EntityRegistry, ) -> None: """Test successful migration of entity unique_ids.""" mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY) mock_config_entry.add_to_hass(hass) - entity_registry = er.async_get(hass) - # create existing entry with new_unique_id existing_entity = entity_registry.async_get_or_create( SENSOR_DOMAIN, diff --git a/tests/components/brother/test_sensor.py b/tests/components/brother/test_sensor.py index 42bcb9847f1..4bb5732e616 100644 --- a/tests/components/brother/test_sensor.py +++ b/tests/components/brother/test_sensor.py @@ -32,14 +32,12 @@ ATTR_REMAINING_PAGES = "remaining_pages" ATTR_COUNTER = "counter" -async def test_sensors(hass: HomeAssistant) -> None: +async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None: """Test states of the sensors.""" entry = await init_integration(hass, skip_setup=True) - registry = er.async_get(hass) - # Pre-create registry entries for disabled by default sensors - registry.async_get_or_create( + entity_registry.async_get_or_create( SENSOR_DOMAIN, DOMAIN, "0123456789_uptime", @@ -62,7 +60,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "waiting" assert state.attributes.get(ATTR_STATE_CLASS) is None - entry = registry.async_get("sensor.hl_l2340dw_status") + entry = entity_registry.async_get("sensor.hl_l2340dw_status") assert entry assert entry.unique_id == "0123456789_status" @@ -73,7 +71,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "75" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_black_toner_remaining") + entry = entity_registry.async_get("sensor.hl_l2340dw_black_toner_remaining") assert entry assert entry.unique_id == "0123456789_black_toner_remaining" @@ -84,7 +82,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "10" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_cyan_toner_remaining") + entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_toner_remaining") assert entry assert entry.unique_id == "0123456789_cyan_toner_remaining" @@ -95,7 +93,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "8" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_magenta_toner_remaining") + entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_toner_remaining") assert entry assert entry.unique_id == "0123456789_magenta_toner_remaining" @@ -106,7 +104,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "2" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_yellow_toner_remaining") + entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_toner_remaining") assert entry assert entry.unique_id == "0123456789_yellow_toner_remaining" @@ -117,7 +115,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "92" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_drum_remaining_lifetime") + entry = entity_registry.async_get("sensor.hl_l2340dw_drum_remaining_lifetime") assert entry assert entry.unique_id == "0123456789_drum_remaining_life" @@ -128,7 +126,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "11014" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_drum_remaining_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_drum_remaining_pages") assert entry assert entry.unique_id == "0123456789_drum_remaining_pages" @@ -139,7 +137,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "986" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_drum_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_drum_page_counter") assert entry assert entry.unique_id == "0123456789_drum_counter" @@ -150,7 +148,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "92" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_black_drum_remaining_lifetime") + entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_remaining_lifetime") assert entry assert entry.unique_id == "0123456789_black_drum_remaining_life" @@ -161,7 +159,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "16389" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_black_drum_remaining_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_remaining_pages") assert entry assert entry.unique_id == "0123456789_black_drum_remaining_pages" @@ -172,7 +170,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "1611" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_black_drum_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_page_counter") assert entry assert entry.unique_id == "0123456789_black_drum_counter" @@ -183,7 +181,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "92" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_lifetime") + entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_lifetime") assert entry assert entry.unique_id == "0123456789_cyan_drum_remaining_life" @@ -194,7 +192,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "16389" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_pages") assert entry assert entry.unique_id == "0123456789_cyan_drum_remaining_pages" @@ -205,7 +203,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "1611" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_cyan_drum_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_page_counter") assert entry assert entry.unique_id == "0123456789_cyan_drum_counter" @@ -216,7 +214,9 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "92" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_lifetime") + entry = entity_registry.async_get( + "sensor.hl_l2340dw_magenta_drum_remaining_lifetime" + ) assert entry assert entry.unique_id == "0123456789_magenta_drum_remaining_life" @@ -227,7 +227,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "16389" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_pages") assert entry assert entry.unique_id == "0123456789_magenta_drum_remaining_pages" @@ -238,7 +238,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "1611" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_magenta_drum_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_drum_page_counter") assert entry assert entry.unique_id == "0123456789_magenta_drum_counter" @@ -249,7 +249,9 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "92" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_lifetime") + entry = entity_registry.async_get( + "sensor.hl_l2340dw_yellow_drum_remaining_lifetime" + ) assert entry assert entry.unique_id == "0123456789_yellow_drum_remaining_life" @@ -260,7 +262,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "16389" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_pages") assert entry assert entry.unique_id == "0123456789_yellow_drum_remaining_pages" @@ -271,7 +273,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "1611" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_yellow_drum_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_drum_page_counter") assert entry assert entry.unique_id == "0123456789_yellow_drum_counter" @@ -282,7 +284,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "97" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_fuser_remaining_lifetime") + entry = entity_registry.async_get("sensor.hl_l2340dw_fuser_remaining_lifetime") assert entry assert entry.unique_id == "0123456789_fuser_remaining_life" @@ -293,7 +295,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "97" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_belt_unit_remaining_lifetime") + entry = entity_registry.async_get("sensor.hl_l2340dw_belt_unit_remaining_lifetime") assert entry assert entry.unique_id == "0123456789_belt_unit_remaining_life" @@ -304,7 +306,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "98" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_pf_kit_1_remaining_lifetime") + entry = entity_registry.async_get("sensor.hl_l2340dw_pf_kit_1_remaining_lifetime") assert entry assert entry.unique_id == "0123456789_pf_kit_1_remaining_life" @@ -315,7 +317,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "986" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_page_counter") assert entry assert entry.unique_id == "0123456789_page_counter" @@ -326,7 +328,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "538" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_duplex_unit_page_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_duplex_unit_page_counter") assert entry assert entry.unique_id == "0123456789_duplex_unit_pages_counter" @@ -337,7 +339,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "709" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_b_w_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_b_w_pages") assert entry assert entry.unique_id == "0123456789_bw_counter" @@ -348,7 +350,7 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "902" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - entry = registry.async_get("sensor.hl_l2340dw_color_pages") + entry = entity_registry.async_get("sensor.hl_l2340dw_color_pages") assert entry assert entry.unique_id == "0123456789_color_counter" @@ -360,20 +362,21 @@ async def test_sensors(hass: HomeAssistant) -> None: assert state.state == "2019-09-24T12:14:56+00:00" assert state.attributes.get(ATTR_STATE_CLASS) is None - entry = registry.async_get("sensor.hl_l2340dw_last_restart") + entry = entity_registry.async_get("sensor.hl_l2340dw_last_restart") assert entry assert entry.unique_id == "0123456789_uptime" -async def test_disabled_by_default_sensors(hass: HomeAssistant) -> None: +async def test_disabled_by_default_sensors( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test the disabled by default Brother sensors.""" await init_integration(hass) - registry = er.async_get(hass) state = hass.states.get("sensor.hl_l2340dw_last_restart") assert state is None - entry = registry.async_get("sensor.hl_l2340dw_last_restart") + entry = entity_registry.async_get("sensor.hl_l2340dw_last_restart") assert entry assert entry.unique_id == "0123456789_uptime" assert entry.disabled @@ -434,11 +437,12 @@ async def test_manual_update_entity(hass: HomeAssistant) -> None: assert len(mock_update.mock_calls) == 1 -async def test_unique_id_migration(hass: HomeAssistant) -> None: +async def test_unique_id_migration( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test states of the unique_id migration.""" - registry = er.async_get(hass) - registry.async_get_or_create( + entity_registry.async_get_or_create( SENSOR_DOMAIN, DOMAIN, "0123456789_b/w_counter", @@ -448,6 +452,6 @@ async def test_unique_id_migration(hass: HomeAssistant) -> None: await init_integration(hass) - entry = registry.async_get("sensor.hl_l2340dw_b_w_counter") + entry = entity_registry.async_get("sensor.hl_l2340dw_b_w_counter") assert entry assert entry.unique_id == "0123456789_bw_counter" diff --git a/tests/components/camera/test_init.py b/tests/components/camera/test_init.py index 2a91a375a13..8e49e00e498 100644 --- a/tests/components/camera/test_init.py +++ b/tests/components/camera/test_init.py @@ -367,7 +367,10 @@ async def test_websocket_update_preload_prefs( async def test_websocket_update_orientation_prefs( - hass: HomeAssistant, hass_ws_client: WebSocketGenerator, mock_camera + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, + mock_camera, ) -> None: """Test updating camera preferences.""" await async_setup_component(hass, "homeassistant", {}) @@ -387,11 +390,10 @@ async def test_websocket_update_orientation_prefs( assert not response["success"] assert response["error"]["code"] == "update_failed" - registry = er.async_get(hass) - assert not registry.async_get("camera.demo_uniquecamera") + assert not entity_registry.async_get("camera.demo_uniquecamera") # Since we don't have a unique id, we need to create a registry entry - registry.async_get_or_create(DOMAIN, "demo", "uniquecamera") - registry.async_update_entity_options( + entity_registry.async_get_or_create(DOMAIN, "demo", "uniquecamera") + entity_registry.async_update_entity_options( "camera.demo_uniquecamera", DOMAIN, {}, @@ -408,7 +410,9 @@ async def test_websocket_update_orientation_prefs( response = await client.receive_json() assert response["success"] - er_camera_prefs = registry.async_get("camera.demo_uniquecamera").options[DOMAIN] + er_camera_prefs = entity_registry.async_get("camera.demo_uniquecamera").options[ + DOMAIN + ] assert er_camera_prefs[PREF_ORIENTATION] == camera.Orientation.ROTATE_180 assert response["result"][PREF_ORIENTATION] == er_camera_prefs[PREF_ORIENTATION] # Check that the preference was saved diff --git a/tests/components/cast/test_media_player.py b/tests/components/cast/test_media_player.py index 3d9feb3e43c..2af5e67f845 100644 --- a/tests/components/cast/test_media_player.py +++ b/tests/components/cast/test_media_player.py @@ -552,6 +552,7 @@ async def test_auto_cast_chromecasts(hass: HomeAssistant) -> None: async def test_discover_dynamic_group( hass: HomeAssistant, + entity_registry: er.EntityRegistry, get_multizone_status_mock, get_chromecast_mock, caplog: pytest.LogCaptureFixture, @@ -562,8 +563,6 @@ async def test_discover_dynamic_group( zconf_1 = get_fake_zconf(host="host_1", port=23456) zconf_2 = get_fake_zconf(host="host_2", port=34567) - reg = er.async_get(hass) - # Fake dynamic group info tmp1 = MagicMock() tmp1.uuid = FakeUUID @@ -606,7 +605,9 @@ async def test_discover_dynamic_group( get_chromecast_mock.assert_called() get_chromecast_mock.reset_mock() assert add_dev1.call_count == 0 - assert reg.async_get_entity_id("media_player", "cast", cast_1.uuid) is None + assert ( + entity_registry.async_get_entity_id("media_player", "cast", cast_1.uuid) is None + ) # Discover other dynamic group cast service with patch( @@ -632,7 +633,9 @@ async def test_discover_dynamic_group( get_chromecast_mock.assert_called() get_chromecast_mock.reset_mock() assert add_dev1.call_count == 0 - assert reg.async_get_entity_id("media_player", "cast", cast_2.uuid) is None + assert ( + entity_registry.async_get_entity_id("media_player", "cast", cast_2.uuid) is None + ) # Get update for cast service with patch( @@ -655,7 +658,9 @@ async def test_discover_dynamic_group( assert len(tasks) == 0 get_chromecast_mock.assert_not_called() assert add_dev1.call_count == 0 - assert reg.async_get_entity_id("media_player", "cast", cast_1.uuid) is None + assert ( + entity_registry.async_get_entity_id("media_player", "cast", cast_1.uuid) is None + ) # Remove cast service assert "Disconnecting from chromecast" not in caplog.text @@ -765,14 +770,17 @@ async def test_entity_availability(hass: HomeAssistant) -> None: @pytest.mark.parametrize(("port", "entry_type"), ((8009, None), (12345, None))) async def test_device_registry( - hass: HomeAssistant, hass_ws_client: WebSocketGenerator, port, entry_type + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + port, + entry_type, ) -> None: """Test device registry integration.""" assert await async_setup_component(hass, "config", {}) entity_id = "media_player.speaker" - reg = er.async_get(hass) - dev_reg = dr.async_get(hass) info = get_fake_chromecast_info(port=port) @@ -790,9 +798,11 @@ async def test_device_registry( assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) - entity_entry = reg.async_get(entity_id) - device_entry = dev_reg.async_get(entity_entry.device_id) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) + entity_entry = entity_registry.async_get(entity_id) + device_entry = device_registry.async_get(entity_entry.device_id) assert entity_entry.device_id == device_entry.id assert device_entry.entry_type == entry_type @@ -815,14 +825,15 @@ async def test_device_registry( await hass.async_block_till_done() chromecast.disconnect.assert_called_once() - assert reg.async_get(entity_id) is None - assert dev_reg.async_get(entity_entry.device_id) is None + assert entity_registry.async_get(entity_id) is None + assert device_registry.async_get(entity_entry.device_id) is None -async def test_entity_cast_status(hass: HomeAssistant) -> None: +async def test_entity_cast_status( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test handling of cast status.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -839,7 +850,9 @@ async def test_entity_cast_status(hass: HomeAssistant) -> None: assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) # No media status, pause, play, stop not supported assert state.attributes.get("supported_features") == ( @@ -1088,10 +1101,11 @@ async def test_entity_browse_media_audio_only( assert expected_child_2 in response["result"]["children"] -async def test_entity_play_media(hass: HomeAssistant, quick_play_mock) -> None: +async def test_entity_play_media( + hass: HomeAssistant, entity_registry: er.EntityRegistry, quick_play_mock +) -> None: """Test playing media.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1107,7 +1121,9 @@ async def test_entity_play_media(hass: HomeAssistant, quick_play_mock) -> None: assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) # Play_media await hass.services.async_call( @@ -1134,10 +1150,11 @@ async def test_entity_play_media(hass: HomeAssistant, quick_play_mock) -> None: ) -async def test_entity_play_media_cast(hass: HomeAssistant, quick_play_mock) -> None: +async def test_entity_play_media_cast( + hass: HomeAssistant, entity_registry: er.EntityRegistry, quick_play_mock +) -> None: """Test playing media with cast special features.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1153,7 +1170,9 @@ async def test_entity_play_media_cast(hass: HomeAssistant, quick_play_mock) -> N assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) # Play_media - cast with app ID await common.async_play_media(hass, "cast", '{"app_id": "abc123"}', entity_id) @@ -1177,11 +1196,13 @@ async def test_entity_play_media_cast(hass: HomeAssistant, quick_play_mock) -> N async def test_entity_play_media_cast_invalid( - hass: HomeAssistant, caplog: pytest.LogCaptureFixture, quick_play_mock + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + caplog: pytest.LogCaptureFixture, + quick_play_mock, ) -> None: """Test playing media.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1197,7 +1218,9 @@ async def test_entity_play_media_cast_invalid( assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) # play_media - media_type cast with invalid JSON with pytest.raises(json.decoder.JSONDecodeError): @@ -1345,11 +1368,13 @@ async def test_entity_play_media_playlist( ], ) async def test_entity_media_content_type( - hass: HomeAssistant, cast_type, default_content_type + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + cast_type, + default_content_type, ) -> None: """Test various content types.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1366,7 +1391,9 @@ async def test_entity_media_content_type( assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) media_status = MagicMock(images=None) media_status.media_is_movie = False @@ -1398,10 +1425,11 @@ async def test_entity_media_content_type( assert state.attributes.get("media_content_type") == "movie" -async def test_entity_control(hass: HomeAssistant, quick_play_mock) -> None: +async def test_entity_control( + hass: HomeAssistant, entity_registry: er.EntityRegistry, quick_play_mock +) -> None: """Test various device and media controls.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1427,7 +1455,9 @@ async def test_entity_control(hass: HomeAssistant, quick_play_mock) -> None: assert state is not None assert state.name == "Speaker" assert state.state == "playing" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) assert state.attributes.get("supported_features") == ( MediaPlayerEntityFeature.PAUSE @@ -1527,10 +1557,11 @@ async def test_entity_control(hass: HomeAssistant, quick_play_mock) -> None: ("app_id", "state_no_media"), [(pychromecast.APP_YOUTUBE, "idle"), ("Netflix", "playing")], ) -async def test_entity_media_states(hass: HomeAssistant, app_id, state_no_media) -> None: +async def test_entity_media_states( + hass: HomeAssistant, entity_registry: er.EntityRegistry, app_id, state_no_media +) -> None: """Test various entity media states.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1546,7 +1577,9 @@ async def test_entity_media_states(hass: HomeAssistant, app_id, state_no_media) assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) # App id updated, but no media status chromecast.app_id = app_id @@ -1606,10 +1639,11 @@ async def test_entity_media_states(hass: HomeAssistant, app_id, state_no_media) assert state.state == "unknown" -async def test_entity_media_states_lovelace_app(hass: HomeAssistant) -> None: +async def test_entity_media_states_lovelace_app( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: """Test various entity media states when the lovelace app is active.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1625,7 +1659,9 @@ async def test_entity_media_states_lovelace_app(hass: HomeAssistant) -> None: assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) chromecast.app_id = CAST_APP_ID_HOMEASSISTANT_LOVELACE cast_status = MagicMock() @@ -1677,10 +1713,11 @@ async def test_entity_media_states_lovelace_app(hass: HomeAssistant) -> None: assert state.state == "unknown" -async def test_group_media_states(hass: HomeAssistant, mz_mock) -> None: +async def test_group_media_states( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mz_mock +) -> None: """Test media states are read from group if entity has no state.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1698,7 +1735,9 @@ async def test_group_media_states(hass: HomeAssistant, mz_mock) -> None: assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) group_media_status = MagicMock(images=None) player_media_status = MagicMock(images=None) @@ -1734,13 +1773,14 @@ async def test_group_media_states(hass: HomeAssistant, mz_mock) -> None: assert state.state == "playing" -async def test_group_media_states_early(hass: HomeAssistant, mz_mock) -> None: +async def test_group_media_states_early( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mz_mock +) -> None: """Test media states are read from group if entity has no state. This tests case asserts group state is polled when the player is created. """ entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1756,7 +1796,9 @@ async def test_group_media_states_early(hass: HomeAssistant, mz_mock) -> None: assert state is not None assert state.name == "Speaker" assert state.state == "unavailable" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) # Check group state is polled when player is first created connection_status = MagicMock() @@ -1788,11 +1830,10 @@ async def test_group_media_states_early(hass: HomeAssistant, mz_mock) -> None: async def test_group_media_control( - hass: HomeAssistant, mz_mock, quick_play_mock + hass: HomeAssistant, entity_registry: er.EntityRegistry, mz_mock, quick_play_mock ) -> None: """Test media controls are handled by group if entity has no state.""" entity_id = "media_player.speaker" - reg = er.async_get(hass) info = get_fake_chromecast_info() @@ -1811,7 +1852,9 @@ async def test_group_media_control( assert state is not None assert state.name == "Speaker" assert state.state == "off" - assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) + assert entity_id == entity_registry.async_get_entity_id( + "media_player", "cast", str(info.uuid) + ) group_media_status = MagicMock(images=None) player_media_status = MagicMock(images=None) diff --git a/tests/components/cloud/test_client.py b/tests/components/cloud/test_client.py index 63ec6ad569d..ff718262b10 100644 --- a/tests/components/cloud/test_client.py +++ b/tests/components/cloud/test_client.py @@ -248,10 +248,12 @@ async def test_webhook_msg( async def test_google_config_expose_entity( - hass: HomeAssistant, mock_cloud_setup, mock_cloud_login + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_cloud_setup, + mock_cloud_login, ) -> None: """Test Google config exposing entity method uses latest config.""" - entity_registry = er.async_get(hass) # Enable exposing new entities to Google exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES] @@ -274,10 +276,12 @@ async def test_google_config_expose_entity( async def test_google_config_should_2fa( - hass: HomeAssistant, mock_cloud_setup, mock_cloud_login + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_cloud_setup, + mock_cloud_login, ) -> None: """Test Google config disabling 2FA method uses latest config.""" - entity_registry = er.async_get(hass) # Register a light entity entity_entry = entity_registry.async_get_or_create( diff --git a/tests/components/cloud/test_google_config.py b/tests/components/cloud/test_google_config.py index fe60ca971a1..39bf60570f2 100644 --- a/tests/components/cloud/test_google_config.py +++ b/tests/components/cloud/test_google_config.py @@ -120,11 +120,10 @@ async def test_sync_entities(mock_conf, hass: HomeAssistant, cloud_prefs) -> Non async def test_google_update_expose_trigger_sync( - hass: HomeAssistant, cloud_prefs + hass: HomeAssistant, entity_registry: er.EntityRegistry, cloud_prefs ) -> None: """Test Google config responds to updating exposed entities.""" assert await async_setup_component(hass, "homeassistant", {}) - entity_registry = er.async_get(hass) # Enable exposing new entities to Google expose_new(hass, True) @@ -176,10 +175,12 @@ async def test_google_update_expose_trigger_sync( async def test_google_entity_registry_sync( - hass: HomeAssistant, mock_cloud_login, cloud_prefs + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_cloud_login, + cloud_prefs, ) -> None: """Test Google config responds to entity registry.""" - entity_registry = er.async_get(hass) # Enable exposing new entities to Google expose_new(hass, True) @@ -246,19 +247,25 @@ async def test_google_entity_registry_sync( async def test_google_device_registry_sync( - hass: HomeAssistant, mock_cloud_login, cloud_prefs + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_cloud_login, + cloud_prefs, ) -> None: """Test Google config responds to device registry.""" config = CloudGoogleConfig( hass, GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, hass.data["cloud"] ) - ent_reg = er.async_get(hass) # Enable exposing new entities to Google expose_new(hass, True) - entity_entry = ent_reg.async_get_or_create("light", "hue", "1234", device_id="1234") - entity_entry = ent_reg.async_update_entity(entity_entry.entity_id, area_id="ABCD") + entity_entry = entity_registry.async_get_or_create( + "light", "hue", "1234", device_id="1234" + ) + entity_entry = entity_registry.async_update_entity( + entity_entry.entity_id, area_id="ABCD" + ) with patch.object(config, "async_sync_entities_all"): await config.async_initialize() @@ -293,7 +300,7 @@ async def test_google_device_registry_sync( assert len(mock_sync.mock_calls) == 0 - ent_reg.async_update_entity(entity_entry.entity_id, area_id=None) + entity_registry.async_update_entity(entity_entry.entity_id, area_id=None) # Device registry updated with relevant changes # but entity has area ID so not impacted diff --git a/tests/components/config/test_automation.py b/tests/components/config/test_automation.py index abe0ed90e86..ad4c7e90851 100644 --- a/tests/components/config/test_automation.py +++ b/tests/components/config/test_automation.py @@ -337,13 +337,13 @@ async def test_bad_formatted_automations( async def test_delete_automation( hass: HomeAssistant, hass_client: ClientSessionGenerator, + entity_registry: er.EntityRegistry, hass_config_store, setup_automation, ) -> None: """Test deleting an automation.""" - ent_reg = er.async_get(hass) - assert len(ent_reg.entities) == 2 + assert len(entity_registry.entities) == 2 with patch.object(config, "SECTIONS", ["automation"]): assert await async_setup_component(hass, "config", {}) @@ -371,7 +371,7 @@ async def test_delete_automation( assert hass_config_store["automations.yaml"] == [{"id": "moon"}] - assert len(ent_reg.entities) == 1 + assert len(entity_registry.entities) == 1 @pytest.mark.parametrize("automation_config", ({},)) diff --git a/tests/components/config/test_scene.py b/tests/components/config/test_scene.py index 1f09d5e9989..9fd596f7f91 100644 --- a/tests/components/config/test_scene.py +++ b/tests/components/config/test_scene.py @@ -184,13 +184,13 @@ async def test_bad_formatted_scene( async def test_delete_scene( hass: HomeAssistant, hass_client: ClientSessionGenerator, + entity_registry: er.EntityRegistry, hass_config_store, setup_scene, ) -> None: """Test deleting a scene.""" - ent_reg = er.async_get(hass) - assert len(ent_reg.entities) == 2 + assert len(entity_registry.entities) == 2 with patch.object(config, "SECTIONS", ["scene"]): assert await async_setup_component(hass, "config", {}) @@ -220,7 +220,7 @@ async def test_delete_scene( {"id": "light_off"}, ] - assert len(ent_reg.entities) == 1 + assert len(entity_registry.entities) == 1 @pytest.mark.parametrize("scene_config", ({},)) diff --git a/tests/components/config/test_script.py b/tests/components/config/test_script.py index cc0352301b4..7cf8cf5833e 100644 --- a/tests/components/config/test_script.py +++ b/tests/components/config/test_script.py @@ -281,7 +281,10 @@ async def test_update_remove_key_script_config( ), ) async def test_delete_script( - hass: HomeAssistant, hass_client: ClientSessionGenerator, hass_config_store + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + entity_registry: er.EntityRegistry, + hass_config_store, ) -> None: """Test deleting a script.""" with patch.object(config, "SECTIONS", ["script"]): @@ -292,8 +295,7 @@ async def test_delete_script( "script.two", ] - ent_reg = er.async_get(hass) - assert len(ent_reg.entities) == 2 + assert len(entity_registry.entities) == 2 client = await hass_client() @@ -313,7 +315,7 @@ async def test_delete_script( assert hass_config_store["scripts.yaml"] == {"one": {}} - assert len(ent_reg.entities) == 1 + assert len(entity_registry.entities) == 1 @pytest.mark.parametrize("script_config", ({},)) diff --git a/tests/components/counter/test_init.py b/tests/components/counter/test_init.py index 12750363469..53bec13d567 100644 --- a/tests/components/counter/test_init.py +++ b/tests/components/counter/test_init.py @@ -502,18 +502,20 @@ async def test_ws_list( async def test_ws_delete( - hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + entity_registry: er.EntityRegistry, + storage_setup, ) -> None: """Test WS delete cleans up entity registry.""" assert await storage_setup() input_id = "from_storage" input_entity_id = f"{DOMAIN}.{input_id}" - ent_reg = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is not None - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None + assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None client = await hass_ws_client(hass) @@ -525,7 +527,7 @@ async def test_ws_delete( state = hass.states.get(input_entity_id) assert state is None - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None + assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None async def test_update_min_max( @@ -546,7 +548,7 @@ async def test_update_min_max( input_id = "from_storage" input_entity_id = f"{DOMAIN}.{input_id}" - ent_reg = er.async_get(hass) + entity_registry = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is not None @@ -554,7 +556,7 @@ async def test_update_min_max( assert state.attributes[ATTR_MAXIMUM] == 100 assert state.attributes[ATTR_MINIMUM] == 10 assert state.attributes[ATTR_STEP] == 3 - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None + assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None client = await hass_ws_client(hass) @@ -627,11 +629,11 @@ async def test_create( counter_id = "new_counter" input_entity_id = f"{DOMAIN}.{counter_id}" - ent_reg = er.async_get(hass) + entity_registry = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is None - assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, counter_id) is None + assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, counter_id) is None client = await hass_ws_client(hass) diff --git a/tests/components/cpuspeed/test_sensor.py b/tests/components/cpuspeed/test_sensor.py index 625f80a6814..457d9c37d14 100644 --- a/tests/components/cpuspeed/test_sensor.py +++ b/tests/components/cpuspeed/test_sensor.py @@ -25,13 +25,13 @@ from tests.common import MockConfigEntry async def test_sensor( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, mock_cpuinfo: MagicMock, init_integration: MockConfigEntry, ) -> None: """Test the CPU Speed sensor.""" await async_setup_component(hass, "homeassistant", {}) - entity_registry = er.async_get(hass) - device_registry = dr.async_get(hass) entry = entity_registry.async_get("sensor.cpu_speed") assert entry