1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Update d-e* tests to use entity & device registry fixtures (#103804)

This commit is contained in:
Jan-Philipp Benecke
2023-11-12 10:38:32 +01:00
committed by GitHub
parent 2cffb4df6d
commit 81450f0117
20 changed files with 139 additions and 115 deletions

View File

@@ -13,12 +13,12 @@ from homeassistant.helpers import entity_registry as er
async def test_migrate_entity_unique_id(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_client: APIClient,
mock_generic_device_entry,
) -> None:
"""Test a generic sensor entity unique id migration."""
ent_reg = er.async_get(hass)
ent_reg.async_get_or_create(
entity_registry.async_get_or_create(
"sensor",
"esphome",
"my_sensor",
@@ -46,10 +46,9 @@ async def test_migrate_entity_unique_id(
state = hass.states.get("sensor.old_sensor")
assert state is not None
assert state.state == "50"
entity_reg = er.async_get(hass)
entry = entity_reg.async_get("sensor.old_sensor")
entry = entity_registry.async_get("sensor.old_sensor")
assert entry is not None
assert entity_reg.async_get_entity_id("sensor", "esphome", "my_sensor") is None
assert entity_registry.async_get_entity_id("sensor", "esphome", "my_sensor") is None
# Note that ESPHome includes the EntityInfo type in the unique id
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
assert entry.unique_id == "11:22:33:44:55:aa-sensor-mysensor"
@@ -57,19 +56,19 @@ async def test_migrate_entity_unique_id(
async def test_migrate_entity_unique_id_downgrade_upgrade(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_client: APIClient,
mock_generic_device_entry,
) -> None:
"""Test unique id migration prefers the original entity on downgrade upgrade."""
ent_reg = er.async_get(hass)
ent_reg.async_get_or_create(
entity_registry.async_get_or_create(
"sensor",
"esphome",
"my_sensor",
suggested_object_id="old_sensor",
disabled_by=None,
)
ent_reg.async_get_or_create(
entity_registry.async_get_or_create(
"sensor",
"esphome",
"11:22:33:44:55:aa-sensor-mysensor",
@@ -97,14 +96,16 @@ async def test_migrate_entity_unique_id_downgrade_upgrade(
state = hass.states.get("sensor.new_sensor")
assert state is not None
assert state.state == "50"
entity_reg = er.async_get(hass)
entry = entity_reg.async_get("sensor.new_sensor")
entry = entity_registry.async_get("sensor.new_sensor")
assert entry is not None
# Confirm we did not touch the entity that was created
# on downgrade so when they upgrade again they can delete the
# entity that was only created on downgrade and they keep
# the original one.
assert entity_reg.async_get_entity_id("sensor", "esphome", "my_sensor") is not None
assert (
entity_registry.async_get_entity_id("sensor", "esphome", "my_sensor")
is not None
)
# Note that ESPHome includes the EntityInfo type in the unique id
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
assert entry.unique_id == "11:22:33:44:55:aa-sensor-mysensor"