From acf7a9e1c2484a3c9bbe7c7314f0a6acb6ac085b Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 31 Aug 2026 18:52:07 +0200 Subject: [PATCH] Use registry fixtures in tests (3/8) (#180923) --- tests/components/hassio/test_backup.py | 2 +- tests/components/hassio/test_init.py | 5 +++-- tests/components/heos/test_diagnostics.py | 2 +- .../components/homeassistant_hardware/test_switch.py | 2 +- tests/components/homekit_controller/test_init.py | 8 +++++--- tests/components/homematicip_cloud/test_sensor.py | 5 +++-- tests/components/homewizard/test_init.py | 12 ++++++------ tests/components/hypontech/test_sensor.py | 2 +- tests/components/imou/test_button.py | 6 ++++-- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/components/hassio/test_backup.py b/tests/components/hassio/test_backup.py index aabc92642563..f58f9ac4758d 100644 --- a/tests/components/hassio/test_backup.py +++ b/tests/components/hassio/test_backup.py @@ -1122,6 +1122,7 @@ async def test_reader_writer_create( ) async def test_reader_writer_create_addon_folder_error( hass: HomeAssistant, + issue_registry: ir.IssueRegistry, hass_supervisor_ws_client: WebSocketGenerator, freezer: FrozenDateTimeFactory, supervisor_client: AsyncMock, @@ -1146,7 +1147,6 @@ async def test_reader_writer_create_addon_folder_error( ), ] - issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures assert not issue_registry.issues await client.send_json_auto_id({"type": "backup/subscribe_events"}) diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index 220f104f64e6..e2adad92dcc9 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -970,7 +970,9 @@ async def test_invalid_service_calls_folder_duplicates(hass: HomeAssistant) -> N @pytest.mark.usefixtures("hassio_env") async def test_partial_backup_legacy_homeassistant_folder( - hass: HomeAssistant, supervisor_client: AsyncMock + hass: HomeAssistant, + issue_registry: ir.IssueRegistry, + supervisor_client: AsyncMock, ) -> None: """Test legacy "homeassistant" folder is translated to homeassistant=True.""" assert await async_setup_component(hass, DOMAIN, {}) @@ -991,7 +993,6 @@ async def test_partial_backup_legacy_homeassistant_folder( folders={Folder.SSL}, ) ) - issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures assert ( issue_registry.async_get_issue("hassio", "legacy_homeassistant_folder") is not None diff --git a/tests/components/heos/test_diagnostics.py b/tests/components/heos/test_diagnostics.py index 97eadff962a9..ec17b0dfee87 100644 --- a/tests/components/heos/test_diagnostics.py +++ b/tests/components/heos/test_diagnostics.py @@ -64,6 +64,7 @@ async def test_config_entry_diagnostics_error_getting_system( async def test_device_diagnostics( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, hass_client: ClientSessionGenerator, config_entry: MockConfigEntry, snapshot: SnapshotAssertion, @@ -71,7 +72,6 @@ async def test_device_diagnostics( """Test generating diagnostics for a config entry.""" config_entry.add_to_hass(hass) assert await hass.config_entries.async_setup(config_entry.entry_id) - device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures device = device_registry.async_get_device_by_identifier( (DOMAIN, "1"), config_entry.entry_id ) diff --git a/tests/components/homeassistant_hardware/test_switch.py b/tests/components/homeassistant_hardware/test_switch.py index c36227b77748..bc65b853e54b 100644 --- a/tests/components/homeassistant_hardware/test_switch.py +++ b/tests/components/homeassistant_hardware/test_switch.py @@ -181,6 +181,7 @@ async def test_switch_default_off_state( ) async def test_switch_restore_state( hass: HomeAssistant, + entity_registry: er.EntityRegistry, switch_config_entry: ConfigEntry, mock_firmware_client, initial_state: str, @@ -204,7 +205,6 @@ async def test_switch_restore_state( ] # Verify entity registry attributes - entity_registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures entity_entry = entity_registry.async_get(TEST_SWITCH_ENTITY_ID) assert entity_entry is not None assert entity_entry.entity_category == EntityCategory.CONFIG diff --git a/tests/components/homekit_controller/test_init.py b/tests/components/homekit_controller/test_init.py index 81ea2a686801..6f8bf6e0932c 100644 --- a/tests/components/homekit_controller/test_init.py +++ b/tests/components/homekit_controller/test_init.py @@ -243,7 +243,10 @@ async def test_ble_device_only_checks_is_available( @pytest.mark.usefixtures("fake_ble_discovery", "fake_ble_pairing") async def test_ble_device_populates_connections( - hass: HomeAssistant, get_next_aid: Callable[[], int], controller + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + get_next_aid: Callable[[], int], + controller, ) -> None: """Test a BLE device populates connections in the device registry.""" aid = get_next_aid() @@ -260,9 +263,8 @@ async def test_ble_device_populates_connections( await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.LOADED - dev_reg = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures assert ( - dev_reg.async_get_device_by_connection( + device_registry.async_get_device_by_connection( ("bluetooth", "AA:BB:CC:DD:EE:FF"), config_entry.entry_id ) is not None diff --git a/tests/components/homematicip_cloud/test_sensor.py b/tests/components/homematicip_cloud/test_sensor.py index a6c5e73e9456..94d587916484 100644 --- a/tests/components/homematicip_cloud/test_sensor.py +++ b/tests/components/homematicip_cloud/test_sensor.py @@ -925,7 +925,9 @@ async def test_hmip_water_valve_water_volume_since_open( async def test_hmip_smoke_detector_dirt_level( - hass: HomeAssistant, default_mock_hap_factory: HomeFactory + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + default_mock_hap_factory: HomeFactory, ) -> None: """Test HomematicipSmokeDetectorDirtLevel.""" entity_id = "sensor.rauchwarnmelder_dirt_level" @@ -933,7 +935,6 @@ async def test_hmip_smoke_detector_dirt_level( device_model = "HmIP-SWSD" # Pre-register the entity as enabled before platform loads - entity_registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures entity_registry.async_get_or_create( "sensor", DOMAIN, diff --git a/tests/components/homewizard/test_init.py b/tests/components/homewizard/test_init.py index 51fc8cd4cd60..5a47827f6723 100644 --- a/tests/components/homewizard/test_init.py +++ b/tests/components/homewizard/test_init.py @@ -131,6 +131,7 @@ async def test_load_detect_invalid_token( @pytest.mark.usefixtures("mock_homewizardenergy") async def test_load_creates_repair_issue( hass: HomeAssistant, + issue_registry: ir.IssueRegistry, mock_config_entry: MockConfigEntry, mock_homewizardenergy: MagicMock, ) -> None: @@ -143,8 +144,6 @@ async def test_load_creates_repair_issue( await hass.async_block_till_done() - issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures - issue = issue_registry.async_get_issue( domain=DOMAIN, issue_id=f"migrate_to_v2_api_{mock_config_entry.entry_id}" ) @@ -157,6 +156,8 @@ async def test_load_creates_repair_issue( @pytest.mark.usefixtures("mock_homewizardenergy") async def test_load_creates_repair_issue_when_name_is_updated( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + issue_registry: ir.IssueRegistry, mock_config_entry: MockConfigEntry, mock_homewizardenergy: MagicMock, ) -> None: @@ -169,7 +170,6 @@ async def test_load_creates_repair_issue_when_name_is_updated( await hass.async_block_till_done() - issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures issue_id = f"migrate_to_v2_api_{mock_config_entry.entry_id}" issue = issue_registry.async_get_issue(domain=DOMAIN, issue_id=issue_id) @@ -179,7 +179,6 @@ async def test_load_creates_repair_issue_when_name_is_updated( assert issue.translation_placeholders["title"] == "Device" # Update the device name - device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures device = get_main_device(hass, mock_config_entry) # Update device name @@ -307,6 +306,7 @@ async def test_battery_cloud_issue_updates_only_on_state_transition( @pytest.mark.usefixtures("mock_homewizardenergy") async def test_battery_cloud_issue_stale_issue_cleared_on_reload( hass: HomeAssistant, + issue_registry: ir.IssueRegistry, mock_config_entry: MockConfigEntry, mock_homewizardenergy: MagicMock, ) -> None: @@ -319,12 +319,12 @@ async def test_battery_cloud_issue_stale_issue_cleared_on_reload( mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is not None # pylint: disable=home-assistant-tests-registry-fixtures + assert issue_registry.async_get_issue(DOMAIN, issue_id) is not None combined_data.system.cloud_enabled = True await hass.config_entries.async_reload(mock_config_entry.entry_id) await hass.async_block_till_done() - assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is None # pylint: disable=home-assistant-tests-registry-fixtures + assert issue_registry.async_get_issue(DOMAIN, issue_id) is None async def test_main_device_registered_before_platform_forwarding( diff --git a/tests/components/hypontech/test_sensor.py b/tests/components/hypontech/test_sensor.py index 5bce4c7ceb8b..53b70c3cb47e 100644 --- a/tests/components/hypontech/test_sensor.py +++ b/tests/components/hypontech/test_sensor.py @@ -30,6 +30,7 @@ async def test_sensors( async def test_device_manufacturer_uses_oem( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, mock_hyponcloud: AsyncMock, ) -> None: """Test device manufacturer uses the selected OEM.""" @@ -46,7 +47,6 @@ async def test_device_manufacturer_uses_oem( with patch("homeassistant.components.hypontech._PLATFORMS", [Platform.SENSOR]): await setup_integration(hass, mock_config_entry) - device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures overview_device = device_registry.async_get_device_by_identifier( (DOMAIN, mock_config_entry.unique_id), mock_config_entry.entry_id ) diff --git a/tests/components/imou/test_button.py b/tests/components/imou/test_button.py index 4b8d8e2075e8..142016d36418 100644 --- a/tests/components/imou/test_button.py +++ b/tests/components/imou/test_button.py @@ -52,11 +52,13 @@ async def test_button_entities_snapshot( @pytest.mark.usefixtures("init_integration") async def test_setup_ignores_unknown_button_types( hass: HomeAssistant, + entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, ) -> None: """Unknown button keys from the API are not turned into entities.""" - registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures - entries = er.async_entries_for_config_entry(registry, mock_config_entry.entry_id) + entries = er.async_entries_for_config_entry( + entity_registry, mock_config_entry.entry_id + ) assert len(entries) == 1 assert entries[0].translation_key == PARAM_MUTE