Use registry fixtures in tests (3/8) (#180923)

This commit is contained in:
Joost Lekkerkerker
2026-08-31 18:52:07 +02:00
committed by GitHub
parent 3b84971576
commit acf7a9e1c2
9 changed files with 25 additions and 19 deletions
+1 -1
View File
@@ -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"})
+3 -2
View File
@@ -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
+1 -1
View File
@@ -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
)
@@ -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
@@ -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
@@ -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,
+6 -6
View File
@@ -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(
+1 -1
View File
@@ -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
)
+4 -2
View File
@@ -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