Use registry fixtures in tests (t-u) (#118297)

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

View file

@ -483,6 +483,7 @@ TEMPERATURE_SENSOR_CONFIG = {
)
async def test_controlling_state_via_mqtt(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
sensor_config,
@ -491,7 +492,6 @@ async def test_controlling_state_via_mqtt(
states,
) -> None:
"""Test state update via MQTT."""
entity_reg = er.async_get(hass)
config = copy.deepcopy(DEFAULT_CONFIG)
sensor_config = copy.deepcopy(sensor_config)
mac = config["mac"]
@ -514,7 +514,7 @@ async def test_controlling_state_via_mqtt(
assert state.state == "unavailable"
assert not state.attributes.get(ATTR_ASSUMED_STATE)
entry = entity_reg.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry.disabled is False
assert entry.disabled_by is None
assert entry.entity_category is None
@ -588,6 +588,7 @@ async def test_controlling_state_via_mqtt(
)
async def test_quantity_override(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
sensor_config,
@ -595,7 +596,6 @@ async def test_quantity_override(
states,
) -> None:
"""Test quantity override for certain sensors."""
entity_reg = er.async_get(hass)
config = copy.deepcopy(DEFAULT_CONFIG)
sensor_config = copy.deepcopy(sensor_config)
mac = config["mac"]
@ -620,7 +620,7 @@ async def test_quantity_override(
for attribute, expected in expected_state.get("attributes", {}).items():
assert state.attributes.get(attribute) == expected
entry = entity_reg.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry.disabled is False
assert entry.disabled_by is None
assert entry.entity_category is None
@ -742,13 +742,14 @@ async def test_bad_indexed_sensor_state_via_mqtt(
@pytest.mark.parametrize("status_sensor_disabled", [False])
async def test_status_sensor_state_via_mqtt(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
) -> None:
"""Test state update via MQTT."""
entity_reg = er.async_get(hass)
# Pre-enable the status sensor
entity_reg.async_get_or_create(
entity_registry.async_get_or_create(
Platform.SENSOR,
"tasmota",
"00000049A3BC_status_sensor_status_sensor_status_signal",
@ -856,13 +857,14 @@ async def test_battery_sensor_state_via_mqtt(
@pytest.mark.parametrize("status_sensor_disabled", [False])
async def test_single_shot_status_sensor_state_via_mqtt(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
) -> None:
"""Test state update via MQTT."""
entity_reg = er.async_get(hass)
# Pre-enable the status sensor
entity_reg.async_get_or_create(
entity_registry.async_get_or_create(
Platform.SENSOR,
"tasmota",
"00000049A3BC_status_sensor_status_sensor_status_restart_reason",
@ -941,13 +943,15 @@ async def test_single_shot_status_sensor_state_via_mqtt(
@pytest.mark.parametrize("status_sensor_disabled", [False])
@patch.object(hatasmota.status_sensor, "datetime", Mock(wraps=datetime.datetime))
async def test_restart_time_status_sensor_state_via_mqtt(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
) -> None:
"""Test state update via MQTT."""
entity_reg = er.async_get(hass)
# Pre-enable the status sensor
entity_reg.async_get_or_create(
entity_registry.async_get_or_create(
Platform.SENSOR,
"tasmota",
"00000049A3BC_status_sensor_status_sensor_last_restart_time",
@ -1119,6 +1123,7 @@ async def test_indexed_sensor_attributes(
)
async def test_diagnostic_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
sensor_name,
@ -1126,8 +1131,6 @@ async def test_diagnostic_sensors(
disabled_by,
) -> None:
"""Test properties of diagnostic sensors."""
entity_reg = er.async_get(hass)
config = copy.deepcopy(DEFAULT_CONFIG)
mac = config["mac"]
@ -1141,7 +1144,7 @@ async def test_diagnostic_sensors(
state = hass.states.get(f"sensor.{sensor_name}")
assert bool(state) != disabled
entry = entity_reg.async_get(f"sensor.{sensor_name}")
entry = entity_registry.async_get(f"sensor.{sensor_name}")
assert entry.disabled == disabled
assert entry.disabled_by is disabled_by
assert entry.entity_category == "diagnostic"
@ -1149,11 +1152,12 @@ async def test_diagnostic_sensors(
@pytest.mark.parametrize("status_sensor_disabled", [False])
async def test_enable_status_sensor(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
) -> None:
"""Test enabling status sensor."""
entity_reg = er.async_get(hass)
config = copy.deepcopy(DEFAULT_CONFIG)
mac = config["mac"]
@ -1167,12 +1171,12 @@ async def test_enable_status_sensor(
state = hass.states.get("sensor.tasmota_signal")
assert state is None
entry = entity_reg.async_get("sensor.tasmota_signal")
entry = entity_registry.async_get("sensor.tasmota_signal")
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
# Enable the signal level status sensor
updated_entry = entity_reg.async_update_entity(
updated_entry = entity_registry.async_update_entity(
"sensor.tasmota_signal", disabled_by=None
)
assert updated_entry != entry

View file

@ -591,11 +591,12 @@ async def test_sensor_no_lower_upper(
assert "Lower or Upper thresholds not provided" in caplog.text
async def test_device_id(hass: HomeAssistant) -> None:
async def test_device_id(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test for source entity device for Threshold."""
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
source_config_entry = MockConfigEntry()
source_config_entry.add_to_hass(hass)
source_device_entry = device_registry.async_get_or_create(

View file

@ -12,6 +12,7 @@ from tests.common import MockConfigEntry
@pytest.mark.parametrize("platform", ["binary_sensor"])
async def test_setup_and_remove_config_entry(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
platform: str,
) -> None:
"""Test setting up and removing a config entry."""
@ -19,7 +20,6 @@ async def test_setup_and_remove_config_entry(
input_sensor = "sensor.input"
registry = er.async_get(hass)
threshold_entity_id = f"{platform}.input_threshold"
# Setup the config entry
@ -40,7 +40,7 @@ async def test_setup_and_remove_config_entry(
await hass.async_block_till_done()
# Check the entity is registered in the entity registry
assert registry.async_get(threshold_entity_id) is not None
assert entity_registry.async_get(threshold_entity_id) is not None
# Check the platform is setup correctly
state = hass.states.get(threshold_entity_id)
@ -59,4 +59,4 @@ async def test_setup_and_remove_config_entry(
# Check the state and entity registry entry are removed
assert hass.states.get(threshold_entity_id) is None
assert registry.async_get(threshold_entity_id) is None
assert entity_registry.async_get(threshold_entity_id) is None

View file

@ -476,11 +476,13 @@ async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> Non
async def test_config_reload(
hass: HomeAssistant, hass_admin_user: MockUser, hass_read_only_user: MockUser
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
hass_admin_user: MockUser,
hass_read_only_user: MockUser,
) -> None:
"""Test reload service."""
count_start = len(hass.states.async_entity_ids())
ent_reg = er.async_get(hass)
_LOGGER.debug("ENTITIES @ start: %s", hass.states.async_entity_ids())
@ -508,9 +510,9 @@ async def test_config_reload(
assert state_1 is not None
assert state_2 is not None
assert state_3 is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "test_1") is not None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "test_2") is not None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "test_3") is None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "test_1") is not None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "test_2") is not None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "test_3") is None
assert state_1.state == STATUS_IDLE
assert ATTR_ICON not in state_1.attributes
@ -559,9 +561,9 @@ async def test_config_reload(
assert state_1 is None
assert state_2 is not None
assert state_3 is not None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "test_1") is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "test_2") is not None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, "test_3") is not None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "test_1") is None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "test_2") is not None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, "test_3") is not None
assert state_2.state == STATUS_IDLE
assert state_2.attributes.get(ATTR_FRIENDLY_NAME) == "Hello World reloaded"
@ -729,18 +731,20 @@ async def test_ws_list(
async def test_ws_delete(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
hass_ws_client: WebSocketGenerator,
storage_setup,
) -> None:
"""Test WS delete cleans up entity registry."""
assert await storage_setup()
timer_id = "from_storage"
timer_entity_id = f"{DOMAIN}.{DOMAIN}_{timer_id}"
ent_reg = er.async_get(hass)
state = hass.states.get(timer_entity_id)
assert state is not None
from_reg = ent_reg.async_get_entity_id(DOMAIN, DOMAIN, timer_id)
from_reg = entity_registry.async_get_entity_id(DOMAIN, DOMAIN, timer_id)
assert from_reg == timer_entity_id
client = await hass_ws_client(hass)
@ -753,11 +757,14 @@ async def test_ws_delete(
state = hass.states.get(timer_entity_id)
assert state is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, timer_id) is None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, timer_id) is None
async def test_update(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
hass_ws_client: WebSocketGenerator,
storage_setup,
) -> None:
"""Test updating timer entity."""
@ -765,11 +772,12 @@ async def test_update(
timer_id = "from_storage"
timer_entity_id = f"{DOMAIN}.{DOMAIN}_{timer_id}"
ent_reg = er.async_get(hass)
state = hass.states.get(timer_entity_id)
assert state.attributes[ATTR_FRIENDLY_NAME] == "timer from storage"
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, timer_id) == timer_entity_id
assert (
entity_registry.async_get_entity_id(DOMAIN, DOMAIN, timer_id) == timer_entity_id
)
client = await hass_ws_client(hass)
@ -801,18 +809,20 @@ async def test_update(
async def test_ws_create(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
hass_ws_client: WebSocketGenerator,
storage_setup,
) -> None:
"""Test create WS."""
assert await storage_setup(items=[])
timer_id = "new_timer"
timer_entity_id = f"{DOMAIN}.{timer_id}"
ent_reg = er.async_get(hass)
state = hass.states.get(timer_entity_id)
assert state is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, timer_id) is None
assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, timer_id) is None
client = await hass_ws_client(hass)
@ -830,7 +840,9 @@ async def test_ws_create(
state = hass.states.get(timer_entity_id)
assert state.state == STATUS_IDLE
assert state.attributes[ATTR_DURATION] == _format_timedelta(cv.time_period(42))
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, timer_id) == timer_entity_id
assert (
entity_registry.async_get_entity_id(DOMAIN, DOMAIN, timer_id) == timer_entity_id
)
async def test_setup_no_config(hass: HomeAssistant, hass_admin_user: MockUser) -> None:

View file

@ -1004,7 +1004,9 @@ async def test_simple_before_after_does_not_loop_berlin_in_range(
assert state.attributes["next_update"] == "2019-01-11T06:00:00+01:00"
async def test_unique_id(hass: HomeAssistant) -> None:
async def test_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test unique id."""
config = {
"binary_sensor": [
@ -1020,7 +1022,6 @@ async def test_unique_id(hass: HomeAssistant) -> None:
await async_setup_component(hass, "binary_sensor", config)
await hass.async_block_till_done()
entity_reg = er.async_get(hass)
entity = entity_reg.async_get("binary_sensor.evening")
entity = entity_registry.async_get("binary_sensor.evening")
assert entity.unique_id == "very_unique_id"

View file

@ -10,9 +10,10 @@ from tests.common import MockConfigEntry
@pytest.mark.freeze_time("2022-03-16 17:37:00", tz_offset=-7)
async def test_setup_and_remove_config_entry(hass: HomeAssistant) -> None:
async def test_setup_and_remove_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test setting up and removing a config entry."""
registry = er.async_get(hass)
tod_entity_id = "binary_sensor.my_tod"
# Setup the config entry
@ -31,7 +32,7 @@ async def test_setup_and_remove_config_entry(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
# Check the entity is registered in the entity registry
assert registry.async_get(tod_entity_id) is not None
assert entity_registry.async_get(tod_entity_id) is not None
# Check the platform is setup correctly
state = hass.states.get(tod_entity_id)
@ -47,4 +48,4 @@ async def test_setup_and_remove_config_entry(hass: HomeAssistant) -> None:
# Check the state and entity registry entry are removed
assert hass.states.get(tod_entity_id) is None
assert registry.async_get(tod_entity_id) is None
assert entity_registry.async_get(tod_entity_id) is None

View file

@ -116,22 +116,24 @@ async def _setup_legacy(hass: HomeAssistant, config: dict[str, Any]) -> State:
return hass.states.get("weather.tomorrow_io_daily")
async def test_new_config_entry(hass: HomeAssistant) -> None:
async def test_new_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test the expected entities are created."""
registry = er.async_get(hass)
await _setup(hass, API_V4_ENTRY_DATA)
assert len(hass.states.async_entity_ids("weather")) == 1
entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 28
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 28
async def test_legacy_config_entry(hass: HomeAssistant) -> None:
async def test_legacy_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test the expected entities are created."""
registry = er.async_get(hass)
data = _get_config_schema(hass, SOURCE_USER)(API_V4_ENTRY_DATA)
for entity_name in ("hourly", "nowcast"):
registry.async_get_or_create(
entity_registry.async_get_or_create(
WEATHER_DOMAIN,
DOMAIN,
f"{_get_unique_id(hass, data)}_{entity_name}",
@ -140,7 +142,7 @@ async def test_legacy_config_entry(hass: HomeAssistant) -> None:
assert len(hass.states.async_entity_ids("weather")) == 3
entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 30
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 30
async def test_v4_weather(hass: HomeAssistant, tomorrowio_config_entry_update) -> None:

View file

@ -45,7 +45,9 @@ from . import (
from tests.common import MockConfigEntry, async_fire_time_changed
async def test_light_unique_id(hass: HomeAssistant) -> None:
async def test_light_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test a light unique id."""
already_migrated_config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "127.0.0.1"}, unique_id=MAC_ADDRESS
@ -58,7 +60,6 @@ async def test_light_unique_id(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
entity_id = "light.my_bulb"
entity_registry = er.async_get(hass)
assert entity_registry.async_get(entity_id).unique_id == "AABBCCDDEEFF"

View file

@ -118,7 +118,9 @@ async def test_color_light_no_emeter(hass: HomeAssistant) -> None:
assert hass.states.get(sensor_entity_id) is None
async def test_sensor_unique_id(hass: HomeAssistant) -> None:
async def test_sensor_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test a sensor unique ids."""
already_migrated_config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "127.0.0.1"}, unique_id=MAC_ADDRESS
@ -145,6 +147,5 @@ async def test_sensor_unique_id(hass: HomeAssistant) -> None:
"sensor.my_plug_voltage": "aa:bb:cc:dd:ee:ff_voltage",
"sensor.my_plug_current": "aa:bb:cc:dd:ee:ff_current_a",
}
entity_registry = er.async_get(hass)
for sensor_entity_id, value in expected.items():
assert entity_registry.async_get(sensor_entity_id).unique_id == value

View file

@ -101,7 +101,9 @@ async def test_led_switch(hass: HomeAssistant, dev, domain: str) -> None:
dev.set_led.reset_mock()
async def test_plug_unique_id(hass: HomeAssistant) -> None:
async def test_plug_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test a plug unique id."""
already_migrated_config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "127.0.0.1"}, unique_id=MAC_ADDRESS
@ -113,7 +115,6 @@ async def test_plug_unique_id(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
entity_id = "switch.my_plug"
entity_registry = er.async_get(hass)
assert entity_registry.async_get(entity_id).unique_id == "aa:bb:cc:dd:ee:ff"
@ -187,7 +188,9 @@ async def test_strip(hass: HomeAssistant) -> None:
strip.children[1].turn_on.reset_mock()
async def test_strip_unique_ids(hass: HomeAssistant) -> None:
async def test_strip_unique_ids(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test a strip unique id."""
already_migrated_config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "127.0.0.1"}, unique_id=MAC_ADDRESS
@ -200,7 +203,6 @@ async def test_strip_unique_ids(hass: HomeAssistant) -> None:
for plug_id in range(2):
entity_id = f"switch.my_strip_plug{plug_id}"
entity_registry = er.async_get(hass)
assert (
entity_registry.async_get(entity_id).unique_id == f"PLUG{plug_id}DEVICEID"
)

View file

@ -100,7 +100,13 @@ async def test_missing_data(hass: HomeAssistant, client, webhook_id) -> None:
assert req.status == HTTPStatus.UNPROCESSABLE_ENTITY
async def test_enter_and_exit(hass: HomeAssistant, client, webhook_id) -> None:
async def test_enter_and_exit(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
client,
webhook_id,
) -> None:
"""Test when there is a known zone."""
url = f"/api/webhook/{webhook_id}"
data = {"lat": str(HOME_LATITUDE), "lon": str(HOME_LONGITUDE), "id": "123"}
@ -135,11 +141,9 @@ async def test_enter_and_exit(hass: HomeAssistant, client, webhook_id) -> None:
).state
assert state_name == STATE_NOT_HOME
dev_reg = dr.async_get(hass)
assert len(dev_reg.devices) == 1
assert len(device_registry.devices) == 1
ent_reg = er.async_get(hass)
assert len(ent_reg.entities) == 1
assert len(entity_registry.entities) == 1
async def test_enter_with_attrs(hass: HomeAssistant, client, webhook_id) -> None:

View file

@ -9,10 +9,11 @@ from tests.components.trend.conftest import ComponentSetup
async def test_setup_and_remove_config_entry(
hass: HomeAssistant, config_entry: MockConfigEntry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
config_entry: MockConfigEntry,
) -> None:
"""Test setting up and removing a config entry."""
registry = er.async_get(hass)
trend_entity_id = "binary_sensor.my_trend"
# Set up the config entry
@ -21,7 +22,7 @@ async def test_setup_and_remove_config_entry(
await hass.async_block_till_done()
# Check the entity is registered in the entity registry
assert registry.async_get(trend_entity_id) is not None
assert entity_registry.async_get(trend_entity_id) is not None
# Remove the config entry
assert await hass.config_entries.async_remove(config_entry.entry_id)
@ -29,7 +30,7 @@ async def test_setup_and_remove_config_entry(
# Check the state and entity registry entry are removed
assert hass.states.get(trend_entity_id) is None
assert registry.async_get(trend_entity_id) is None
assert entity_registry.async_get(trend_entity_id) is None
async def test_reload_config_entry(

View file

@ -86,15 +86,16 @@ async def test_binary_sensor_sensor_remove(
async def test_binary_sensor_setup_light(
hass: HomeAssistant, ufp: MockUFPFixture, light: Light
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
light: Light,
) -> None:
"""Test binary_sensor entity setup for light devices."""
await init_entry(hass, ufp, [light])
assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8)
entity_registry = er.async_get(hass)
for description in LIGHT_SENSOR_WRITE:
unique_id, entity_id = ids_from_device_description(
Platform.BINARY_SENSOR, light, description
@ -112,6 +113,7 @@ async def test_binary_sensor_setup_light(
async def test_binary_sensor_setup_camera_all(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
unadopted_camera: Camera,
@ -122,8 +124,6 @@ async def test_binary_sensor_setup_camera_all(
await init_entry(hass, ufp, [doorbell, unadopted_camera])
assert_entity_counts(hass, Platform.BINARY_SENSOR, 7, 7)
entity_registry = er.async_get(hass)
description = EVENT_SENSORS[0]
unique_id, entity_id = ids_from_device_description(
Platform.BINARY_SENSOR, doorbell, description
@ -170,7 +170,10 @@ async def test_binary_sensor_setup_camera_all(
async def test_binary_sensor_setup_camera_none(
hass: HomeAssistant, ufp: MockUFPFixture, camera: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
camera: Camera,
) -> None:
"""Test binary_sensor entity setup for camera devices (no features)."""
@ -178,7 +181,6 @@ async def test_binary_sensor_setup_camera_none(
await init_entry(hass, ufp, [camera])
assert_entity_counts(hass, Platform.BINARY_SENSOR, 2, 2)
entity_registry = er.async_get(hass)
description = CAMERA_SENSORS[0]
unique_id, entity_id = ids_from_device_description(
@ -196,15 +198,16 @@ async def test_binary_sensor_setup_camera_none(
async def test_binary_sensor_setup_sensor(
hass: HomeAssistant, ufp: MockUFPFixture, sensor_all: Sensor
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
sensor_all: Sensor,
) -> None:
"""Test binary_sensor entity setup for sensor devices."""
await init_entry(hass, ufp, [sensor_all])
assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11)
entity_registry = er.async_get(hass)
expected = [
STATE_OFF,
STATE_UNAVAILABLE,
@ -228,7 +231,10 @@ async def test_binary_sensor_setup_sensor(
async def test_binary_sensor_setup_sensor_leak(
hass: HomeAssistant, ufp: MockUFPFixture, sensor: Sensor
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
sensor: Sensor,
) -> None:
"""Test binary_sensor entity setup for sensor with most leak mounting type."""
@ -236,8 +242,6 @@ async def test_binary_sensor_setup_sensor_leak(
await init_entry(hass, ufp, [sensor])
assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11)
entity_registry = er.async_get(hass)
expected = [
STATE_UNAVAILABLE,
STATE_OFF,

View file

@ -36,6 +36,7 @@ async def test_button_chime_remove(
async def test_reboot_button(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
chime: Chime,
) -> None:
@ -49,7 +50,6 @@ async def test_reboot_button(
unique_id = f"{chime.mac}_reboot"
entity_id = "button.test_chime_reboot_device"
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity
assert entity.disabled
@ -68,6 +68,7 @@ async def test_reboot_button(
async def test_chime_button(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
chime: Chime,
) -> None:
@ -81,7 +82,6 @@ async def test_chime_button(
unique_id = f"{chime.mac}_play"
entity_id = "button.test_chime_play_chime"
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity
assert not entity.disabled
@ -98,7 +98,11 @@ async def test_chime_button(
async def test_adopt_button(
hass: HomeAssistant, ufp: MockUFPFixture, doorlock: Doorlock, doorbell: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorlock: Doorlock,
doorbell: Camera,
) -> None:
"""Test button entity."""
@ -122,7 +126,6 @@ async def test_adopt_button(
unique_id = f"{doorlock.mac}_adopt"
entity_id = "button.test_lock_adopt_device"
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity
assert not entity.disabled
@ -139,12 +142,15 @@ async def test_adopt_button(
async def test_adopt_button_removed(
hass: HomeAssistant, ufp: MockUFPFixture, doorlock: Doorlock, doorbell: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorlock: Doorlock,
doorbell: Camera,
) -> None:
"""Test button entity."""
entity_id = "button.test_lock_adopt_device"
entity_registry = er.async_get(hass)
doorlock._api = ufp.api
doorlock.is_adopted = False

View file

@ -241,6 +241,8 @@ async def test_setup_starts_discovery(
async def test_device_remove_devices(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
light: Light,
hass_ws_client: WebSocketGenerator,
@ -252,10 +254,8 @@ async def test_device_remove_devices(
entity_id = "light.test_light"
entry_id = ufp.entry.entry_id
registry: er.EntityRegistry = er.async_get(hass)
entity = registry.async_get(entity_id)
entity = entity_registry.async_get(entity_id)
assert entity is not None
device_registry = dr.async_get(hass)
live_device_entry = device_registry.async_get(entity.device_id)
client = await hass_ws_client(hass)
@ -272,6 +272,7 @@ async def test_device_remove_devices(
async def test_device_remove_devices_nvr(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
ufp: MockUFPFixture,
hass_ws_client: WebSocketGenerator,
) -> None:
@ -283,8 +284,6 @@ async def test_device_remove_devices_nvr(
await hass.async_block_till_done()
entry_id = ufp.entry.entry_id
device_registry = dr.async_get(hass)
live_device_entry = list(device_registry.devices.values())[0]
client = await hass_ws_client(hass)
response = await client.remove_device(live_device_entry.id, entry_id)

View file

@ -42,7 +42,11 @@ async def test_light_remove(
async def test_light_setup(
hass: HomeAssistant, ufp: MockUFPFixture, light: Light, unadopted_light: Light
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
light: Light,
unadopted_light: Light,
) -> None:
"""Test light entity setup."""
@ -52,7 +56,6 @@ async def test_light_setup(
unique_id = light.mac
entity_id = "light.test_light"
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity
assert entity.unique_id == unique_id

View file

@ -45,6 +45,7 @@ async def test_lock_remove(
async def test_lock_setup(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorlock: Doorlock,
unadopted_doorlock: Doorlock,
@ -57,7 +58,6 @@ async def test_lock_setup(
unique_id = f"{doorlock.mac}_lock"
entity_id = "lock.test_lock_lock"
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity
assert entity.unique_id == unique_id

View file

@ -49,6 +49,7 @@ async def test_media_player_camera_remove(
async def test_media_player_setup(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
unadopted_camera: Camera,
@ -61,7 +62,6 @@ async def test_media_player_setup(
unique_id = f"{doorbell.mac}_speaker"
entity_id = "media_player.test_camera_speaker"
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity
assert entity.unique_id == unique_id

View file

@ -344,7 +344,11 @@ async def test_browse_media_root_single_console(
async def test_browse_media_camera(
hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera, camera: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
camera: Camera,
) -> None:
"""Test browsing camera selector level media."""
@ -360,7 +364,6 @@ async def test_browse_media_camera(
),
]
entity_registry = er.async_get(hass)
entity_registry.async_update_entity(
"camera.test_camera_high_resolution_channel",
disabled_by=er.RegistryEntryDisabler("user"),

View file

@ -44,12 +44,14 @@ async def test_deprecated_entity(
async def test_deprecated_entity_no_automations(
hass: HomeAssistant, ufp: MockUFPFixture, hass_ws_client, doorbell: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
hass_ws_client,
doorbell: Camera,
):
"""Test Deprecate entity repair exists for existing installs."""
registry = er.async_get(hass)
registry.async_get_or_create(
entity_registry.async_get_or_create(
Platform.SWITCH,
DOMAIN,
f"{doorbell.mac}_hdr_mode",
@ -107,14 +109,13 @@ async def _load_automation(hass: HomeAssistant, entity_id: str):
async def test_deprecate_entity_automation(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
hass_ws_client: WebSocketGenerator,
doorbell: Camera,
) -> None:
"""Test Deprecate entity repair exists for existing installs."""
registry = er.async_get(hass)
entry = registry.async_get_or_create(
entry = entity_registry.async_get_or_create(
Platform.SWITCH,
DOMAIN,
f"{doorbell.mac}_hdr_mode",
@ -176,14 +177,13 @@ async def _load_script(hass: HomeAssistant, entity_id: str):
async def test_deprecate_entity_script(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
hass_ws_client: WebSocketGenerator,
doorbell: Camera,
) -> None:
"""Test Deprecate entity repair exists for existing installs."""
registry = er.async_get(hass)
entry = registry.async_get_or_create(
entry = entity_registry.async_get_or_create(
Platform.SWITCH,
DOMAIN,
f"{doorbell.mac}_hdr_mode",

View file

@ -69,14 +69,16 @@ async def test_number_lock_remove(
async def test_number_setup_light(
hass: HomeAssistant, ufp: MockUFPFixture, light: Light
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
light: Light,
) -> None:
"""Test number entity setup for light devices."""
await init_entry(hass, ufp, [light])
assert_entity_counts(hass, Platform.NUMBER, 2, 2)
entity_registry = er.async_get(hass)
for description in LIGHT_NUMBERS:
unique_id, entity_id = ids_from_device_description(
Platform.NUMBER, light, description
@ -93,7 +95,10 @@ async def test_number_setup_light(
async def test_number_setup_camera_all(
hass: HomeAssistant, ufp: MockUFPFixture, camera: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
camera: Camera,
) -> None:
"""Test number entity setup for camera devices (all features)."""
@ -105,8 +110,6 @@ async def test_number_setup_camera_all(
await init_entry(hass, ufp, [camera])
assert_entity_counts(hass, Platform.NUMBER, 5, 5)
entity_registry = er.async_get(hass)
for description in CAMERA_NUMBERS:
unique_id, entity_id = ids_from_device_description(
Platform.NUMBER, camera, description

View file

@ -84,7 +84,10 @@ async def test_select_viewer_remove(
async def test_select_setup_light(
hass: HomeAssistant, ufp: MockUFPFixture, light: Light
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
light: Light,
) -> None:
"""Test select entity setup for light devices."""
@ -92,7 +95,6 @@ async def test_select_setup_light(
await init_entry(hass, ufp, [light])
assert_entity_counts(hass, Platform.SELECT, 2, 2)
entity_registry = er.async_get(hass)
expected_values = ("On Motion - When Dark", "Not Paired")
for index, description in enumerate(LIGHT_SELECTS):
@ -111,7 +113,11 @@ async def test_select_setup_light(
async def test_select_setup_viewer(
hass: HomeAssistant, ufp: MockUFPFixture, viewer: Viewer, liveview: Liveview
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
viewer: Viewer,
liveview: Liveview,
) -> None:
"""Test select entity setup for light devices."""
@ -119,7 +125,6 @@ async def test_select_setup_viewer(
await init_entry(hass, ufp, [viewer])
assert_entity_counts(hass, Platform.SELECT, 1, 1)
entity_registry = er.async_get(hass)
description = VIEWER_SELECTS[0]
unique_id, entity_id = ids_from_device_description(
@ -137,14 +142,16 @@ async def test_select_setup_viewer(
async def test_select_setup_camera_all(
hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
) -> None:
"""Test select entity setup for camera devices (all features)."""
await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SELECT, 5, 5)
entity_registry = er.async_get(hass)
expected_values = (
"Always",
"Auto",
@ -169,14 +176,16 @@ async def test_select_setup_camera_all(
async def test_select_setup_camera_none(
hass: HomeAssistant, ufp: MockUFPFixture, camera: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
camera: Camera,
) -> None:
"""Test select entity setup for camera devices (no features)."""
await init_entry(hass, ufp, [camera])
assert_entity_counts(hass, Platform.SELECT, 2, 2)
entity_registry = er.async_get(hass)
expected_values = ("Always", "Auto", "Default Message (Welcome)")
for index, description in enumerate(CAMERA_SELECTS):

View file

@ -80,15 +80,16 @@ async def test_sensor_sensor_remove(
async def test_sensor_setup_sensor(
hass: HomeAssistant, ufp: MockUFPFixture, sensor_all: Sensor
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
sensor_all: Sensor,
) -> None:
"""Test sensor entity setup for sensor devices."""
await init_entry(hass, ufp, [sensor_all])
assert_entity_counts(hass, Platform.SENSOR, 22, 14)
entity_registry = er.async_get(hass)
expected_values = (
"10",
"10.0",
@ -131,15 +132,16 @@ async def test_sensor_setup_sensor(
async def test_sensor_setup_sensor_none(
hass: HomeAssistant, ufp: MockUFPFixture, sensor: Sensor
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
sensor: Sensor,
) -> None:
"""Test sensor entity setup for sensor devices with no sensors enabled."""
await init_entry(hass, ufp, [sensor])
assert_entity_counts(hass, Platform.SENSOR, 22, 14)
entity_registry = er.async_get(hass)
expected_values = (
"10",
STATE_UNAVAILABLE,
@ -165,7 +167,10 @@ async def test_sensor_setup_sensor_none(
async def test_sensor_setup_nvr(
hass: HomeAssistant, ufp: MockUFPFixture, fixed_now: datetime
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
fixed_now: datetime,
) -> None:
"""Test sensor entity setup for NVR device."""
@ -190,8 +195,6 @@ async def test_sensor_setup_nvr(
assert_entity_counts(hass, Platform.SENSOR, 12, 9)
entity_registry = er.async_get(hass)
expected_values = (
fixed_now.replace(second=0, microsecond=0).isoformat(),
"50.0",
@ -241,7 +244,7 @@ async def test_sensor_setup_nvr(
async def test_sensor_nvr_missing_values(
hass: HomeAssistant, ufp: MockUFPFixture
hass: HomeAssistant, entity_registry: er.EntityRegistry, ufp: MockUFPFixture
) -> None:
"""Test NVR sensor sensors if no data available."""
@ -257,8 +260,6 @@ async def test_sensor_nvr_missing_values(
assert_entity_counts(hass, Platform.SENSOR, 12, 9)
entity_registry = er.async_get(hass)
# Uptime
description = NVR_SENSORS[0]
unique_id, entity_id = ids_from_device_description(
@ -311,15 +312,17 @@ async def test_sensor_nvr_missing_values(
async def test_sensor_setup_camera(
hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera, fixed_now: datetime
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
fixed_now: datetime,
) -> None:
"""Test sensor entity setup for camera devices."""
await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SENSOR, 24, 12)
entity_registry = er.async_get(hass)
expected_values = (
fixed_now.replace(microsecond=0).isoformat(),
"100",
@ -398,6 +401,7 @@ async def test_sensor_setup_camera(
async def test_sensor_setup_camera_with_last_trip_time(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
entity_registry_enabled_by_default: None,
ufp: MockUFPFixture,
doorbell: Camera,
@ -408,8 +412,6 @@ async def test_sensor_setup_camera_with_last_trip_time(
await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SENSOR, 24, 24)
entity_registry = er.async_get(hass)
# Last Trip Time
unique_id, entity_id = ids_from_device_description(
Platform.SENSOR, doorbell, MOTION_TRIP_SENSORS[0]
@ -474,6 +476,7 @@ async def test_sensor_update_alarm(
async def test_sensor_update_alarm_with_last_trip_time(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
entity_registry_enabled_by_default: None,
ufp: MockUFPFixture,
sensor_all: Sensor,
@ -488,7 +491,6 @@ async def test_sensor_update_alarm_with_last_trip_time(
unique_id, entity_id = ids_from_device_description(
Platform.SENSOR, sensor_all, SENSE_SENSORS_WRITE[-3]
)
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(entity_id)
assert entity

View file

@ -26,24 +26,27 @@ from .utils import MockUFPFixture, init_entry
@pytest.fixture(name="device")
async def device_fixture(hass: HomeAssistant, ufp: MockUFPFixture):
async def device_fixture(
hass: HomeAssistant, device_registry: dr.DeviceRegistry, ufp: MockUFPFixture
):
"""Fixture with entry setup to call services with."""
await init_entry(hass, ufp, [])
device_registry = dr.async_get(hass)
return list(device_registry.devices.values())[0]
@pytest.fixture(name="subdevice")
async def subdevice_fixture(hass: HomeAssistant, ufp: MockUFPFixture, light: Light):
async def subdevice_fixture(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
ufp: MockUFPFixture,
light: Light,
):
"""Fixture with entry setup to call services with."""
await init_entry(hass, ufp, [light])
device_registry = dr.async_get(hass)
return [d for d in device_registry.devices.values() if d.name != "UnifiProtect"][0]
@ -141,6 +144,7 @@ async def test_set_default_doorbell_text(
async def test_set_chime_paired_doorbells(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
chime: Chime,
doorbell: Camera,
@ -157,9 +161,8 @@ async def test_set_chime_paired_doorbells(
await init_entry(hass, ufp, [camera1, camera2, chime])
registry = er.async_get(hass)
chime_entry = registry.async_get("button.test_chime_play_chime")
camera_entry = registry.async_get("binary_sensor.test_camera_2_doorbell")
chime_entry = entity_registry.async_get("button.test_chime_play_chime")
camera_entry = entity_registry.async_get("binary_sensor.test_camera_2_doorbell")
assert chime_entry is not None
assert camera_entry is not None
@ -183,6 +186,7 @@ async def test_set_chime_paired_doorbells(
async def test_remove_privacy_zone_no_zone(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
) -> None:
@ -193,8 +197,7 @@ async def test_remove_privacy_zone_no_zone(
await init_entry(hass, ufp, [doorbell])
registry = er.async_get(hass)
camera_entry = registry.async_get("binary_sensor.test_camera_doorbell")
camera_entry = entity_registry.async_get("binary_sensor.test_camera_doorbell")
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
@ -208,6 +211,7 @@ async def test_remove_privacy_zone_no_zone(
async def test_remove_privacy_zone(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
) -> None:
@ -220,8 +224,7 @@ async def test_remove_privacy_zone(
await init_entry(hass, ufp, [doorbell])
registry = er.async_get(hass)
camera_entry = registry.async_get("binary_sensor.test_camera_doorbell")
camera_entry = entity_registry.async_get("binary_sensor.test_camera_doorbell")
await hass.services.async_call(
DOMAIN,

View file

@ -123,6 +123,7 @@ async def test_switch_setup_no_perm(
async def test_switch_setup_light(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
light: Light,
) -> None:
@ -131,8 +132,6 @@ async def test_switch_setup_light(
await init_entry(hass, ufp, [light])
assert_entity_counts(hass, Platform.SWITCH, 4, 3)
entity_registry = er.async_get(hass)
description = LIGHT_SWITCHES[1]
unique_id, entity_id = ids_from_device_description(
@ -168,6 +167,7 @@ async def test_switch_setup_light(
async def test_switch_setup_camera_all(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
) -> None:
@ -176,8 +176,6 @@ async def test_switch_setup_camera_all(
await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
entity_registry = er.async_get(hass)
for description in CAMERA_SWITCHES_BASIC:
unique_id, entity_id = ids_from_device_description(
Platform.SWITCH, doorbell, description
@ -215,6 +213,7 @@ async def test_switch_setup_camera_all(
async def test_switch_setup_camera_none(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
camera: Camera,
) -> None:
@ -223,8 +222,6 @@ async def test_switch_setup_camera_none(
await init_entry(hass, ufp, [camera])
assert_entity_counts(hass, Platform.SWITCH, 8, 7)
entity_registry = er.async_get(hass)
for description in CAMERA_SWITCHES_BASIC:
if description.ufp_required_field is not None:
continue

View file

@ -37,7 +37,10 @@ async def test_text_camera_remove(
async def test_text_camera_setup(
hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
) -> None:
"""Test text entity setup for camera devices."""
@ -47,8 +50,6 @@ async def test_text_camera_setup(
await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.TEXT, 1, 1)
entity_registry = er.async_get(hass)
description = CAMERA[0]
unique_id, entity_id = ids_from_device_description(
Platform.TEXT, doorbell, description

View file

@ -197,13 +197,13 @@ async def test_update_errors(
async def test_device_management(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test that we are adding and removing devices for monitors returned from the API."""
mock_entry = await setup_uptimerobot_integration(hass)
dev_reg = dr.async_get(hass)
devices = dr.async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
devices = dr.async_entries_for_config_entry(device_registry, mock_entry.entry_id)
assert len(devices) == 1
assert devices[0].identifiers == {(DOMAIN, "1234")}
@ -222,7 +222,7 @@ async def test_device_management(
async_fire_time_changed(hass)
await hass.async_block_till_done()
devices = dr.async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
devices = dr.async_entries_for_config_entry(device_registry, mock_entry.entry_id)
assert len(devices) == 2
assert devices[0].identifiers == {(DOMAIN, "1234")}
assert devices[1].identifiers == {(DOMAIN, "12345")}
@ -241,7 +241,7 @@ async def test_device_management(
await hass.async_block_till_done()
await hass.async_block_till_done()
devices = dr.async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
devices = dr.async_entries_for_config_entry(device_registry, mock_entry.entry_id)
assert len(devices) == 1
assert devices[0].identifiers == {(DOMAIN, "1234")}

View file

@ -336,12 +336,12 @@ async def test_options(hass: HomeAssistant) -> None:
assert state.attributes["source"] == input_sensor2_entity_id
async def test_change_device_source(hass: HomeAssistant) -> None:
async def test_change_device_source(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test remove the device registry configuration entry when the source entity changes."""
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
# Configure source entity 1 (with a linked device)
source_config_entry_1 = MockConfigEntry()
source_config_entry_1.add_to_hass(hass)

View file

@ -401,11 +401,13 @@ async def test_setup_missing_discovery(hass: HomeAssistant) -> None:
],
)
async def test_setup_and_remove_config_entry(
hass: HomeAssistant, tariffs: str, expected_entities: list[str]
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
tariffs: str,
expected_entities: list[str],
) -> None:
"""Test setting up and removing a config entry."""
input_sensor_entity_id = "sensor.input"
registry = er.async_get(hass)
# Setup the config entry
config_entry = MockConfigEntry(
@ -428,10 +430,10 @@ async def test_setup_and_remove_config_entry(
await hass.async_block_till_done()
assert len(hass.states.async_all()) == len(expected_entities)
assert len(registry.entities) == len(expected_entities)
assert len(entity_registry.entities) == len(expected_entities)
for entity in expected_entities:
assert hass.states.get(entity)
assert entity in registry.entities
assert entity in entity_registry.entities
# Remove the config entry
assert await hass.config_entries.async_remove(config_entry.entry_id)
@ -439,4 +441,4 @@ async def test_setup_and_remove_config_entry(
# Check the state and entity registry entry are removed
assert len(hass.states.async_all()) == 0
assert len(registry.entities) == 0
assert len(entity_registry.entities) == 0

View file

@ -1950,11 +1950,12 @@ async def test_unit_of_measurement_missing_invalid_new_state(
)
async def test_device_id(hass: HomeAssistant) -> None:
async def test_device_id(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test for source entity device for Utility Meter."""
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
source_config_entry = MockConfigEntry()
source_config_entry.add_to_hass(hass)
source_device_entry = device_registry.async_get_or_create(