Use registry fixtures in tests (r) (#118293)

This commit is contained in:
epenet 2024-05-28 14:23:31 +02:00 committed by GitHub
parent 2545b7d3bb
commit 8d8696075b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 234 additions and 180 deletions

View file

@ -49,11 +49,12 @@ async def test_async_setup_entry_auth_failed(
@pytest.mark.freeze_time("2021-12-03 00:00:00+00:00")
async def test_device_info(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test device info."""
entry = await setup_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
await hass.async_block_till_done()
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})

View file

@ -71,6 +71,7 @@ async def test_number_values(
async def test_set_value(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
responses: list[str],
) -> None:
@ -79,7 +80,6 @@ async def test_set_value(
raindelay = hass.states.get("number.rain_bird_controller_rain_delay")
assert raindelay is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={(DOMAIN, MAC_ADDRESS.lower())}
)

View file

@ -59,6 +59,7 @@ async def test_invalid_password(hass: HomeAssistant, config) -> None:
)
async def test_migrate_1_2(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
client,
config,
config_entry,
@ -69,10 +70,8 @@ async def test_migrate_1_2(
platform,
) -> None:
"""Test migration from version 1 to 2 (consistent unique IDs)."""
ent_reg = er.async_get(hass)
# Create entity RegistryEntry using old unique ID format:
entity_entry = ent_reg.async_get_or_create(
entity_entry = entity_registry.async_get_or_create(
platform,
DOMAIN,
old_unique_id,
@ -96,9 +95,9 @@ async def test_migrate_1_2(
await hass.async_block_till_done()
# Check that new RegistryEntry is using new unique ID format
entity_entry = ent_reg.async_get(entity_id)
entity_entry = entity_registry.async_get(entity_id)
assert entity_entry.unique_id == new_unique_id
assert ent_reg.async_get_entity_id(platform, DOMAIN, old_unique_id) is None
assert entity_registry.async_get_entity_id(platform, DOMAIN, old_unique_id) is None
async def test_options_flow(hass: HomeAssistant, config, config_entry) -> None:

View file

@ -11,12 +11,11 @@ from tests.common import MockConfigEntry
async def test_vehicle_binary_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the RDW vehicle binary sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("binary_sensor.skoda_11zkz3_liability_insured")
entry = entity_registry.async_get("binary_sensor.skoda_11zkz3_liability_insured")
assert entry

View file

@ -16,12 +16,11 @@ from tests.common import MockConfigEntry
async def test_vehicle_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the RDW vehicle sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.skoda_11zkz3_apk_expiration")
entry = entity_registry.async_get("sensor.skoda_11zkz3_apk_expiration")
assert entry

View file

@ -118,13 +118,13 @@ async def test_setup_entry_missing_vehicle_details(
@pytest.mark.parametrize("vehicle_type", ["zoe_40"], indirect=True)
async def test_registry_cleanup(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
config_entry: ConfigEntry,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test being able to remove a disconnected device."""
assert await async_setup_component(hass, "config", {})
entry_id = config_entry.entry_id
device_registry = dr.async_get(hass)
live_id = "VF1AAAAA555777999"
dead_id = "VF1AAAAA555777888"

View file

@ -253,7 +253,7 @@ async def test_service_invalid_device_id(
async def test_service_invalid_device_id2(
hass: HomeAssistant, config_entry: ConfigEntry
hass: HomeAssistant, device_registry: dr.DeviceRegistry, config_entry: ConfigEntry
) -> None:
"""Test that service fails with ValueError if device_id not found in vehicles."""
await hass.config_entries.async_setup(config_entry.entry_id)
@ -261,7 +261,6 @@ async def test_service_invalid_device_id2(
extra_vehicle = MOCK_VEHICLES["captur_phev"]["expected_device"]
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers=extra_vehicle[ATTR_IDENTIFIERS],

View file

@ -465,7 +465,9 @@ async def test_setup_query_params(hass: HomeAssistant) -> None:
@respx.mock
async def test_entity_config(hass: HomeAssistant) -> None:
async def test_entity_config(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test entity configuration."""
config = {
@ -486,7 +488,6 @@ async def test_entity_config(hass: HomeAssistant) -> None:
assert await async_setup_component(hass, BINARY_SENSOR_DOMAIN, config)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
assert (
entity_registry.async_get("binary_sensor.rest_binary_sensor").unique_id
== "very_unique"

View file

@ -982,7 +982,9 @@ async def test_reload(hass: HomeAssistant) -> None:
@respx.mock
async def test_entity_config(hass: HomeAssistant) -> None:
async def test_entity_config(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test entity configuration."""
config = {
@ -1006,7 +1008,6 @@ async def test_entity_config(hass: HomeAssistant) -> None:
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
assert entity_registry.async_get("sensor.rest_sensor").unique_id == "very_unique"
state = hass.states.get("sensor.rest_sensor")

View file

@ -450,7 +450,9 @@ async def test_update_timeout(hass: HomeAssistant) -> None:
@respx.mock
async def test_entity_config(hass: HomeAssistant) -> None:
async def test_entity_config(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test entity configuration."""
respx.get(RESOURCE) % HTTPStatus.OK
@ -471,7 +473,6 @@ async def test_entity_config(hass: HomeAssistant) -> None:
assert await async_setup_component(hass, SWITCH_DOMAIN, config)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
assert entity_registry.async_get("switch.rest_switch").unique_id == "very_unique"
state = hass.states.get("switch.rest_switch")

View file

@ -480,7 +480,9 @@ async def test_default_keepalive(
assert "TCP Keepalive IDLE timer was provided" not in caplog.text
async def test_unique_id(hass: HomeAssistant, monkeypatch) -> None:
async def test_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry, monkeypatch
) -> None:
"""Validate the device unique_id."""
DOMAIN = "sensor"
@ -503,15 +505,13 @@ async def test_unique_id(hass: HomeAssistant, monkeypatch) -> None:
},
}
registry = er.async_get(hass)
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
humidity_entry = registry.async_get("sensor.humidity_device")
humidity_entry = entity_registry.async_get("sensor.humidity_device")
assert humidity_entry
assert humidity_entry.unique_id == "my_humidity_device_unique_id"
temperature_entry = registry.async_get("sensor.temperature_device")
temperature_entry = entity_registry.async_get("sensor.temperature_device")
assert temperature_entry
assert temperature_entry.unique_id == "my_temperature_device_unique_id"

View file

@ -426,7 +426,11 @@ async def test_options_add_duplicate_device(hass: HomeAssistant) -> None:
assert result["errors"]["event_code"] == "already_configured_device"
async def test_options_replace_sensor_device(hass: HomeAssistant) -> None:
async def test_options_replace_sensor_device(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we can replace a sensor device."""
entry = MockConfigEntry(
@ -486,7 +490,6 @@ async def test_options_replace_sensor_device(hass: HomeAssistant) -> None:
)
assert state
device_registry = dr.async_get(hass)
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
old_device = next(
@ -533,8 +536,6 @@ async def test_options_replace_sensor_device(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(
"sensor.thgn122_123_thgn132_thgr122_228_238_268_f0_04_signal_strength"
)
@ -583,7 +584,11 @@ async def test_options_replace_sensor_device(hass: HomeAssistant) -> None:
assert not state
async def test_options_replace_control_device(hass: HomeAssistant) -> None:
async def test_options_replace_control_device(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we can replace a control device."""
entry = MockConfigEntry(
@ -619,7 +624,6 @@ async def test_options_replace_control_device(hass: HomeAssistant) -> None:
state = hass.states.get("switch.ac_1118cdea_2")
assert state
device_registry = dr.async_get(hass)
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
old_device = next(
@ -666,8 +670,6 @@ async def test_options_replace_control_device(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("binary_sensor.ac_118cdea_2")
assert entry
assert entry.device_id == new_device
@ -686,7 +688,9 @@ async def test_options_replace_control_device(hass: HomeAssistant) -> None:
assert not state
async def test_options_add_and_configure_device(hass: HomeAssistant) -> None:
async def test_options_add_and_configure_device(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test we can add a device."""
entry = MockConfigEntry(
@ -757,7 +761,6 @@ async def test_options_add_and_configure_device(hass: HomeAssistant) -> None:
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
device_registry = dr.async_get(hass)
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
assert device_entries[0].id
@ -795,7 +798,9 @@ async def test_options_add_and_configure_device(hass: HomeAssistant) -> None:
assert "delay_off" not in entry.data["devices"]["0913000022670e013970"]
async def test_options_configure_rfy_cover_device(hass: HomeAssistant) -> None:
async def test_options_configure_rfy_cover_device(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test we can configure the venetion blind mode of an Rfy cover."""
entry = MockConfigEntry(
@ -842,7 +847,6 @@ async def test_options_configure_rfy_cover_device(hass: HomeAssistant) -> None:
entry.data["devices"]["0C1a0000010203010000000000"]["device_id"], list
)
device_registry = dr.async_get(hass)
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
assert device_entries[0].id

View file

@ -104,7 +104,9 @@ async def test_invalid_event_type(
assert hass.states.get("event.arc_c1") == state
async def test_ignoring_lighting4(hass: HomeAssistant, rfxtrx) -> None:
async def test_ignoring_lighting4(
hass: HomeAssistant, entity_registry: er.EntityRegistry, rfxtrx
) -> None:
"""Test with 1 sensor."""
entry = await setup_rfx_test_cfg(
hass,
@ -117,10 +119,11 @@ async def test_ignoring_lighting4(hass: HomeAssistant, rfxtrx) -> None:
},
)
registry = er.async_get(hass)
entries = [
entry
for entry in registry.entities.get_entries_for_config_entry_id(entry.entry_id)
for entry in entity_registry.entities.get_entries_for_config_entry_id(
entry.entry_id
)
if entry.domain == Platform.EVENT
]
assert entries == []

View file

@ -19,7 +19,9 @@ from tests.typing import WebSocketGenerator
SOME_PROTOCOLS = ["ac", "arc"]
async def test_fire_event(hass: HomeAssistant, rfxtrx) -> None:
async def test_fire_event(
hass: HomeAssistant, device_registry: dr.DeviceRegistry, rfxtrx
) -> None:
"""Test fire event."""
await setup_rfx_test_cfg(
hass,
@ -31,8 +33,6 @@ async def test_fire_event(hass: HomeAssistant, rfxtrx) -> None:
},
)
device_registry: dr.DeviceRegistry = dr.async_get(hass)
calls = []
@callback
@ -92,7 +92,9 @@ async def test_send(hass: HomeAssistant, rfxtrx) -> None:
async def test_ws_device_remove(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test removing a device through device registry."""
assert await async_setup_component(hass, "config", {})
@ -105,9 +107,9 @@ async def test_ws_device_remove(
},
)
device_reg = dr.async_get(hass)
device_entry = device_reg.async_get_device(identifiers={("rfxtrx", *device_id)})
device_entry = device_registry.async_get_device(
identifiers={("rfxtrx", *device_id)}
)
assert device_entry
# Ask to remove existing device
@ -116,7 +118,9 @@ async def test_ws_device_remove(
assert response["success"]
# Verify device entry is removed
assert device_reg.async_get_device(identifiers={("rfxtrx", *device_id)}) is None
assert (
device_registry.async_get_device(identifiers={("rfxtrx", *device_id)}) is None
)
# Verify that the config entry has removed the device
assert mock_entry.data["devices"] == {}

View file

@ -18,11 +18,12 @@ from tests.common import load_fixture
async def test_entity_registry(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, Platform.CAMERA)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("camera.front")
assert entry.unique_id == "765432"

View file

@ -18,11 +18,12 @@ from tests.common import load_fixture
async def test_entity_registry(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, Platform.LIGHT)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("light.front_light")
assert entry.unique_id == "765432"

View file

@ -16,11 +16,12 @@ from .common import setup_platform
async def test_entity_registry(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, Platform.SIREN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("siren.downstairs_siren")
assert entry.unique_id == "123456-siren"

View file

@ -19,11 +19,12 @@ from tests.common import load_fixture
async def test_entity_registry(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, Platform.SWITCH)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("switch.front_siren")
assert entry.unique_id == "765432-siren"

View file

@ -143,30 +143,38 @@ def two_part_local_alarm():
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_login(
hass: HomeAssistant, login_with_error, cloud_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
login_with_error,
cloud_config_entry,
) -> None:
"""Test error on login."""
await hass.config_entries.async_setup(cloud_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_CLOUD_ENTITY_ID)
assert not registry.async_is_registered(SECOND_CLOUD_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_CLOUD_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_CLOUD_ENTITY_ID)
async def test_cloud_setup(
hass: HomeAssistant, two_part_cloud_alarm, setup_risco_cloud
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
two_part_cloud_alarm,
setup_risco_cloud,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
assert registry.async_is_registered(FIRST_CLOUD_ENTITY_ID)
assert registry.async_is_registered(SECOND_CLOUD_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_CLOUD_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_CLOUD_ENTITY_ID)
registry = dr.async_get(hass)
device = registry.async_get_device(identifiers={(DOMAIN, TEST_SITE_UUID + "_0")})
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_0")}
)
assert device is not None
assert device.manufacturer == "Risco"
device = registry.async_get_device(identifiers={(DOMAIN, TEST_SITE_UUID + "_1")})
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_1")}
)
assert device is not None
assert device.manufacturer == "Risco"
@ -274,11 +282,13 @@ async def _test_cloud_no_service_call(
@pytest.mark.parametrize("options", [CUSTOM_MAPPING_OPTIONS])
async def test_cloud_sets_custom_mapping(
hass: HomeAssistant, two_part_cloud_alarm, setup_risco_cloud
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_part_cloud_alarm,
setup_risco_cloud,
) -> None:
"""Test settings the various modes when mapping some states."""
registry = er.async_get(hass)
entity = registry.async_get(FIRST_CLOUD_ENTITY_ID)
entity = entity_registry.async_get(FIRST_CLOUD_ENTITY_ID)
assert entity.supported_features == EXPECTED_FEATURES
await _test_cloud_service_call(
@ -309,11 +319,13 @@ async def test_cloud_sets_custom_mapping(
@pytest.mark.parametrize("options", [FULL_CUSTOM_MAPPING])
async def test_cloud_sets_full_custom_mapping(
hass: HomeAssistant, two_part_cloud_alarm, setup_risco_cloud
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_part_cloud_alarm,
setup_risco_cloud,
) -> None:
"""Test settings the various modes when mapping all states."""
registry = er.async_get(hass)
entity = registry.async_get(FIRST_CLOUD_ENTITY_ID)
entity = entity_registry.async_get(FIRST_CLOUD_ENTITY_ID)
assert (
entity.supported_features
== EXPECTED_FEATURES | AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
@ -479,32 +491,36 @@ async def test_cloud_sets_with_incorrect_code(
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_connect(
hass: HomeAssistant, connect_with_error, local_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
connect_with_error,
local_config_entry,
) -> None:
"""Test error on connect."""
await hass.config_entries.async_setup(local_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_LOCAL_ENTITY_ID)
assert not registry.async_is_registered(SECOND_LOCAL_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_LOCAL_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_LOCAL_ENTITY_ID)
async def test_local_setup(
hass: HomeAssistant, two_part_local_alarm, setup_risco_local
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
two_part_local_alarm,
setup_risco_local,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
assert registry.async_is_registered(FIRST_LOCAL_ENTITY_ID)
assert registry.async_is_registered(SECOND_LOCAL_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_LOCAL_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_LOCAL_ENTITY_ID)
registry = dr.async_get(hass)
device = registry.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_0_local")}
)
assert device is not None
assert device.manufacturer == "Risco"
device = registry.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_1_local")}
)
assert device is not None
@ -630,11 +646,13 @@ async def _test_local_no_service_call(
@pytest.mark.parametrize("options", [CUSTOM_MAPPING_OPTIONS])
async def test_local_sets_custom_mapping(
hass: HomeAssistant, two_part_local_alarm, setup_risco_local
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_part_local_alarm,
setup_risco_local,
) -> None:
"""Test settings the various modes when mapping some states."""
registry = er.async_get(hass)
entity = registry.async_get(FIRST_LOCAL_ENTITY_ID)
entity = entity_registry.async_get(FIRST_LOCAL_ENTITY_ID)
assert entity.supported_features == EXPECTED_FEATURES
await _test_local_service_call(
@ -699,11 +717,13 @@ async def test_local_sets_custom_mapping(
@pytest.mark.parametrize("options", [FULL_CUSTOM_MAPPING])
async def test_local_sets_full_custom_mapping(
hass: HomeAssistant, two_part_local_alarm, setup_risco_local
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_part_local_alarm,
setup_risco_local,
) -> None:
"""Test settings the various modes when mapping all states."""
registry = er.async_get(hass)
entity = registry.async_get(FIRST_LOCAL_ENTITY_ID)
entity = entity_registry.async_get(FIRST_LOCAL_ENTITY_ID)
assert (
entity.supported_features
== EXPECTED_FEATURES | AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS

View file

@ -23,32 +23,36 @@ SECOND_ARMED_ENTITY_ID = SECOND_ENTITY_ID + "_armed"
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_login(
hass: HomeAssistant, login_with_error, cloud_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
login_with_error,
cloud_config_entry,
) -> None:
"""Test error on login."""
await hass.config_entries.async_setup(cloud_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_ENTITY_ID)
async def test_cloud_setup(
hass: HomeAssistant, two_zone_cloud, setup_risco_cloud
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
two_zone_cloud,
setup_risco_cloud,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
assert registry.async_is_registered(FIRST_ENTITY_ID)
assert registry.async_is_registered(SECOND_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_ENTITY_ID)
registry = dr.async_get(hass)
device = registry.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_zone_0")}
)
assert device is not None
assert device.manufacturer == "Risco"
device = registry.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_zone_1")}
)
assert device is not None
@ -81,42 +85,46 @@ async def test_cloud_states(
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_connect(
hass: HomeAssistant, connect_with_error, local_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
connect_with_error,
local_config_entry,
) -> None:
"""Test error on connect."""
await hass.config_entries.async_setup(local_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID)
assert not registry.async_is_registered(FIRST_ALARMED_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ALARMED_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_ALARMED_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_ALARMED_ENTITY_ID)
async def test_local_setup(
hass: HomeAssistant, two_zone_local, setup_risco_local
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
two_zone_local,
setup_risco_local,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
assert registry.async_is_registered(FIRST_ENTITY_ID)
assert registry.async_is_registered(SECOND_ENTITY_ID)
assert registry.async_is_registered(FIRST_ALARMED_ENTITY_ID)
assert registry.async_is_registered(SECOND_ALARMED_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_ALARMED_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_ALARMED_ENTITY_ID)
registry = dr.async_get(hass)
device = registry.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_zone_0_local")}
)
assert device is not None
assert device.manufacturer == "Risco"
device = registry.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, TEST_SITE_UUID + "_zone_1_local")}
)
assert device is not None
assert device.manufacturer == "Risco"
device = registry.async_get_device(identifiers={(DOMAIN, TEST_SITE_UUID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, TEST_SITE_UUID)})
assert device is not None
assert device.manufacturer == "Risco"

View file

@ -123,15 +123,17 @@ def _no_zones_and_partitions():
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_login(
hass: HomeAssistant, login_with_error, cloud_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
login_with_error,
cloud_config_entry,
) -> None:
"""Test error on login."""
await hass.config_entries.async_setup(cloud_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
for entity_id in ENTITY_IDS.values():
assert not registry.async_is_registered(entity_id)
assert not entity_registry.async_is_registered(entity_id)
def _check_state(hass, category, entity_id):
@ -174,15 +176,15 @@ def save_mock():
@pytest.mark.parametrize("events", [TEST_EVENTS])
async def test_cloud_setup(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_zone_cloud,
_set_utc_time_zone,
save_mock,
setup_risco_cloud,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
for entity_id in ENTITY_IDS.values():
assert registry.async_is_registered(entity_id)
assert entity_registry.async_is_registered(entity_id)
save_mock.assert_awaited_once_with({LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time})
for category, entity_id in ENTITY_IDS.items():
@ -206,9 +208,11 @@ async def test_cloud_setup(
async def test_local_setup(
hass: HomeAssistant, setup_risco_local, _no_zones_and_partitions
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
setup_risco_local,
_no_zones_and_partitions,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
for entity_id in ENTITY_IDS.values():
assert not registry.async_is_registered(entity_id)
assert not entity_registry.async_is_registered(entity_id)

View file

@ -17,23 +17,27 @@ SECOND_ENTITY_ID = "switch.zone_1_bypassed"
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_login(
hass: HomeAssistant, login_with_error, cloud_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
login_with_error,
cloud_config_entry,
) -> None:
"""Test error on login."""
await hass.config_entries.async_setup(cloud_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_ENTITY_ID)
async def test_cloud_setup(
hass: HomeAssistant, two_zone_cloud, setup_risco_cloud
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_zone_cloud,
setup_risco_cloud,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
assert registry.async_is_registered(FIRST_ENTITY_ID)
assert registry.async_is_registered(SECOND_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_ENTITY_ID)
async def _check_cloud_state(hass, zones, bypassed, entity_id, zone_id):
@ -90,23 +94,27 @@ async def test_cloud_unbypass(
@pytest.mark.parametrize("exception", [CannotConnectError, UnauthorizedError])
async def test_error_on_connect(
hass: HomeAssistant, connect_with_error, local_config_entry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
connect_with_error,
local_config_entry,
) -> None:
"""Test error on connect."""
await hass.config_entries.async_setup(local_config_entry.entry_id)
await hass.async_block_till_done()
registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID)
assert not entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert not entity_registry.async_is_registered(SECOND_ENTITY_ID)
async def test_local_setup(
hass: HomeAssistant, two_zone_local, setup_risco_local
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
two_zone_local,
setup_risco_local,
) -> None:
"""Test entity setup."""
registry = er.async_get(hass)
assert registry.async_is_registered(FIRST_ENTITY_ID)
assert registry.async_is_registered(SECOND_ENTITY_ID)
assert entity_registry.async_is_registered(FIRST_ENTITY_ID)
assert entity_registry.async_is_registered(SECOND_ENTITY_ID)
async def _check_local_state(hass, zones, bypassed, entity_id, zone_id, callback):

View file

@ -35,10 +35,12 @@ DEVICE_ID = "abc123"
async def test_registry_entries(
hass: HomeAssistant, bypass_api_fixture, setup_entry: MockConfigEntry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
bypass_api_fixture,
setup_entry: MockConfigEntry,
) -> None:
"""Tests devices are registered in the entity registry."""
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(ENTITY_ID)
assert entry.unique_id == DEVICE_ID

View file

@ -17,12 +17,12 @@ from tests.common import MockConfigEntry
async def test_roku_binary_sensors(
hass: HomeAssistant, init_integration: MockConfigEntry
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the Roku binary sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("binary_sensor.my_roku_3_headphones_connected")
entry = entity_registry.async_get("binary_sensor.my_roku_3_headphones_connected")
assert entry
@ -83,14 +83,13 @@ async def test_roku_binary_sensors(
@pytest.mark.parametrize("mock_device", ["roku/rokutv-7820x.json"], indirect=True)
async def test_rokutv_binary_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
mock_device: RokuDevice,
mock_roku: MagicMock,
) -> None:
"""Test the Roku binary sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("binary_sensor.58_onn_roku_tv_headphones_connected")
entry = entity_registry.async_get(
"binary_sensor.58_onn_roku_tv_headphones_connected"

View file

@ -70,11 +70,13 @@ MAIN_ENTITY_ID = f"{MP_DOMAIN}.my_roku_3"
TV_ENTITY_ID = f"{MP_DOMAIN}.58_onn_roku_tv"
async def test_setup(hass: HomeAssistant, init_integration: MockConfigEntry) -> None:
async def test_setup(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test setup with basic config."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get(MAIN_ENTITY_ID)
entry = entity_registry.async_get(MAIN_ENTITY_ID)
@ -115,13 +117,12 @@ async def test_idle_setup(
@pytest.mark.parametrize("mock_device", ["roku/rokutv-7820x.json"], indirect=True)
async def test_tv_setup(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
mock_roku: MagicMock,
) -> None:
"""Test Roku TV setup."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get(TV_ENTITY_ID)
entry = entity_registry.async_get(TV_ENTITY_ID)

View file

@ -24,11 +24,11 @@ async def test_setup(hass: HomeAssistant, init_integration: MockConfigEntry) ->
async def test_unique_id(
hass: HomeAssistant, init_integration: MockConfigEntry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test unique id."""
entity_registry = er.async_get(hass)
main = entity_registry.async_get(MAIN_ENTITY_ID)
assert main.unique_id == UPNP_SERIAL

View file

@ -29,13 +29,12 @@ from tests.common import MockConfigEntry, async_fire_time_changed
async def test_application_state(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_device: RokuDevice,
mock_roku: MagicMock,
) -> None:
"""Test the creation and values of the Roku selects."""
entity_registry = er.async_get(hass)
entity_registry.async_get_or_create(
SELECT_DOMAIN,
DOMAIN,
@ -122,14 +121,13 @@ async def test_application_state(
)
async def test_application_select_error(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_roku: MagicMock,
error: RokuError,
error_string: str,
) -> None:
"""Test error handling of the Roku selects."""
entity_registry = er.async_get(hass)
entity_registry.async_get_or_create(
SELECT_DOMAIN,
DOMAIN,
@ -165,13 +163,12 @@ async def test_application_select_error(
@pytest.mark.parametrize("mock_device", ["roku/rokutv-7820x.json"], indirect=True)
async def test_channel_state(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
mock_device: RokuDevice,
mock_roku: MagicMock,
) -> None:
"""Test the creation and values of the Roku selects."""
entity_registry = er.async_get(hass)
state = hass.states.get("select.58_onn_roku_tv_channel")
assert state
assert state.attributes.get(ATTR_OPTIONS) == [

View file

@ -21,12 +21,11 @@ from tests.common import MockConfigEntry
async def test_roku_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the Roku sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.my_roku_3_active_app")
entry = entity_registry.async_get("sensor.my_roku_3_active_app")
assert entry
@ -67,13 +66,12 @@ async def test_roku_sensors(
@pytest.mark.parametrize("mock_device", ["roku/rokutv-7820x.json"], indirect=True)
async def test_rokutv_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
mock_roku: MagicMock,
) -> None:
"""Test the Roku TV sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.58_onn_roku_tv_active_app")
entry = entity_registry.async_get("sensor.58_onn_roku_tv_active_app")
assert entry

View file

@ -84,13 +84,14 @@ async def test_clients_update_auth_failed(hass: HomeAssistant) -> None:
assert test_client.state == STATE_UNAVAILABLE
async def test_restoring_clients(hass: HomeAssistant) -> None:
async def test_restoring_clients(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test restoring existing device_tracker entities if not detected on startup."""
entry = mock_config_entry()
entry.add_to_hass(hass)
registry = er.async_get(hass)
registry.async_get_or_create(
entity_registry.async_get_or_create(
"device_tracker",
DOMAIN,
DEFAULT_UNIQUEID,

View file

@ -53,13 +53,14 @@ async def test_setup_entry_connection_error(hass: HomeAssistant) -> None:
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_router_device_setup(hass: HomeAssistant) -> None:
async def test_router_device_setup(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test a router device is created."""
await init_integration(hass)
device_info = DEFAULT_AP_INFO[0]
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={(CONNECTION_NETWORK_MAC, device_info[API_AP_MAC])},
connections={(CONNECTION_NETWORK_MAC, device_info[API_AP_MAC])},