mirror of
https://github.com/home-assistant/core.git
synced 2026-09-03 12:02:16 +01:00
Use registry fixtures in tests (6/8) (#180928)
This commit is contained in:
@@ -261,6 +261,7 @@ async def test_device(
|
||||
)
|
||||
async def test_data_cap_issues(
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_onedrive_client: MagicMock,
|
||||
mock_drive: Drive,
|
||||
@@ -274,7 +275,6 @@ async def test_data_cap_issues(
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
issue = issue_registry.async_get_issue(DOMAIN, issue_key)
|
||||
assert (issue is not None) == issue_exists
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ from . import (
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_migrate_camera_entities_unique_ids(hass: HomeAssistant) -> None:
|
||||
async def test_migrate_camera_entities_unique_ids(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test that camera entities unique ids get migrated properly."""
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, unique_id=MAC)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
entity_registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
|
||||
entity_with_only_mac = entity_registry.async_get_or_create(
|
||||
domain="camera",
|
||||
platform="onvif",
|
||||
|
||||
@@ -40,6 +40,7 @@ async def test_entry_setup_unload(
|
||||
@pytest.mark.usefixtures("mock_openrgb_client")
|
||||
async def test_remove_config_entry_device_server(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that server device cannot be removed."""
|
||||
@@ -48,7 +49,6 @@ async def test_remove_config_entry_device_server(
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
server_device = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, mock_config_entry.entry_id), mock_config_entry.entry_id
|
||||
)
|
||||
@@ -66,6 +66,7 @@ async def test_remove_config_entry_device_server(
|
||||
@pytest.mark.usefixtures("mock_openrgb_client")
|
||||
async def test_remove_config_entry_device_still_connected(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that connected devices cannot be removed."""
|
||||
@@ -74,8 +75,6 @@ async def test_remove_config_entry_device_still_connected(
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
|
||||
# Get a device that's in coordinator.data (still connected)
|
||||
devices = dr.async_entries_for_config_entry(
|
||||
device_registry, mock_config_entry.entry_id
|
||||
|
||||
@@ -182,6 +182,7 @@ async def test_coordinator_subsequent_run_no_energy_data(
|
||||
async def test_coordinator_migration(
|
||||
recorder_mock: Recorder,
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_opower_api: AsyncMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
@@ -238,7 +239,6 @@ async def test_coordinator_migration(
|
||||
assert stats == snapshot
|
||||
|
||||
# Check that an issue was created
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
issue = issue_registry.async_get_issue(DOMAIN, "return_to_grid_migration_111111")
|
||||
assert issue is not None
|
||||
assert issue.severity == ir.IssueSeverity.WARNING
|
||||
@@ -370,6 +370,7 @@ async def test_coordinator_updates_with_finer_grained_data(
|
||||
async def test_coordinator_migration_empty_source_stats(
|
||||
recorder_mock: Recorder,
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_opower_api: AsyncMock,
|
||||
) -> None:
|
||||
@@ -412,7 +413,6 @@ async def test_coordinator_migration_empty_source_stats(
|
||||
# no individual stats were found
|
||||
assert migrated is False
|
||||
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
issue = issue_registry.async_get_issue(DOMAIN, "return_to_grid_migration_111111")
|
||||
assert issue is None
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from tests.common import MockConfigEntry
|
||||
async def test_sensors(
|
||||
recorder_mock: Recorder,
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_opower_api: AsyncMock,
|
||||
) -> None:
|
||||
@@ -39,8 +40,6 @@ async def test_sensors(
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
|
||||
# Check electric sensors
|
||||
entry = entity_registry.async_get(
|
||||
"sensor.elec_account_111111_current_bill_electric_usage_to_date"
|
||||
|
||||
@@ -181,9 +181,6 @@ async def test_migration_v1_to_v3(
|
||||
entry.add_to_hass(hass)
|
||||
assert entry.version == 1
|
||||
|
||||
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
entity_registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
|
||||
vm_device = device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, f"{entry.entry_id}_vm_100")},
|
||||
|
||||
@@ -468,6 +468,7 @@ async def test_update_unavailability_threshold(
|
||||
|
||||
async def test_cloud_api_repair(
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_roborock_entry: MockConfigEntry,
|
||||
fake_vacuum: FakeDevice,
|
||||
) -> None:
|
||||
@@ -480,7 +481,6 @@ async def test_cloud_api_repair(
|
||||
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
assert len(issue_registry.issues) == 1
|
||||
# Check that both expected device names are present, regardless of order
|
||||
assert all(
|
||||
@@ -507,6 +507,7 @@ async def test_cloud_api_repair(
|
||||
@pytest.mark.parametrize("platforms", [[Platform.SENSOR]])
|
||||
async def test_cloud_api_repair_cleared_on_update(
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_roborock_entry: MockConfigEntry,
|
||||
fake_vacuum: FakeDevice,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
@@ -523,7 +524,6 @@ async def test_cloud_api_repair_cleared_on_update(
|
||||
await hass.async_block_till_done()
|
||||
assert mock_roborock_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
assert len(issue_registry.issues) == 1
|
||||
|
||||
# Fake that the device is reachable locally again.
|
||||
@@ -541,7 +541,6 @@ async def test_cloud_api_repair_cleared_on_update(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Verify that the repair issue is cleared
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
assert len(issue_registry.issues) == 0
|
||||
|
||||
# Fake the device is cloud only again. Refreshing the coordinator
|
||||
@@ -557,7 +556,6 @@ async def test_cloud_api_repair_cleared_on_update(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Verify that the repair issue still does not exist
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
assert len(issue_registry.issues) == 0
|
||||
|
||||
|
||||
|
||||
@@ -625,6 +625,7 @@ async def test_segments_changed_issue(
|
||||
hass: HomeAssistant,
|
||||
setup_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
fake_vacuum: FakeDevice,
|
||||
) -> None:
|
||||
"""Test repair issue created when segments change after mapping."""
|
||||
@@ -647,7 +648,7 @@ async def test_segments_changed_issue(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
issue_id = f"segments_changed_{entity_entry.id}"
|
||||
issue = ir.async_get(hass).async_get_issue(VACUUM_DOMAIN, issue_id) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
issue = issue_registry.async_get_issue(VACUUM_DOMAIN, issue_id)
|
||||
assert issue is not None
|
||||
assert issue.severity == ir.IssueSeverity.WARNING
|
||||
assert issue.translation_key == "segments_changed"
|
||||
@@ -657,6 +658,7 @@ async def test_segments_changed_issue_no_map_info(
|
||||
hass: HomeAssistant,
|
||||
setup_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
fake_vacuum: FakeDevice,
|
||||
) -> None:
|
||||
"""Test no repair issue is created when map info is not loaded/empty."""
|
||||
@@ -680,7 +682,7 @@ async def test_segments_changed_issue_no_map_info(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
issue_id = f"segments_changed_{entity_entry.id}"
|
||||
issue = ir.async_get(hass).async_get_issue(VACUUM_DOMAIN, issue_id) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
issue = issue_registry.async_get_issue(VACUUM_DOMAIN, issue_id)
|
||||
assert issue is None
|
||||
|
||||
|
||||
|
||||
@@ -6754,11 +6754,12 @@ async def test_exclude_attributes(hass: HomeAssistant) -> None:
|
||||
],
|
||||
)
|
||||
async def test_clean_up_repairs(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
) -> None:
|
||||
"""Test cleaning up repairs."""
|
||||
await async_setup_component(hass, DOMAIN, {})
|
||||
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
|
||||
client = await hass_ws_client()
|
||||
|
||||
# Create some issues
|
||||
|
||||
Reference in New Issue
Block a user