Use registry fixtures in tests (2/8) (#180920)

This commit is contained in:
Joost Lekkerkerker
2026-08-31 18:55:54 +02:00
committed by GitHub
parent ff5bde37e9
commit b23e5c84e5
9 changed files with 29 additions and 25 deletions
+3 -3
View File
@@ -15,6 +15,7 @@ from tests.typing import ClientSessionGenerator
async def test_change_schedule_fails(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
doorbird_mocker: DoorbirdMockerType,
hass_client: ClientSessionGenerator,
) -> None:
@@ -24,9 +25,8 @@ async def test_change_schedule_fails(
favorites_side_effect=mock_not_found_exception()
)
assert doorbird_entry.entry.state is ConfigEntryState.SETUP_RETRY
issue_reg = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
assert len(issue_reg.issues) == 1
issue = list(issue_reg.issues.values())[0]
assert len(issue_registry.issues) == 1
issue = list(issue_registry.issues.values())[0]
issue_id = issue.issue_id
assert issue.domain == DOMAIN
+9 -6
View File
@@ -458,14 +458,15 @@ async def test_remote_sensors(hass: HomeAssistant) -> None:
async def test_remote_sensor_devices(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test remote sensor devices."""
await setup_platform(hass, [const.Platform.CLIMATE, const.Platform.SENSOR])
freezer.tick(100)
async_fire_time_changed(hass)
state = hass.states.get(ENTITY_ID)
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
for device in device_registry.devices:
if device.name == "Remote Sensor 1":
remote_sensor_1_id = device.id
@@ -545,7 +546,9 @@ async def test_remote_sensor_ids_names(hass: HomeAssistant) -> None:
assert sorted(name_by_user_list) == sorted(["Remote Sensor 1", "ecobee"])
async def test_remote_sensors_ignore_non_ecobee_devices(hass: HomeAssistant) -> None:
async def test_remote_sensors_ignore_non_ecobee_devices(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Devices from other integrations sharing a sensor's name are not matched.
Regression test: the remote-sensor device lookup matched by device name across
@@ -553,7 +556,6 @@ async def test_remote_sensors_ignore_non_ecobee_devices(hass: HomeAssistant) ->
an ecobee sensor's name was wrongly reported as a participating sensor.
"""
await setup_platform(hass, [const.Platform.CLIMATE, const.Platform.SENSOR])
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
# A device from another integration that shares the ecobee sensor's name.
other_entry = MockConfigEntry(domain="other")
@@ -579,11 +581,12 @@ async def test_remote_sensors_ignore_non_ecobee_devices(hass: HomeAssistant) ->
assert sorted(name_by_user_list) == sorted(["Remote Sensor 1", "ecobee"])
async def test_set_sensors_used_in_climate(hass: HomeAssistant) -> None:
async def test_set_sensors_used_in_climate(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test set sensors used in climate."""
# Get device_id of remote sensor from the device registry.
await setup_platform(hass, [const.Platform.CLIMATE, const.Platform.SENSOR])
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
for device in device_registry.devices:
if device.name == "Remote Sensor 1":
remote_sensor_1_id = device.id
+2 -1
View File
@@ -375,6 +375,7 @@ async def test_clean_area_room_from_not_current_map(
async def test_raise_segment_changed_issue(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
issue_registry: ir.IssueRegistry,
controller: EcovacsController,
entity_id: str,
events: tuple[Event, ...],
@@ -390,7 +391,7 @@ async def test_raise_segment_changed_issue(
entity_entry = entity_registry.async_get(entity_id)
issue_id = f"{vacuum.ISSUE_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
+1 -2
View File
@@ -747,13 +747,12 @@ async def test_deep_sleep_added_after_setup(
async def test_entity_assignment_to_sub_device(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
) -> None:
"""Test entities are assigned to correct sub devices."""
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
# Define sub devices
sub_devices = [
SubDeviceInfo(device_id=11111111, name="Motion Sensor", area_id=0),
+7 -7
View File
@@ -2385,6 +2385,7 @@ async def test_entry_missing_bluetooth_mac_address(
async def test_device_adds_friendly_name(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
caplog: pytest.LogCaptureFixture,
@@ -2395,8 +2396,7 @@ async def test_device_adds_friendly_name(
device_info={"name": "nofriendlyname", "friendly_name": ""},
)
await hass.async_block_till_done()
dev_reg = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
dev = dev_reg.async_get_device_by_connection(
dev = device_registry.async_get_device_by_connection(
(dr.CONNECTION_NETWORK_MAC, device.entry.unique_id), device.entry.entry_id
)
assert dev.name == "Nofriendlyname"
@@ -2418,7 +2418,7 @@ async def test_device_adds_friendly_name(
)
await device.mock_connect()
await hass.async_block_till_done()
dev = dev_reg.async_get_device_by_connection(
dev = device_registry.async_get_device_by_connection(
(dr.CONNECTION_NETWORK_MAC, device.entry.unique_id), device.entry.entry_id
)
assert dev.name == "I have a friendly name"
@@ -2477,11 +2477,11 @@ async def test_assist_in_progress_issue_deleted(
async def test_sub_device_creation(
hass: HomeAssistant,
area_registry: ar.AreaRegistry,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
) -> None:
"""Test sub devices are created in device registry."""
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
# Define areas
areas = [
@@ -2548,11 +2548,11 @@ async def test_sub_device_creation(
async def test_sub_device_cleanup(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
) -> None:
"""Test sub devices are removed when they no longer exist."""
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
# Initial sub devices
sub_devices_initial = [
@@ -2645,11 +2645,11 @@ async def test_sub_device_cleanup(
async def test_sub_device_with_empty_name(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
) -> None:
"""Test sub devices with empty names are handled correctly."""
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
# Define sub devices with empty names
sub_devices = [
@@ -2690,11 +2690,11 @@ async def test_sub_device_with_empty_name(
async def test_sub_device_references_main_device_area(
hass: HomeAssistant,
area_registry: ar.AreaRegistry,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: MockESPHomeDeviceType,
) -> None:
"""Test sub devices can reference the main device's area."""
device_registry = dr.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
# Define areas - note we don't include area_id=0 in the areas list
areas = [
+2 -2
View File
@@ -87,6 +87,7 @@ async def test_last_alarm_pic_sensor_not_created(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_ezviz_client: AsyncMock,
entity_registry: er.EntityRegistry,
) -> None:
"""Test that last_alarm_pic sensor is not created."""
# Mock coordinator data with all sensor fields
@@ -115,8 +116,7 @@ async def test_last_alarm_pic_sensor_not_created(
assert last_alarm_pic_state is None
# But other sensors should be created
registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
battery_entity = registry.async_get("sensor.camera_1_battery")
battery_entity = entity_registry.async_get("sensor.camera_1_battery")
assert battery_entity is not None
+2 -2
View File
@@ -271,6 +271,7 @@ async def test_cleanup_button(
async def test_cleanup_button_deprecation_issue(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
issue_registry: ir.IssueRegistry,
fc_class_mock,
fh_class_mock,
fs_class_mock,
@@ -283,7 +284,6 @@ async def test_cleanup_button_deprecation_issue(
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.LOADED
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
assert issue_registry.async_get_issue(DOMAIN, "deprecated_cleanup_button")
@@ -291,6 +291,7 @@ async def test_cleanup_button_deprecation_issue(
async def test_firmware_update_button_deprecation_issue(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
issue_registry: ir.IssueRegistry,
fc_class_mock,
fh_class_mock,
fs_class_mock,
@@ -303,5 +304,4 @@ async def test_firmware_update_button_deprecation_issue(
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.LOADED
issue_registry = ir.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
assert issue_registry.async_get_issue(DOMAIN, "deprecated_firmware_update_button")
@@ -26,9 +26,10 @@ async def test_get_forecast_service(
mock_config_entry: MockConfigEntry,
mock_api: AsyncMock,
snapshot: SnapshotAssertion,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test fetching a forecast for a subentry."""
device = dr.async_get(hass).async_get_device_by_identifier( # pylint: disable=home-assistant-tests-registry-fixtures
device = device_registry.async_get_device_by_identifier(
(DOMAIN, f"{mock_config_entry.entry_id}_home-subentry-id"),
mock_config_entry.entry_id,
)
+1 -1
View File
@@ -834,6 +834,7 @@ async def test_dynamic_device_added(
mock_growatt_v1_api,
mock_config_entry: MockConfigEntry,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test that new devices are dynamically added when discovered during a scan."""
@@ -881,7 +882,6 @@ async def test_dynamic_device_added(
# Verify multiple entity types to confirm end-to-end dynamic device support
assert hass.states.get("switch.new456789_charge_from_grid") is not None
# Additional check: verify entities exist in the entity registry
entity_registry = er.async_get(hass) # pylint: disable=home-assistant-tests-registry-fixtures
new_device_entry = device_registry.async_get_device_by_identifier(
(DOMAIN, "NEW456789"), mock_config_entry.entry_id
)