Update deconz tests to use device & entity registry fixtures (#103703)

This commit is contained in:
Franck Nijhof
2023-11-09 18:06:53 +01:00
committed by GitHub
parent d1f1bbe304
commit 81909f7ddf
13 changed files with 134 additions and 97 deletions
+13 -9
View File
@@ -480,17 +480,17 @@ TEST_DATA = [
@pytest.mark.parametrize(("sensor_data", "expected"), TEST_DATA)
async def test_binary_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
sensor_data,
expected,
) -> None:
"""Test successful creation of binary sensor entities."""
ent_reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
# Create entity entry to migrate to new unique ID
ent_reg.async_get_or_create(
entity_registry.async_get_or_create(
DOMAIN,
DECONZ_DOMAIN,
expected["old_unique_id"],
@@ -513,14 +513,14 @@ async def test_binary_sensors(
# Verify entity registry data
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
assert ent_reg_entry.entity_category is expected["entity_category"]
assert ent_reg_entry.unique_id == expected["unique_id"]
# Verify device registry data
assert (
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
== expected["device_count"]
)
@@ -670,7 +670,10 @@ async def test_add_new_binary_sensor(
async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
) -> None:
"""Test that adding a new binary sensor is not allowed."""
sensor = {
@@ -702,7 +705,6 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
assert len(hass.states.async_all()) == 0
assert not hass.states.get("binary_sensor.presence_sensor")
entity_registry = er.async_get(hass)
assert (
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
)
@@ -719,7 +721,10 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
) -> None:
"""Test that adding a new binary sensor is not allowed."""
sensor = {
@@ -751,7 +756,6 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
assert len(hass.states.async_all()) == 0
assert not hass.states.get("binary_sensor.presence_sensor")
entity_registry = er.async_get(hass)
assert (
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
)
+8 -6
View File
@@ -101,12 +101,14 @@ TEST_DATA = [
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
async def test_button(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, raw_data, expected
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
raw_data,
expected,
) -> None:
"""Test successful creation of button entities."""
ent_reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
@@ -119,14 +121,14 @@ async def test_button(
# Verify entity registry data
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
assert ent_reg_entry.entity_category is expected["entity_category"]
assert ent_reg_entry.unique_id == expected["unique_id"]
# Verify device registry data
assert (
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
== expected["device_count"]
)
+19 -15
View File
@@ -34,7 +34,10 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_deconz_events(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
) -> None:
"""Test successful creation of deconz events."""
data = {
@@ -79,8 +82,6 @@ async def test_deconz_events(
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
assert len(hass.states.async_all()) == 3
# 5 switches + 2 additional devices for deconz service and host
assert (
@@ -212,7 +213,10 @@ async def test_deconz_events(
async def test_deconz_alarm_events(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
) -> None:
"""Test successful creation of deconz alarm events."""
data = {
@@ -276,8 +280,6 @@ async def test_deconz_alarm_events(
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
assert len(hass.states.async_all()) == 4
# 1 alarm control device + 2 additional devices for deconz service and host
assert (
@@ -424,7 +426,10 @@ async def test_deconz_alarm_events(
async def test_deconz_presence_events(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
) -> None:
"""Test successful creation of deconz presence events."""
data = {
@@ -457,8 +462,6 @@ async def test_deconz_presence_events(
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
assert len(hass.states.async_all()) == 5
assert (
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
@@ -527,7 +530,10 @@ async def test_deconz_presence_events(
async def test_deconz_relative_rotary_events(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
) -> None:
"""Test successful creation of deconz relative rotary events."""
data = {
@@ -559,8 +565,6 @@ async def test_deconz_relative_rotary_events(
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
assert len(hass.states.async_all()) == 1
assert (
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
@@ -626,7 +630,9 @@ async def test_deconz_relative_rotary_events(
async def test_deconz_events_bad_unique_id(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Verify no devices are created if unique id is bad or missing."""
data = {
@@ -649,8 +655,6 @@ async def test_deconz_events_bad_unique_id(
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
assert len(hass.states.async_all()) == 1
assert (
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
+21 -15
View File
@@ -49,7 +49,10 @@ def automation_calls(hass):
async def test_get_triggers(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test triggers work."""
data = {
@@ -78,11 +81,9 @@ async def test_get_triggers(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
)
entity_registry = er.async_get(hass)
battery_sensor_entry = entity_registry.async_get(
"sensor.tradfri_on_off_switch_battery"
)
@@ -154,7 +155,10 @@ async def test_get_triggers(
async def test_get_triggers_for_alarm_event(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test triggers work."""
data = {
@@ -190,11 +194,9 @@ async def test_get_triggers_for_alarm_event(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={(DECONZ_DOMAIN, "00:00:00:00:00:00:00:00")}
)
entity_registry = er.async_get(hass)
bat_entity = entity_registry.async_get("sensor.keypad_battery")
low_bat_entity = entity_registry.async_get("binary_sensor.keypad_low_battery")
tamper_entity = entity_registry.async_get("binary_sensor.keypad_tampered")
@@ -250,7 +252,9 @@ async def test_get_triggers_for_alarm_event(
async def test_get_triggers_manage_unsupported_remotes(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Verify no triggers for an unsupported remote."""
data = {
@@ -278,7 +282,6 @@ async def test_get_triggers_manage_unsupported_remotes(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
)
@@ -297,6 +300,7 @@ async def test_functional_device_trigger(
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
automation_calls,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test proper matching and attachment of device trigger automation."""
@@ -326,7 +330,6 @@ async def test_functional_device_trigger(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
)
@@ -403,12 +406,13 @@ async def test_validate_trigger_unknown_device(
async def test_validate_trigger_unsupported_device(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test unsupported device doesn't return a trigger config."""
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
@@ -444,12 +448,13 @@ async def test_validate_trigger_unsupported_device(
async def test_validate_trigger_unsupported_trigger(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test unsupported trigger does not return a trigger config."""
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
@@ -487,12 +492,13 @@ async def test_validate_trigger_unsupported_trigger(
async def test_attach_trigger_no_matching_event(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test no matching event for device doesn't return a trigger config."""
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
+6 -4
View File
@@ -139,7 +139,9 @@ async def setup_deconz_integration(
async def test_gateway_setup(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Successful setup."""
with patch(
@@ -178,7 +180,6 @@ async def test_gateway_setup(
assert forward_entry_setup.mock_calls[12][1] == (config_entry, SIREN_DOMAIN)
assert forward_entry_setup.mock_calls[13][1] == (config_entry, SWITCH_DOMAIN)
device_registry = dr.async_get(hass)
gateway_entry = device_registry.async_get_device(
identifiers={(DECONZ_DOMAIN, gateway.bridgeid)}
)
@@ -188,7 +189,9 @@ async def test_gateway_setup(
async def test_gateway_device_configuration_url_when_addon(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Successful setup."""
with patch(
@@ -200,7 +203,6 @@ async def test_gateway_device_configuration_url_when_addon(
)
gateway = get_gateway_from_config_entry(hass, config_entry)
device_registry = dr.async_get(hass)
gateway_entry = device_registry.async_get_device(
identifiers={(DECONZ_DOMAIN, gateway.bridgeid)}
)
+21 -10
View File
@@ -159,7 +159,9 @@ async def test_unload_entry_multiple_gateways_parallel(
assert len(hass.data[DECONZ_DOMAIN]) == 0
async def test_update_group_unique_id(hass: HomeAssistant) -> None:
async def test_update_group_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test successful migration of entry data."""
old_unique_id = "123"
new_unique_id = "1234"
@@ -174,9 +176,8 @@ async def test_update_group_unique_id(hass: HomeAssistant) -> None:
},
)
registry = er.async_get(hass)
# Create entity entry to migrate to new unique ID
registry.async_get_or_create(
entity_registry.async_get_or_create(
LIGHT_DOMAIN,
DECONZ_DOMAIN,
f"{old_unique_id}-OLD",
@@ -184,7 +185,7 @@ async def test_update_group_unique_id(hass: HomeAssistant) -> None:
config_entry=entry,
)
# Create entity entry with new unique ID
registry.async_get_or_create(
entity_registry.async_get_or_create(
LIGHT_DOMAIN,
DECONZ_DOMAIN,
f"{new_unique_id}-NEW",
@@ -195,11 +196,19 @@ async def test_update_group_unique_id(hass: HomeAssistant) -> None:
await async_update_group_unique_id(hass, entry)
assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{new_unique_id}-OLD"
assert registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id == f"{new_unique_id}-NEW"
assert (
entity_registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id
== f"{new_unique_id}-OLD"
)
assert (
entity_registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id
== f"{new_unique_id}-NEW"
)
async def test_update_group_unique_id_no_legacy_group_id(hass: HomeAssistant) -> None:
async def test_update_group_unique_id_no_legacy_group_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test migration doesn't trigger without old legacy group id in entry data."""
old_unique_id = "123"
new_unique_id = "1234"
@@ -209,9 +218,8 @@ async def test_update_group_unique_id_no_legacy_group_id(hass: HomeAssistant) ->
data={},
)
registry = er.async_get(hass)
# Create entity entry to migrate to new unique ID
registry.async_get_or_create(
entity_registry.async_get_or_create(
LIGHT_DOMAIN,
DECONZ_DOMAIN,
f"{old_unique_id}-OLD",
@@ -221,4 +229,7 @@ async def test_update_group_unique_id_no_legacy_group_id(hass: HomeAssistant) ->
await async_update_group_unique_id(hass, entry)
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{old_unique_id}-OLD"
assert (
entity_registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id
== f"{old_unique_id}-OLD"
)
+6 -6
View File
@@ -27,7 +27,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_humanifying_deconz_alarm_event(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test humanifying deCONZ event."""
data = {
@@ -61,8 +63,6 @@ async def test_humanifying_deconz_alarm_event(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
keypad_event_id = slugify(data["sensors"]["1"]["name"])
keypad_serial = serial_from_unique_id(data["sensors"]["1"]["uniqueid"])
keypad_entry = device_registry.async_get_device(
@@ -112,7 +112,9 @@ async def test_humanifying_deconz_alarm_event(
async def test_humanifying_deconz_event(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test humanifying deCONZ event."""
data = {
@@ -152,8 +154,6 @@ async def test_humanifying_deconz_event(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
switch_event_id = slugify(data["sensors"]["1"]["name"])
switch_serial = serial_from_unique_id(data["sensors"]["1"]["uniqueid"])
switch_entry = device_registry.async_get_device(
+5 -5
View File
@@ -111,17 +111,17 @@ TEST_DATA = [
async def test_number_entities(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
mock_deconz_websocket,
sensor_data,
expected,
) -> None:
"""Test successful creation of number entities."""
ent_reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
# Create entity entry to migrate to new unique ID
if "old_unique_id" in expected:
ent_reg.async_get_or_create(
entity_registry.async_get_or_create(
NUMBER_DOMAIN,
DECONZ_DOMAIN,
expected["old_unique_id"],
@@ -141,14 +141,14 @@ async def test_number_entities(
# Verify entity registry data
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
assert ent_reg_entry.entity_category is expected["entity_category"]
assert ent_reg_entry.unique_id == expected["unique_id"]
# Verify device registry data
assert (
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
== expected["device_count"]
)
+8 -6
View File
@@ -57,12 +57,14 @@ TEST_DATA = [
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
async def test_scenes(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, raw_data, expected
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
raw_data,
expected,
) -> None:
"""Test successful creation of scene entities."""
ent_reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
@@ -75,14 +77,14 @@ async def test_scenes(
# Verify entity registry data
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
assert ent_reg_entry.entity_category is expected["entity_category"]
assert ent_reg_entry.unique_id == expected["unique_id"]
# Verify device registry data
assert (
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
== expected["device_count"]
)
+8 -6
View File
@@ -168,12 +168,14 @@ TEST_DATA = [
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
async def test_select(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, raw_data, expected
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
raw_data,
expected,
) -> None:
"""Test successful creation of button entities."""
ent_reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
@@ -186,14 +188,14 @@ async def test_select(
# Verify entity registry data
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
assert ent_reg_entry.entity_category is expected["entity_category"]
assert ent_reg_entry.unique_id == expected["unique_id"]
# Verify device registry data
assert (
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
== expected["device_count"]
)
+9 -7
View File
@@ -792,18 +792,18 @@ TEST_DATA = [
@pytest.mark.parametrize(("sensor_data", "expected"), TEST_DATA)
async def test_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_deconz_websocket,
sensor_data,
expected,
) -> None:
"""Test successful creation of sensor entities."""
ent_reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
# Create entity entry to migrate to new unique ID
if "old_unique_id" in expected:
ent_reg.async_get_or_create(
entity_registry.async_get_or_create(
SENSOR_DOMAIN,
DECONZ_DOMAIN,
expected["old_unique_id"],
@@ -817,7 +817,9 @@ async def test_sensors(
# Enable in entity registry
if expected.get("enable_entity"):
ent_reg.async_update_entity(entity_id=expected["entity_id"], disabled_by=None)
entity_registry.async_update_entity(
entity_id=expected["entity_id"], disabled_by=None
)
await hass.async_block_till_done()
async_fire_time_changed(
@@ -836,16 +838,16 @@ async def test_sensors(
# Verify entity registry
assert (
ent_reg.async_get(expected["entity_id"]).entity_category
entity_registry.async_get(expected["entity_id"]).entity_category
is expected["entity_category"]
)
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
assert ent_reg_entry.entity_category is expected["entity_category"]
assert ent_reg_entry.unique_id == expected["unique_id"]
# Verify device registry
assert (
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
== expected["device_count"]
)
+4 -3
View File
@@ -349,7 +349,10 @@ async def test_service_refresh_devices_trigger_no_state_update(
async def test_remove_orphaned_entries_service(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test service works and also don't remove more than expected."""
data = {
@@ -374,7 +377,6 @@ async def test_remove_orphaned_entries_service(
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, "123")},
@@ -391,7 +393,6 @@ async def test_remove_orphaned_entries_service(
== 5 # Host, gateway, light, switch and orphan
)
entity_registry = er.async_get(hass)
entity_registry.async_get_or_create(
SENSOR_DOMAIN,
DECONZ_DOMAIN,
+6 -5
View File
@@ -119,13 +119,14 @@ async def test_power_plugs(
async def test_remove_legacy_on_off_output_as_light(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test that switch platform cleans up legacy light entities."""
unique_id = "00:00:00:00:00:00:00:00-00"
registry = er.async_get(hass)
switch_light_entity = registry.async_get_or_create(
switch_light_entity = entity_registry.async_get_or_create(
LIGHT_DOMAIN, DECONZ_DOMAIN, unique_id
)
@@ -144,6 +145,6 @@ async def test_remove_legacy_on_off_output_as_light(
with patch.dict(DECONZ_WEB_REQUEST, data):
await setup_deconz_integration(hass, aioclient_mock)
assert not registry.async_get("light.on_off_output_device")
assert registry.async_get("switch.on_off_output_device")
assert not entity_registry.async_get("light.on_off_output_device")
assert entity_registry.async_get("switch.on_off_output_device")
assert len(hass.states.async_all()) == 1