mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 14:08:21 +00:00
Clean up unnecessary registry mocks from helpers (#87734)
This commit is contained in:
@@ -11,22 +11,11 @@ from homeassistant.exceptions import MaxLengthExceeded
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
flush_store,
|
||||
mock_device_registry,
|
||||
mock_registry,
|
||||
)
|
||||
from tests.common import MockConfigEntry, flush_store
|
||||
|
||||
YAML__OPEN_PATH = "homeassistant.util.yaml.loader.open"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registry(hass):
|
||||
"""Return an empty, loaded, registry."""
|
||||
return mock_registry(hass)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def update_events(hass):
|
||||
"""Capture update events."""
|
||||
@@ -41,14 +30,14 @@ def update_events(hass):
|
||||
return events
|
||||
|
||||
|
||||
async def test_get_or_create_returns_same_entry(hass, registry, update_events):
|
||||
async def test_get_or_create_returns_same_entry(hass, entity_registry, update_events):
|
||||
"""Make sure we do not duplicate entries."""
|
||||
entry = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry2 = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
entry2 = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(registry.entities) == 1
|
||||
assert len(entity_registry.entities) == 1
|
||||
assert entry is entry2
|
||||
assert entry.entity_id == "light.hue_1234"
|
||||
assert len(update_events) == 1
|
||||
@@ -56,20 +45,20 @@ async def test_get_or_create_returns_same_entry(hass, registry, update_events):
|
||||
assert update_events[0]["entity_id"] == entry.entity_id
|
||||
|
||||
|
||||
def test_get_or_create_suggested_object_id(registry):
|
||||
def test_get_or_create_suggested_object_id(entity_registry):
|
||||
"""Test that suggested_object_id works."""
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "1234", suggested_object_id="beer"
|
||||
)
|
||||
|
||||
assert entry.entity_id == "light.beer"
|
||||
|
||||
|
||||
def test_get_or_create_updates_data(registry):
|
||||
def test_get_or_create_updates_data(entity_registry):
|
||||
"""Test that we update data in get_or_create."""
|
||||
orig_config_entry = MockConfigEntry(domain="light")
|
||||
|
||||
orig_entry = registry.async_get_or_create(
|
||||
orig_entry = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -113,7 +102,7 @@ def test_get_or_create_updates_data(registry):
|
||||
|
||||
new_config_entry = MockConfigEntry(domain="light")
|
||||
|
||||
new_entry = registry.async_get_or_create(
|
||||
new_entry = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -157,7 +146,7 @@ def test_get_or_create_updates_data(registry):
|
||||
unit_of_measurement="updated-unit_of_measurement",
|
||||
)
|
||||
|
||||
new_entry = registry.async_get_or_create(
|
||||
new_entry = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -202,12 +191,12 @@ def test_get_or_create_updates_data(registry):
|
||||
)
|
||||
|
||||
|
||||
def test_get_or_create_suggested_object_id_conflict_register(registry):
|
||||
def test_get_or_create_suggested_object_id_conflict_register(entity_registry):
|
||||
"""Test that we don't generate an entity id that is already registered."""
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "1234", suggested_object_id="beer"
|
||||
)
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", suggested_object_id="beer"
|
||||
)
|
||||
|
||||
@@ -215,27 +204,27 @@ def test_get_or_create_suggested_object_id_conflict_register(registry):
|
||||
assert entry2.entity_id == "light.beer_2"
|
||||
|
||||
|
||||
def test_get_or_create_suggested_object_id_conflict_existing(hass, registry):
|
||||
def test_get_or_create_suggested_object_id_conflict_existing(hass, entity_registry):
|
||||
"""Test that we don't generate an entity id that currently exists."""
|
||||
hass.states.async_set("light.hue_1234", "on")
|
||||
entry = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
assert entry.entity_id == "light.hue_1234_2"
|
||||
|
||||
|
||||
def test_create_triggers_save(hass, registry):
|
||||
def test_create_triggers_save(entity_registry):
|
||||
"""Test that registering entry triggers a save."""
|
||||
with patch.object(registry, "async_schedule_save") as mock_schedule_save:
|
||||
registry.async_get_or_create("light", "hue", "1234")
|
||||
with patch.object(entity_registry, "async_schedule_save") as mock_schedule_save:
|
||||
entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
|
||||
assert len(mock_schedule_save.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_loading_saving_data(hass, registry):
|
||||
async def test_loading_saving_data(hass, entity_registry):
|
||||
"""Test that we load/save data correctly."""
|
||||
mock_config = MockConfigEntry(domain="light")
|
||||
|
||||
orig_entry1 = registry.async_get_or_create("light", "hue", "1234")
|
||||
orig_entry2 = registry.async_get_or_create(
|
||||
orig_entry1 = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
orig_entry2 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -253,7 +242,7 @@ async def test_loading_saving_data(hass, registry):
|
||||
translation_key="initial-translation_key",
|
||||
unit_of_measurement="initial-unit_of_measurement",
|
||||
)
|
||||
registry.async_update_entity(
|
||||
entity_registry.async_update_entity(
|
||||
orig_entry2.entity_id,
|
||||
aliases={"initial_alias_1", "initial_alias_2"},
|
||||
area_id="mock-area-id",
|
||||
@@ -261,22 +250,22 @@ async def test_loading_saving_data(hass, registry):
|
||||
name="User Name",
|
||||
icon="hass:user-icon",
|
||||
)
|
||||
registry.async_update_entity_options(
|
||||
entity_registry.async_update_entity_options(
|
||||
orig_entry2.entity_id, "light", {"minimum_brightness": 20}
|
||||
)
|
||||
orig_entry2 = registry.async_get(orig_entry2.entity_id)
|
||||
orig_entry2 = entity_registry.async_get(orig_entry2.entity_id)
|
||||
|
||||
assert len(registry.entities) == 2
|
||||
assert len(entity_registry.entities) == 2
|
||||
|
||||
# Now load written data in new registry
|
||||
registry2 = er.EntityRegistry(hass)
|
||||
await flush_store(registry._store)
|
||||
await flush_store(entity_registry._store)
|
||||
await registry2.async_load()
|
||||
|
||||
# Ensure same order
|
||||
assert list(registry.entities) == list(registry2.entities)
|
||||
new_entry1 = registry.async_get_or_create("light", "hue", "1234")
|
||||
new_entry2 = registry.async_get_or_create("light", "hue", "5678")
|
||||
assert list(entity_registry.entities) == list(registry2.entities)
|
||||
new_entry1 = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
new_entry2 = entity_registry.async_get_or_create("light", "hue", "5678")
|
||||
|
||||
assert orig_entry1 == new_entry1
|
||||
assert orig_entry2 == new_entry2
|
||||
@@ -301,24 +290,30 @@ async def test_loading_saving_data(hass, registry):
|
||||
assert new_entry2.unit_of_measurement == "initial-unit_of_measurement"
|
||||
|
||||
|
||||
def test_generate_entity_considers_registered_entities(registry):
|
||||
def test_generate_entity_considers_registered_entities(entity_registry):
|
||||
"""Test that we don't create entity id that are already registered."""
|
||||
entry = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
assert entry.entity_id == "light.hue_1234"
|
||||
assert registry.async_generate_entity_id("light", "hue_1234") == "light.hue_1234_2"
|
||||
assert (
|
||||
entity_registry.async_generate_entity_id("light", "hue_1234")
|
||||
== "light.hue_1234_2"
|
||||
)
|
||||
|
||||
|
||||
def test_generate_entity_considers_existing_entities(hass, registry):
|
||||
def test_generate_entity_considers_existing_entities(hass, entity_registry):
|
||||
"""Test that we don't create entity id that currently exists."""
|
||||
hass.states.async_set("light.kitchen", "on")
|
||||
assert registry.async_generate_entity_id("light", "kitchen") == "light.kitchen_2"
|
||||
assert (
|
||||
entity_registry.async_generate_entity_id("light", "kitchen")
|
||||
== "light.kitchen_2"
|
||||
)
|
||||
|
||||
|
||||
def test_is_registered(registry):
|
||||
def test_is_registered(entity_registry):
|
||||
"""Test that is_registered works."""
|
||||
entry = registry.async_get_or_create("light", "hue", "1234")
|
||||
assert registry.async_is_registered(entry.entity_id)
|
||||
assert not registry.async_is_registered("light.non_existing")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
assert entity_registry.async_is_registered(entry.entity_id)
|
||||
assert not entity_registry.async_is_registered("light.non_existing")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
@@ -403,23 +398,25 @@ async def test_filter_on_load(hass, hass_storage):
|
||||
assert entry_system_category.entity_category is None
|
||||
|
||||
|
||||
def test_async_get_entity_id(registry):
|
||||
def test_async_get_entity_id(entity_registry):
|
||||
"""Test that entity_id is returned."""
|
||||
entry = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
assert entry.entity_id == "light.hue_1234"
|
||||
assert registry.async_get_entity_id("light", "hue", "1234") == "light.hue_1234"
|
||||
assert registry.async_get_entity_id("light", "hue", "123") is None
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "1234") == "light.hue_1234"
|
||||
)
|
||||
assert entity_registry.async_get_entity_id("light", "hue", "123") is None
|
||||
|
||||
|
||||
async def test_updating_config_entry_id(hass, registry, update_events):
|
||||
async def test_updating_config_entry_id(hass, entity_registry, update_events):
|
||||
"""Test that we update config entry id in registry."""
|
||||
mock_config_1 = MockConfigEntry(domain="light", entry_id="mock-id-1")
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config_1
|
||||
)
|
||||
|
||||
mock_config_2 = MockConfigEntry(domain="light", entry_id="mock-id-2")
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config_2
|
||||
)
|
||||
assert entry.entity_id == entry2.entity_id
|
||||
@@ -435,17 +432,17 @@ async def test_updating_config_entry_id(hass, registry, update_events):
|
||||
assert update_events[1]["changes"] == {"config_entry_id": "mock-id-1"}
|
||||
|
||||
|
||||
async def test_removing_config_entry_id(hass, registry, update_events):
|
||||
async def test_removing_config_entry_id(hass, entity_registry, update_events):
|
||||
"""Test that we update config entry id in registry."""
|
||||
mock_config = MockConfigEntry(domain="light", entry_id="mock-id-1")
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config
|
||||
)
|
||||
assert entry.config_entry_id == "mock-id-1"
|
||||
registry.async_clear_config_entry("mock-id-1")
|
||||
entity_registry.async_clear_config_entry("mock-id-1")
|
||||
|
||||
assert not registry.entities
|
||||
assert not entity_registry.entities
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -456,14 +453,16 @@ async def test_removing_config_entry_id(hass, registry, update_events):
|
||||
assert update_events[1]["entity_id"] == entry.entity_id
|
||||
|
||||
|
||||
async def test_removing_area_id(registry):
|
||||
async def test_removing_area_id(entity_registry):
|
||||
"""Make sure we can clear area id."""
|
||||
entry = registry.async_get_or_create("light", "hue", "5678")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "5678")
|
||||
|
||||
entry_w_area = registry.async_update_entity(entry.entity_id, area_id="12345A")
|
||||
entry_w_area = entity_registry.async_update_entity(
|
||||
entry.entity_id, area_id="12345A"
|
||||
)
|
||||
|
||||
registry.async_clear_area_id("12345A")
|
||||
entry_wo_area = registry.async_get(entry.entity_id)
|
||||
entity_registry.async_clear_area_id("12345A")
|
||||
entry_wo_area = entity_registry.async_get(entry.entity_id)
|
||||
|
||||
assert not entry_wo_area.area_id
|
||||
assert entry_w_area != entry_wo_area
|
||||
@@ -568,69 +567,81 @@ async def test_migration_1_7(hass, hass_storage):
|
||||
assert entry.original_device_class == "class_by_integration"
|
||||
|
||||
|
||||
async def test_update_entity_unique_id(registry):
|
||||
async def test_update_entity_unique_id(entity_registry):
|
||||
"""Test entity's unique_id is updated."""
|
||||
mock_config = MockConfigEntry(domain="light", entry_id="mock-id-1")
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config
|
||||
)
|
||||
assert registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
assert (
|
||||
entity_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(
|
||||
with patch.object(entity_registry, "async_schedule_save") as mock_schedule_save:
|
||||
updated_entry = entity_registry.async_update_entity(
|
||||
entry.entity_id, new_unique_id=new_unique_id
|
||||
)
|
||||
assert updated_entry != entry
|
||||
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
|
||||
assert entity_registry.async_get_entity_id("light", "hue", "5678") is None
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "1234") == entry.entity_id
|
||||
)
|
||||
|
||||
|
||||
async def test_update_entity_unique_id_conflict(registry):
|
||||
async def test_update_entity_unique_id_conflict(entity_registry):
|
||||
"""Test migration raises when unique_id already in use."""
|
||||
mock_config = MockConfigEntry(domain="light", entry_id="mock-id-1")
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config
|
||||
)
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light", "hue", "1234", config_entry=mock_config
|
||||
)
|
||||
with patch.object(
|
||||
registry, "async_schedule_save"
|
||||
entity_registry, "async_schedule_save"
|
||||
) as mock_schedule_save, pytest.raises(ValueError):
|
||||
registry.async_update_entity(entry.entity_id, new_unique_id=entry2.unique_id)
|
||||
entity_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
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
)
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "1234") == entry2.entity_id
|
||||
)
|
||||
|
||||
|
||||
async def test_update_entity_entity_id(registry):
|
||||
async def test_update_entity_entity_id(entity_registry):
|
||||
"""Test entity's entity_id is updated."""
|
||||
entry = registry.async_get_or_create("light", "hue", "5678")
|
||||
assert registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "5678")
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
)
|
||||
|
||||
new_entity_id = "light.blah"
|
||||
assert new_entity_id != entry.entity_id
|
||||
with patch.object(registry, "async_schedule_save") as mock_schedule_save:
|
||||
updated_entry = registry.async_update_entity(
|
||||
with patch.object(entity_registry, "async_schedule_save") as mock_schedule_save:
|
||||
updated_entry = entity_registry.async_update_entity(
|
||||
entry.entity_id, new_entity_id=new_entity_id
|
||||
)
|
||||
assert updated_entry != entry
|
||||
assert updated_entry.entity_id == new_entity_id
|
||||
assert mock_schedule_save.call_count == 1
|
||||
|
||||
assert registry.async_get(entry.entity_id) is None
|
||||
assert registry.async_get(new_entity_id) is not None
|
||||
assert entity_registry.async_get(entry.entity_id) is None
|
||||
assert entity_registry.async_get(new_entity_id) is not None
|
||||
|
||||
|
||||
async def test_update_entity_entity_id_entity_id(hass: HomeAssistant, registry):
|
||||
async def test_update_entity_entity_id_entity_id(hass: HomeAssistant, entity_registry):
|
||||
"""Test update raises when entity_id already in use."""
|
||||
entry = registry.async_get_or_create("light", "hue", "5678")
|
||||
entry2 = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry = entity_registry.async_get_or_create("light", "hue", "5678")
|
||||
entry2 = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
state_entity_id = "light.blah"
|
||||
hass.states.async_set(state_entity_id, "on")
|
||||
assert entry.entity_id != state_entity_id
|
||||
@@ -638,30 +649,40 @@ async def test_update_entity_entity_id_entity_id(hass: HomeAssistant, registry):
|
||||
|
||||
# Try updating to a registered entity_id
|
||||
with patch.object(
|
||||
registry, "async_schedule_save"
|
||||
entity_registry, "async_schedule_save"
|
||||
) as mock_schedule_save, pytest.raises(ValueError):
|
||||
registry.async_update_entity(entry.entity_id, new_entity_id=entry2.entity_id)
|
||||
entity_registry.async_update_entity(
|
||||
entry.entity_id, new_entity_id=entry2.entity_id
|
||||
)
|
||||
assert mock_schedule_save.call_count == 0
|
||||
assert registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
assert registry.async_get(entry.entity_id) is entry
|
||||
assert registry.async_get_entity_id("light", "hue", "1234") == entry2.entity_id
|
||||
assert registry.async_get(entry2.entity_id) is entry2
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
)
|
||||
assert entity_registry.async_get(entry.entity_id) is entry
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "1234") == entry2.entity_id
|
||||
)
|
||||
assert entity_registry.async_get(entry2.entity_id) is entry2
|
||||
|
||||
# Try updating to an entity_id which is in the state machine
|
||||
with patch.object(
|
||||
registry, "async_schedule_save"
|
||||
entity_registry, "async_schedule_save"
|
||||
) as mock_schedule_save, pytest.raises(ValueError):
|
||||
registry.async_update_entity(entry.entity_id, new_entity_id=state_entity_id)
|
||||
entity_registry.async_update_entity(
|
||||
entry.entity_id, new_entity_id=state_entity_id
|
||||
)
|
||||
assert mock_schedule_save.call_count == 0
|
||||
assert registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
assert registry.async_get(entry.entity_id) is entry
|
||||
assert registry.async_get(state_entity_id) is None
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("light", "hue", "5678") == entry.entity_id
|
||||
)
|
||||
assert entity_registry.async_get(entry.entity_id) is entry
|
||||
assert entity_registry.async_get(state_entity_id) is None
|
||||
|
||||
|
||||
async def test_update_entity(registry):
|
||||
async def test_update_entity(entity_registry):
|
||||
"""Test updating entity."""
|
||||
mock_config = MockConfigEntry(domain="light", entry_id="mock-id-1")
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config
|
||||
)
|
||||
|
||||
@@ -672,73 +693,73 @@ async def test_update_entity(registry):
|
||||
("name", "new name"),
|
||||
):
|
||||
changes = {attr_name: new_value}
|
||||
updated_entry = registry.async_update_entity(entry.entity_id, **changes)
|
||||
updated_entry = entity_registry.async_update_entity(entry.entity_id, **changes)
|
||||
|
||||
assert updated_entry != entry
|
||||
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")
|
||||
entity_registry.async_get_entity_id("light", "hue", "5678")
|
||||
== updated_entry.entity_id
|
||||
)
|
||||
entry = updated_entry
|
||||
|
||||
|
||||
async def test_update_entity_options(registry):
|
||||
async def test_update_entity_options(entity_registry):
|
||||
"""Test updating entity."""
|
||||
mock_config = MockConfigEntry(domain="light", entry_id="mock-id-1")
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", config_entry=mock_config
|
||||
)
|
||||
|
||||
registry.async_update_entity_options(
|
||||
entity_registry.async_update_entity_options(
|
||||
entry.entity_id, "light", {"minimum_brightness": 20}
|
||||
)
|
||||
new_entry_1 = registry.async_get(entry.entity_id)
|
||||
new_entry_1 = entity_registry.async_get(entry.entity_id)
|
||||
|
||||
assert entry.options == {}
|
||||
assert new_entry_1.options == {"light": {"minimum_brightness": 20}}
|
||||
|
||||
registry.async_update_entity_options(
|
||||
entity_registry.async_update_entity_options(
|
||||
entry.entity_id, "light", {"minimum_brightness": 30}
|
||||
)
|
||||
new_entry_2 = registry.async_get(entry.entity_id)
|
||||
new_entry_2 = entity_registry.async_get(entry.entity_id)
|
||||
|
||||
assert entry.options == {}
|
||||
assert new_entry_1.options == {"light": {"minimum_brightness": 20}}
|
||||
assert new_entry_2.options == {"light": {"minimum_brightness": 30}}
|
||||
|
||||
|
||||
async def test_disabled_by(registry):
|
||||
async def test_disabled_by(entity_registry):
|
||||
"""Test that we can disable an entry when we create it."""
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", disabled_by=er.RegistryEntryDisabler.HASS
|
||||
)
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.HASS
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "5678", disabled_by=er.RegistryEntryDisabler.INTEGRATION
|
||||
)
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.HASS
|
||||
|
||||
entry2 = registry.async_get_or_create("light", "hue", "1234")
|
||||
entry2 = entity_registry.async_get_or_create("light", "hue", "1234")
|
||||
assert entry2.disabled_by is None
|
||||
|
||||
|
||||
async def test_disabled_by_config_entry_pref(registry):
|
||||
async def test_disabled_by_config_entry_pref(entity_registry):
|
||||
"""Test config entry preference setting disabled_by."""
|
||||
mock_config = MockConfigEntry(
|
||||
domain="light",
|
||||
entry_id="mock-id-1",
|
||||
pref_disable_new_entities=True,
|
||||
)
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light", "hue", "AAAA", config_entry=mock_config
|
||||
)
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"BBBB",
|
||||
@@ -893,9 +914,8 @@ async def test_async_get_device_class_lookup(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_remove_device_removes_entities(hass, registry):
|
||||
async def test_remove_device_removes_entities(hass, entity_registry, device_registry):
|
||||
"""Test that we remove entities tied to a device."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry = MockConfigEntry(domain="light")
|
||||
|
||||
device_entry = device_registry.async_get_or_create(
|
||||
@@ -903,7 +923,7 @@ async def test_remove_device_removes_entities(hass, registry):
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -911,17 +931,18 @@ async def test_remove_device_removes_entities(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
|
||||
assert registry.async_is_registered(entry.entity_id)
|
||||
assert entity_registry.async_is_registered(entry.entity_id)
|
||||
|
||||
device_registry.async_remove_device(device_entry.id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not registry.async_is_registered(entry.entity_id)
|
||||
assert not entity_registry.async_is_registered(entry.entity_id)
|
||||
|
||||
|
||||
async def test_remove_config_entry_from_device_removes_entities(hass, registry):
|
||||
async def test_remove_config_entry_from_device_removes_entities(
|
||||
hass, device_registry, entity_registry
|
||||
):
|
||||
"""Test that we remove entities tied to a device when config entry is removed."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry_1 = MockConfigEntry(domain="hue")
|
||||
config_entry_2 = MockConfigEntry(domain="device_tracker")
|
||||
|
||||
@@ -940,7 +961,7 @@ async def test_remove_config_entry_from_device_removes_entities(hass, registry):
|
||||
}
|
||||
|
||||
# Create one entity for each config entry
|
||||
entry_1 = registry.async_get_or_create(
|
||||
entry_1 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -948,7 +969,7 @@ async def test_remove_config_entry_from_device_removes_entities(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
|
||||
entry_2 = registry.async_get_or_create(
|
||||
entry_2 = entity_registry.async_get_or_create(
|
||||
"sensor",
|
||||
"device_tracker",
|
||||
"6789",
|
||||
@@ -956,8 +977,8 @@ async def test_remove_config_entry_from_device_removes_entities(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
|
||||
assert registry.async_is_registered(entry_1.entity_id)
|
||||
assert registry.async_is_registered(entry_2.entity_id)
|
||||
assert entity_registry.async_is_registered(entry_1.entity_id)
|
||||
assert entity_registry.async_is_registered(entry_2.entity_id)
|
||||
|
||||
# Remove the first config entry from the device, the entity associated with it
|
||||
# should be removed
|
||||
@@ -967,8 +988,8 @@ async def test_remove_config_entry_from_device_removes_entities(hass, registry):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert device_registry.async_get(device_entry.id)
|
||||
assert not registry.async_is_registered(entry_1.entity_id)
|
||||
assert registry.async_is_registered(entry_2.entity_id)
|
||||
assert not entity_registry.async_is_registered(entry_1.entity_id)
|
||||
assert entity_registry.async_is_registered(entry_2.entity_id)
|
||||
|
||||
# Remove the second config entry from the device, the entity associated with it
|
||||
# (and the device itself) should be removed
|
||||
@@ -978,13 +999,14 @@ async def test_remove_config_entry_from_device_removes_entities(hass, registry):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not device_registry.async_get(device_entry.id)
|
||||
assert not registry.async_is_registered(entry_1.entity_id)
|
||||
assert not registry.async_is_registered(entry_2.entity_id)
|
||||
assert not entity_registry.async_is_registered(entry_1.entity_id)
|
||||
assert not entity_registry.async_is_registered(entry_2.entity_id)
|
||||
|
||||
|
||||
async def test_remove_config_entry_from_device_removes_entities_2(hass, registry):
|
||||
async def test_remove_config_entry_from_device_removes_entities_2(
|
||||
hass, device_registry, entity_registry
|
||||
):
|
||||
"""Test that we don't remove entities with no config entry when device is modified."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry_1 = MockConfigEntry(domain="hue")
|
||||
config_entry_2 = MockConfigEntry(domain="device_tracker")
|
||||
|
||||
@@ -1003,14 +1025,14 @@ async def test_remove_config_entry_from_device_removes_entities_2(hass, registry
|
||||
}
|
||||
|
||||
# Create one entity for each config entry
|
||||
entry_1 = registry.async_get_or_create(
|
||||
entry_1 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
|
||||
assert registry.async_is_registered(entry_1.entity_id)
|
||||
assert entity_registry.async_is_registered(entry_1.entity_id)
|
||||
|
||||
# Remove the first config entry from the device
|
||||
device_registry.async_update_device(
|
||||
@@ -1019,12 +1041,11 @@ async def test_remove_config_entry_from_device_removes_entities_2(hass, registry
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert device_registry.async_get(device_entry.id)
|
||||
assert registry.async_is_registered(entry_1.entity_id)
|
||||
assert entity_registry.async_is_registered(entry_1.entity_id)
|
||||
|
||||
|
||||
async def test_update_device_race(hass, registry):
|
||||
async def test_update_device_race(hass, device_registry, entity_registry):
|
||||
"""Test race when a device is created, updated and removed."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry = MockConfigEntry(domain="light")
|
||||
|
||||
# Create device
|
||||
@@ -1039,7 +1060,7 @@ async def test_update_device_race(hass, registry):
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
# Add entity to the device
|
||||
entry = registry.async_get_or_create(
|
||||
entry = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -1047,17 +1068,16 @@ async def test_update_device_race(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
|
||||
assert registry.async_is_registered(entry.entity_id)
|
||||
assert entity_registry.async_is_registered(entry.entity_id)
|
||||
|
||||
device_registry.async_remove_device(device_entry.id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not registry.async_is_registered(entry.entity_id)
|
||||
assert not entity_registry.async_is_registered(entry.entity_id)
|
||||
|
||||
|
||||
async def test_disable_device_disables_entities(hass, registry):
|
||||
async def test_disable_device_disables_entities(hass, device_registry, entity_registry):
|
||||
"""Test that we disable entities tied to a device."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry = MockConfigEntry(domain="light")
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
@@ -1066,14 +1086,14 @@ async def test_disable_device_disables_entities(hass, registry):
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
|
||||
entry1 = registry.async_get_or_create(
|
||||
entry1 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
config_entry=config_entry,
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"ABCD",
|
||||
@@ -1081,7 +1101,7 @@ async def test_disable_device_disables_entities(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
disabled_by=er.RegistryEntryDisabler.USER,
|
||||
)
|
||||
entry3 = registry.async_get_or_create(
|
||||
entry3 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"EFGH",
|
||||
@@ -1099,32 +1119,33 @@ async def test_disable_device_disables_entities(hass, registry):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry1 = registry.async_get(entry1.entity_id)
|
||||
entry1 = entity_registry.async_get(entry1.entity_id)
|
||||
assert entry1.disabled
|
||||
assert entry1.disabled_by is er.RegistryEntryDisabler.DEVICE
|
||||
entry2 = registry.async_get(entry2.entity_id)
|
||||
entry2 = entity_registry.async_get(entry2.entity_id)
|
||||
assert entry2.disabled
|
||||
assert entry2.disabled_by is er.RegistryEntryDisabler.USER
|
||||
entry3 = registry.async_get(entry3.entity_id)
|
||||
entry3 = entity_registry.async_get(entry3.entity_id)
|
||||
assert entry3.disabled
|
||||
assert entry3.disabled_by is er.RegistryEntryDisabler.CONFIG_ENTRY
|
||||
|
||||
device_registry.async_update_device(device_entry.id, disabled_by=None)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry1 = registry.async_get(entry1.entity_id)
|
||||
entry1 = entity_registry.async_get(entry1.entity_id)
|
||||
assert not entry1.disabled
|
||||
entry2 = registry.async_get(entry2.entity_id)
|
||||
entry2 = entity_registry.async_get(entry2.entity_id)
|
||||
assert entry2.disabled
|
||||
assert entry2.disabled_by is er.RegistryEntryDisabler.USER
|
||||
entry3 = registry.async_get(entry3.entity_id)
|
||||
entry3 = entity_registry.async_get(entry3.entity_id)
|
||||
assert entry3.disabled
|
||||
assert entry3.disabled_by is er.RegistryEntryDisabler.CONFIG_ENTRY
|
||||
|
||||
|
||||
async def test_disable_config_entry_disables_entities(hass, registry):
|
||||
async def test_disable_config_entry_disables_entities(
|
||||
hass, device_registry, entity_registry
|
||||
):
|
||||
"""Test that we disable entities tied to a config entry."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry = MockConfigEntry(domain="light")
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
@@ -1133,14 +1154,14 @@ async def test_disable_config_entry_disables_entities(hass, registry):
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
|
||||
entry1 = registry.async_get_or_create(
|
||||
entry1 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
config_entry=config_entry,
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"ABCD",
|
||||
@@ -1148,7 +1169,7 @@ async def test_disable_config_entry_disables_entities(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
disabled_by=er.RegistryEntryDisabler.USER,
|
||||
)
|
||||
entry3 = registry.async_get_or_create(
|
||||
entry3 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"EFGH",
|
||||
@@ -1166,32 +1187,33 @@ async def test_disable_config_entry_disables_entities(hass, registry):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry1 = registry.async_get(entry1.entity_id)
|
||||
entry1 = entity_registry.async_get(entry1.entity_id)
|
||||
assert entry1.disabled
|
||||
assert entry1.disabled_by is er.RegistryEntryDisabler.CONFIG_ENTRY
|
||||
entry2 = registry.async_get(entry2.entity_id)
|
||||
entry2 = entity_registry.async_get(entry2.entity_id)
|
||||
assert entry2.disabled
|
||||
assert entry2.disabled_by is er.RegistryEntryDisabler.USER
|
||||
entry3 = registry.async_get(entry3.entity_id)
|
||||
entry3 = entity_registry.async_get(entry3.entity_id)
|
||||
assert entry3.disabled
|
||||
assert entry3.disabled_by is er.RegistryEntryDisabler.DEVICE
|
||||
|
||||
await hass.config_entries.async_set_disabled_by(config_entry.entry_id, None)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry1 = registry.async_get(entry1.entity_id)
|
||||
entry1 = entity_registry.async_get(entry1.entity_id)
|
||||
assert not entry1.disabled
|
||||
entry2 = registry.async_get(entry2.entity_id)
|
||||
entry2 = entity_registry.async_get(entry2.entity_id)
|
||||
assert entry2.disabled
|
||||
assert entry2.disabled_by is er.RegistryEntryDisabler.USER
|
||||
# The device was re-enabled, so entity disabled by the device will be re-enabled too
|
||||
entry3 = registry.async_get(entry3.entity_id)
|
||||
entry3 = entity_registry.async_get(entry3.entity_id)
|
||||
assert not entry3.disabled_by
|
||||
|
||||
|
||||
async def test_disabled_entities_excluded_from_entity_list(hass, registry):
|
||||
async def test_disabled_entities_excluded_from_entity_list(
|
||||
hass, device_registry, entity_registry
|
||||
):
|
||||
"""Test that disabled entities are excluded from async_entries_for_device."""
|
||||
device_registry = mock_device_registry(hass)
|
||||
config_entry = MockConfigEntry(domain="light")
|
||||
|
||||
device_entry = device_registry.async_get_or_create(
|
||||
@@ -1199,7 +1221,7 @@ async def test_disabled_entities_excluded_from_entity_list(hass, registry):
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
|
||||
entry1 = registry.async_get_or_create(
|
||||
entry1 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"5678",
|
||||
@@ -1207,7 +1229,7 @@ async def test_disabled_entities_excluded_from_entity_list(hass, registry):
|
||||
device_id=device_entry.id,
|
||||
)
|
||||
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
"ABCD",
|
||||
@@ -1216,16 +1238,16 @@ async def test_disabled_entities_excluded_from_entity_list(hass, registry):
|
||||
disabled_by=er.RegistryEntryDisabler.USER,
|
||||
)
|
||||
|
||||
entries = er.async_entries_for_device(registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
assert entries == [entry1]
|
||||
|
||||
entries = er.async_entries_for_device(
|
||||
registry, device_entry.id, include_disabled_entities=True
|
||||
entity_registry, device_entry.id, include_disabled_entities=True
|
||||
)
|
||||
assert entries == [entry1, entry2]
|
||||
|
||||
|
||||
async def test_entity_max_length_exceeded(hass, registry):
|
||||
async def test_entity_max_length_exceeded(entity_registry):
|
||||
"""Test that an exception is raised when the max character length is exceeded."""
|
||||
|
||||
long_domain_name = (
|
||||
@@ -1236,7 +1258,7 @@ async def test_entity_max_length_exceeded(hass, registry):
|
||||
)
|
||||
|
||||
with pytest.raises(MaxLengthExceeded) as exc_info:
|
||||
registry.async_generate_entity_id(long_domain_name, "sensor")
|
||||
entity_registry.async_generate_entity_id(long_domain_name, "sensor")
|
||||
|
||||
assert exc_info.value.property_name == "domain"
|
||||
assert exc_info.value.max_length == 64
|
||||
@@ -1251,43 +1273,55 @@ async def test_entity_max_length_exceeded(hass, registry):
|
||||
)
|
||||
|
||||
known = []
|
||||
new_id = registry.async_generate_entity_id("sensor", long_entity_id_name, known)
|
||||
new_id = entity_registry.async_generate_entity_id(
|
||||
"sensor", long_entity_id_name, known
|
||||
)
|
||||
assert new_id == "sensor." + long_entity_id_name[: 255 - 7]
|
||||
known.append(new_id)
|
||||
new_id = registry.async_generate_entity_id("sensor", long_entity_id_name, known)
|
||||
new_id = entity_registry.async_generate_entity_id(
|
||||
"sensor", long_entity_id_name, known
|
||||
)
|
||||
assert new_id == "sensor." + long_entity_id_name[: 255 - 7 - 2] + "_2"
|
||||
known.append(new_id)
|
||||
new_id = registry.async_generate_entity_id("sensor", long_entity_id_name, known)
|
||||
new_id = entity_registry.async_generate_entity_id(
|
||||
"sensor", long_entity_id_name, known
|
||||
)
|
||||
assert new_id == "sensor." + long_entity_id_name[: 255 - 7 - 2] + "_3"
|
||||
|
||||
|
||||
async def test_resolve_entity_ids(hass, registry):
|
||||
async def test_resolve_entity_ids(entity_registry):
|
||||
"""Test resolving entity IDs."""
|
||||
|
||||
entry1 = registry.async_get_or_create(
|
||||
entry1 = entity_registry.async_get_or_create(
|
||||
"light", "hue", "1234", suggested_object_id="beer"
|
||||
)
|
||||
assert entry1.entity_id == "light.beer"
|
||||
|
||||
entry2 = registry.async_get_or_create(
|
||||
entry2 = entity_registry.async_get_or_create(
|
||||
"light", "hue", "2345", suggested_object_id="milk"
|
||||
)
|
||||
assert entry2.entity_id == "light.milk"
|
||||
|
||||
expected = ["light.beer", "light.milk"]
|
||||
assert er.async_validate_entity_ids(registry, [entry1.id, entry2.id]) == expected
|
||||
assert (
|
||||
er.async_validate_entity_ids(entity_registry, [entry1.id, entry2.id])
|
||||
== expected
|
||||
)
|
||||
|
||||
expected = ["light.beer", "light.milk"]
|
||||
assert er.async_validate_entity_ids(registry, ["light.beer", entry2.id]) == expected
|
||||
assert (
|
||||
er.async_validate_entity_ids(entity_registry, ["light.beer", entry2.id])
|
||||
== expected
|
||||
)
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
er.async_validate_entity_ids(registry, ["light.beer", "bad_uuid"])
|
||||
er.async_validate_entity_ids(entity_registry, ["light.beer", "bad_uuid"])
|
||||
|
||||
expected = ["light.unknown"]
|
||||
assert er.async_validate_entity_ids(registry, ["light.unknown"]) == expected
|
||||
assert er.async_validate_entity_ids(entity_registry, ["light.unknown"]) == expected
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
er.async_validate_entity_ids(registry, ["unknown_uuid"])
|
||||
er.async_validate_entity_ids(entity_registry, ["unknown_uuid"])
|
||||
|
||||
|
||||
def test_entity_registry_items() -> None:
|
||||
@@ -1364,12 +1398,12 @@ async def test_hidden_by_str_not_allowed(hass: HomeAssistant) -> None:
|
||||
reg.async_update_entity(entity_id, hidden_by=er.RegistryEntryHider.USER.value)
|
||||
|
||||
|
||||
def test_migrate_entity_to_new_platform(hass, registry):
|
||||
def test_migrate_entity_to_new_platform(hass, entity_registry):
|
||||
"""Test migrate_entity_to_new_platform."""
|
||||
orig_config_entry = MockConfigEntry(domain="light")
|
||||
orig_unique_id = "5678"
|
||||
|
||||
orig_entry = registry.async_get_or_create(
|
||||
orig_entry = entity_registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
orig_unique_id,
|
||||
@@ -1381,8 +1415,8 @@ def test_migrate_entity_to_new_platform(hass, registry):
|
||||
original_icon="initial-original_icon",
|
||||
original_name="initial-original_name",
|
||||
)
|
||||
assert registry.async_get("light.light") is orig_entry
|
||||
registry.async_update_entity(
|
||||
assert entity_registry.async_get("light.light") is orig_entry
|
||||
entity_registry.async_update_entity(
|
||||
"light.light",
|
||||
name="new_name",
|
||||
icon="new_icon",
|
||||
@@ -1391,16 +1425,16 @@ def test_migrate_entity_to_new_platform(hass, registry):
|
||||
new_config_entry = MockConfigEntry(domain="light")
|
||||
new_unique_id = "1234"
|
||||
|
||||
assert registry.async_update_entity_platform(
|
||||
assert entity_registry.async_update_entity_platform(
|
||||
"light.light",
|
||||
"hue2",
|
||||
new_unique_id=new_unique_id,
|
||||
new_config_entry_id=new_config_entry.entry_id,
|
||||
)
|
||||
|
||||
assert not registry.async_get_entity_id("light", "hue", orig_unique_id)
|
||||
assert not entity_registry.async_get_entity_id("light", "hue", orig_unique_id)
|
||||
|
||||
assert (new_entry := registry.async_get("light.light")) is not orig_entry
|
||||
assert (new_entry := entity_registry.async_get("light.light")) is not orig_entry
|
||||
|
||||
assert new_entry.config_entry_id == new_config_entry.entry_id
|
||||
assert new_entry.unique_id == new_unique_id
|
||||
@@ -1410,7 +1444,7 @@ def test_migrate_entity_to_new_platform(hass, registry):
|
||||
|
||||
# Test nonexisting entity
|
||||
with pytest.raises(KeyError):
|
||||
registry.async_update_entity_platform(
|
||||
entity_registry.async_update_entity_platform(
|
||||
"light.not_a_real_light",
|
||||
"hue2",
|
||||
new_unique_id=new_unique_id,
|
||||
@@ -1419,7 +1453,7 @@ def test_migrate_entity_to_new_platform(hass, registry):
|
||||
|
||||
# Test migrate entity without new config entry ID
|
||||
with pytest.raises(ValueError):
|
||||
registry.async_update_entity_platform(
|
||||
entity_registry.async_update_entity_platform(
|
||||
"light.light",
|
||||
"hue3",
|
||||
)
|
||||
@@ -1427,7 +1461,7 @@ def test_migrate_entity_to_new_platform(hass, registry):
|
||||
# Test entity with a state
|
||||
hass.states.async_set("light.light", "on")
|
||||
with pytest.raises(ValueError):
|
||||
registry.async_update_entity_platform(
|
||||
entity_registry.async_update_entity_platform(
|
||||
"light.light",
|
||||
"hue2",
|
||||
new_unique_id=new_unique_id,
|
||||
|
||||
Reference in New Issue
Block a user