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

Index the entity registry (#37994)

This commit is contained in:
J. Nick Koston
2020-07-19 19:52:41 -10:00
committed by GitHub
parent 41421b56a4
commit 890562e3ae
3 changed files with 43 additions and 22 deletions

View File

@@ -428,6 +428,8 @@ async def test_update_entity_unique_id(registry):
entry = registry.async_get_or_create(
"light", "hue", "5678", config_entry=mock_config
)
assert registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
new_unique_id = "1234"
with patch.object(registry, "async_schedule_save") as mock_schedule_save:
updated_entry = registry.async_update_entity(
@@ -437,6 +439,9 @@ async def test_update_entity_unique_id(registry):
assert updated_entry.unique_id == new_unique_id
assert mock_schedule_save.call_count == 1
assert registry.async_get_entity_id("light", "hue", "5678") is None
assert registry.async_get_entity_id("light", "hue", "1234") == entry.entity_id
async def test_update_entity_unique_id_conflict(registry):
"""Test migration raises when unique_id already in use."""
@@ -452,6 +457,8 @@ async def test_update_entity_unique_id_conflict(registry):
) as mock_schedule_save, pytest.raises(ValueError):
registry.async_update_entity(entry.entity_id, new_unique_id=entry2.unique_id)
assert mock_schedule_save.call_count == 0
assert registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
assert registry.async_get_entity_id("light", "hue", "1234") == entry2.entity_id
async def test_update_entity(registry):
@@ -473,6 +480,10 @@ async def test_update_entity(registry):
assert getattr(updated_entry, attr_name) == new_value
assert getattr(updated_entry, attr_name) != getattr(entry, attr_name)
assert (
registry.async_get_entity_id("light", "hue", "5678")
== updated_entry.entity_id
)
entry = updated_entry