Remove unused defaults from entity_registry.RegistryEntry (#143655)
This commit is contained in:
@@ -44,6 +44,7 @@ from tests.common import (
|
||||
MockEntityPlatform,
|
||||
MockModule,
|
||||
MockPlatform,
|
||||
RegistryEntryWithDefaults,
|
||||
mock_integration,
|
||||
mock_registry,
|
||||
)
|
||||
@@ -683,7 +684,7 @@ async def test_warn_disabled(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we warn once if we write to a disabled entity."""
|
||||
entry = er.RegistryEntry(
|
||||
entry = RegistryEntryWithDefaults(
|
||||
entity_id="hello.world",
|
||||
unique_id="test-unique-id",
|
||||
platform="test-platform",
|
||||
@@ -710,7 +711,7 @@ async def test_warn_disabled(
|
||||
|
||||
async def test_disabled_in_entity_registry(hass: HomeAssistant) -> None:
|
||||
"""Test entity is removed if we disable entity registry entry."""
|
||||
entry = er.RegistryEntry(
|
||||
entry = RegistryEntryWithDefaults(
|
||||
entity_id="hello.world",
|
||||
unique_id="test-unique-id",
|
||||
platform="test-platform",
|
||||
|
||||
@@ -48,6 +48,7 @@ from tests.common import (
|
||||
MockEntity,
|
||||
MockEntityPlatform,
|
||||
MockPlatform,
|
||||
RegistryEntryWithDefaults,
|
||||
async_fire_time_changed,
|
||||
mock_platform,
|
||||
mock_registry,
|
||||
@@ -752,7 +753,7 @@ async def test_overriding_name_from_registry(hass: HomeAssistant) -> None:
|
||||
mock_registry(
|
||||
hass,
|
||||
{
|
||||
"test_domain.world": er.RegistryEntry(
|
||||
"test_domain.world": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.world",
|
||||
unique_id="1234",
|
||||
# Using component.async_add_entities is equal to platform "domain"
|
||||
@@ -785,7 +786,7 @@ async def test_registry_respect_entity_disabled(hass: HomeAssistant) -> None:
|
||||
mock_registry(
|
||||
hass,
|
||||
{
|
||||
"test_domain.world": er.RegistryEntry(
|
||||
"test_domain.world": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.world",
|
||||
unique_id="1234",
|
||||
# Using component.async_add_entities is equal to platform "domain"
|
||||
@@ -832,7 +833,7 @@ async def test_entity_registry_updates_name(hass: HomeAssistant) -> None:
|
||||
registry = mock_registry(
|
||||
hass,
|
||||
{
|
||||
"test_domain.world": er.RegistryEntry(
|
||||
"test_domain.world": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.world",
|
||||
unique_id="1234",
|
||||
# Using component.async_add_entities is equal to platform "domain"
|
||||
@@ -1065,7 +1066,7 @@ async def test_entity_registry_updates_entity_id(hass: HomeAssistant) -> None:
|
||||
registry = mock_registry(
|
||||
hass,
|
||||
{
|
||||
"test_domain.world": er.RegistryEntry(
|
||||
"test_domain.world": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.world",
|
||||
unique_id="1234",
|
||||
# Using component.async_add_entities is equal to platform "domain"
|
||||
@@ -1097,14 +1098,14 @@ async def test_entity_registry_updates_invalid_entity_id(hass: HomeAssistant) ->
|
||||
registry = mock_registry(
|
||||
hass,
|
||||
{
|
||||
"test_domain.world": er.RegistryEntry(
|
||||
"test_domain.world": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.world",
|
||||
unique_id="1234",
|
||||
# Using component.async_add_entities is equal to platform "domain"
|
||||
platform="test_platform",
|
||||
name="Some name",
|
||||
),
|
||||
"test_domain.existing": er.RegistryEntry(
|
||||
"test_domain.existing": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.existing",
|
||||
unique_id="5678",
|
||||
platform="test_platform",
|
||||
@@ -1529,14 +1530,19 @@ async def test_entity_info_added_to_entity_registry(
|
||||
|
||||
entry_default = entity_registry.async_get_or_create(DOMAIN, DOMAIN, "default")
|
||||
assert entry_default == er.RegistryEntry(
|
||||
"test_domain.best_name",
|
||||
"default",
|
||||
"test_domain",
|
||||
entity_id="test_domain.best_name",
|
||||
unique_id="default",
|
||||
platform="test_domain",
|
||||
capabilities={"max": 100},
|
||||
config_entry_id=None,
|
||||
config_subentry_id=None,
|
||||
created_at=dt_util.utcnow(),
|
||||
device_class=None,
|
||||
device_id=None,
|
||||
disabled_by=None,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
has_entity_name=True,
|
||||
hidden_by=None,
|
||||
icon=None,
|
||||
id=ANY,
|
||||
modified_at=dt_util.utcnow(),
|
||||
@@ -1544,6 +1550,7 @@ async def test_entity_info_added_to_entity_registry(
|
||||
original_device_class="mock-device-class",
|
||||
original_icon="nice:icon",
|
||||
original_name="best name",
|
||||
options=None,
|
||||
supported_features=5,
|
||||
translation_key="my_translation_key",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
|
||||
@@ -24,6 +24,7 @@ from homeassistant.util.dt import utc_from_timestamp
|
||||
from tests.common import (
|
||||
ANY,
|
||||
MockConfigEntry,
|
||||
RegistryEntryWithDefaults,
|
||||
async_capture_events,
|
||||
async_fire_time_changed,
|
||||
flush_store,
|
||||
@@ -122,9 +123,9 @@ def test_get_or_create_updates_data(
|
||||
assert set(entity_registry.async_device_ids()) == {orig_device_entry.id}
|
||||
|
||||
assert orig_entry == er.RegistryEntry(
|
||||
"light.hue_5678",
|
||||
"5678",
|
||||
"hue",
|
||||
entity_id="light.hue_5678",
|
||||
unique_id="5678",
|
||||
platform="hue",
|
||||
capabilities={"max": 100},
|
||||
config_entry_id=orig_config_entry.entry_id,
|
||||
config_subentry_id=config_subentry_id,
|
||||
@@ -139,6 +140,7 @@ def test_get_or_create_updates_data(
|
||||
id=orig_entry.id,
|
||||
modified_at=created,
|
||||
name=None,
|
||||
options=None,
|
||||
original_device_class="mock-device-class",
|
||||
original_icon="initial-original_icon",
|
||||
original_name="initial-original_name",
|
||||
@@ -177,9 +179,9 @@ def test_get_or_create_updates_data(
|
||||
)
|
||||
|
||||
assert new_entry == er.RegistryEntry(
|
||||
"light.hue_5678",
|
||||
"5678",
|
||||
"hue",
|
||||
entity_id="light.hue_5678",
|
||||
unique_id="5678",
|
||||
platform="hue",
|
||||
aliases=set(),
|
||||
area_id=None,
|
||||
capabilities={"new-max": 150},
|
||||
@@ -196,6 +198,7 @@ def test_get_or_create_updates_data(
|
||||
id=orig_entry.id,
|
||||
modified_at=modified,
|
||||
name=None,
|
||||
options=None,
|
||||
original_device_class="new-mock-device-class",
|
||||
original_icon="updated-original_icon",
|
||||
original_name="updated-original_name",
|
||||
@@ -228,13 +231,14 @@ def test_get_or_create_updates_data(
|
||||
)
|
||||
|
||||
assert new_entry == er.RegistryEntry(
|
||||
"light.hue_5678",
|
||||
"5678",
|
||||
"hue",
|
||||
entity_id="light.hue_5678",
|
||||
unique_id="5678",
|
||||
platform="hue",
|
||||
aliases=set(),
|
||||
area_id=None,
|
||||
capabilities=None,
|
||||
config_entry_id=None,
|
||||
config_subentry_id=None,
|
||||
created_at=created,
|
||||
device_class=None,
|
||||
device_id=None,
|
||||
@@ -246,6 +250,7 @@ def test_get_or_create_updates_data(
|
||||
id=orig_entry.id,
|
||||
modified_at=modified,
|
||||
name=None,
|
||||
options=None,
|
||||
original_device_class=None,
|
||||
original_icon=None,
|
||||
original_name=None,
|
||||
@@ -2095,8 +2100,12 @@ def test_entity_registry_items() -> None:
|
||||
assert entities.get_entity_id(("a", "b", "c")) is None
|
||||
assert entities.get_entry("abc") is None
|
||||
|
||||
entry1 = er.RegistryEntry("test.entity1", "1234", "hue")
|
||||
entry2 = er.RegistryEntry("test.entity2", "2345", "hue")
|
||||
entry1 = RegistryEntryWithDefaults(
|
||||
entity_id="test.entity1", unique_id="1234", platform="hue"
|
||||
)
|
||||
entry2 = RegistryEntryWithDefaults(
|
||||
entity_id="test.entity2", unique_id="2345", platform="hue"
|
||||
)
|
||||
entities["test.entity1"] = entry1
|
||||
entities["test.entity2"] = entry2
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ from tests.common import (
|
||||
MockEntity,
|
||||
MockModule,
|
||||
MockUser,
|
||||
RegistryEntryWithDefaults,
|
||||
async_mock_service,
|
||||
mock_area_registry,
|
||||
mock_device_registry,
|
||||
@@ -158,94 +159,94 @@ def floor_area_mock(hass: HomeAssistant) -> None:
|
||||
},
|
||||
)
|
||||
|
||||
entity_in_own_area = er.RegistryEntry(
|
||||
entity_in_own_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.in_own_area",
|
||||
unique_id="in-own-area-id",
|
||||
platform="test",
|
||||
area_id="own-area",
|
||||
)
|
||||
config_entity_in_own_area = er.RegistryEntry(
|
||||
config_entity_in_own_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.config_in_own_area",
|
||||
unique_id="config-in-own-area-id",
|
||||
platform="test",
|
||||
area_id="own-area",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
)
|
||||
hidden_entity_in_own_area = er.RegistryEntry(
|
||||
hidden_entity_in_own_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.hidden_in_own_area",
|
||||
unique_id="hidden-in-own-area-id",
|
||||
platform="test",
|
||||
area_id="own-area",
|
||||
hidden_by=er.RegistryEntryHider.USER,
|
||||
)
|
||||
entity_in_area = er.RegistryEntry(
|
||||
entity_in_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.in_area",
|
||||
unique_id="in-area-id",
|
||||
platform="test",
|
||||
device_id=device_in_area.id,
|
||||
)
|
||||
config_entity_in_area = er.RegistryEntry(
|
||||
config_entity_in_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.config_in_area",
|
||||
unique_id="config-in-area-id",
|
||||
platform="test",
|
||||
device_id=device_in_area.id,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
)
|
||||
hidden_entity_in_area = er.RegistryEntry(
|
||||
hidden_entity_in_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.hidden_in_area",
|
||||
unique_id="hidden-in-area-id",
|
||||
platform="test",
|
||||
device_id=device_in_area.id,
|
||||
hidden_by=er.RegistryEntryHider.USER,
|
||||
)
|
||||
entity_in_other_area = er.RegistryEntry(
|
||||
entity_in_other_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.in_other_area",
|
||||
unique_id="in-area-a-id",
|
||||
platform="test",
|
||||
device_id=device_in_area.id,
|
||||
area_id="other-area",
|
||||
)
|
||||
entity_assigned_to_area = er.RegistryEntry(
|
||||
entity_assigned_to_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.assigned_to_area",
|
||||
unique_id="assigned-area-id",
|
||||
platform="test",
|
||||
device_id=device_in_area.id,
|
||||
area_id="test-area",
|
||||
)
|
||||
entity_no_area = er.RegistryEntry(
|
||||
entity_no_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.no_area",
|
||||
unique_id="no-area-id",
|
||||
platform="test",
|
||||
device_id=device_no_area.id,
|
||||
)
|
||||
config_entity_no_area = er.RegistryEntry(
|
||||
config_entity_no_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.config_no_area",
|
||||
unique_id="config-no-area-id",
|
||||
platform="test",
|
||||
device_id=device_no_area.id,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
)
|
||||
hidden_entity_no_area = er.RegistryEntry(
|
||||
hidden_entity_no_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.hidden_no_area",
|
||||
unique_id="hidden-no-area-id",
|
||||
platform="test",
|
||||
device_id=device_no_area.id,
|
||||
hidden_by=er.RegistryEntryHider.USER,
|
||||
)
|
||||
entity_diff_area = er.RegistryEntry(
|
||||
entity_diff_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.diff_area",
|
||||
unique_id="diff-area-id",
|
||||
platform="test",
|
||||
device_id=device_diff_area.id,
|
||||
)
|
||||
entity_in_area_a = er.RegistryEntry(
|
||||
entity_in_area_a = RegistryEntryWithDefaults(
|
||||
entity_id="light.in_area_a",
|
||||
unique_id="in-area-a-id",
|
||||
platform="test",
|
||||
device_id=device_area_a.id,
|
||||
area_id="area-a",
|
||||
)
|
||||
entity_in_area_b = er.RegistryEntry(
|
||||
entity_in_area_b = RegistryEntryWithDefaults(
|
||||
entity_id="light.in_area_b",
|
||||
unique_id="in-area-b-id",
|
||||
platform="test",
|
||||
@@ -329,53 +330,53 @@ def label_mock(hass: HomeAssistant) -> None:
|
||||
},
|
||||
)
|
||||
|
||||
entity_with_my_label = er.RegistryEntry(
|
||||
entity_with_my_label = RegistryEntryWithDefaults(
|
||||
entity_id="light.with_my_label",
|
||||
unique_id="with_my_label",
|
||||
platform="test",
|
||||
labels={"my-label"},
|
||||
)
|
||||
hidden_entity_with_my_label = er.RegistryEntry(
|
||||
hidden_entity_with_my_label = RegistryEntryWithDefaults(
|
||||
entity_id="light.hidden_with_my_label",
|
||||
unique_id="hidden_with_my_label",
|
||||
platform="test",
|
||||
labels={"my-label"},
|
||||
hidden_by=er.RegistryEntryHider.USER,
|
||||
)
|
||||
config_entity_with_my_label = er.RegistryEntry(
|
||||
config_entity_with_my_label = RegistryEntryWithDefaults(
|
||||
entity_id="light.config_with_my_label",
|
||||
unique_id="config_with_my_label",
|
||||
platform="test",
|
||||
labels={"my-label"},
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
)
|
||||
entity_with_label1_from_device = er.RegistryEntry(
|
||||
entity_with_label1_from_device = RegistryEntryWithDefaults(
|
||||
entity_id="light.with_label1_from_device",
|
||||
unique_id="with_label1_from_device",
|
||||
platform="test",
|
||||
device_id=device_has_label1.id,
|
||||
)
|
||||
entity_with_label1_from_device_and_different_area = er.RegistryEntry(
|
||||
entity_with_label1_from_device_and_different_area = RegistryEntryWithDefaults(
|
||||
entity_id="light.with_label1_from_device_diff_area",
|
||||
unique_id="with_label1_from_device_diff_area",
|
||||
platform="test",
|
||||
device_id=device_has_label1.id,
|
||||
area_id=area_without_labels.id,
|
||||
)
|
||||
entity_with_label1_and_label2_from_device = er.RegistryEntry(
|
||||
entity_with_label1_and_label2_from_device = RegistryEntryWithDefaults(
|
||||
entity_id="light.with_label1_and_label2_from_device",
|
||||
unique_id="with_label1_and_label2_from_device",
|
||||
platform="test",
|
||||
labels={"label1"},
|
||||
device_id=device_has_label2.id,
|
||||
)
|
||||
entity_with_labels_from_device = er.RegistryEntry(
|
||||
entity_with_labels_from_device = RegistryEntryWithDefaults(
|
||||
entity_id="light.with_labels_from_device",
|
||||
unique_id="with_labels_from_device",
|
||||
platform="test",
|
||||
device_id=device_has_labels.id,
|
||||
)
|
||||
entity_with_no_labels = er.RegistryEntry(
|
||||
entity_with_no_labels = RegistryEntryWithDefaults(
|
||||
entity_id="light.no_labels",
|
||||
unique_id="no_labels",
|
||||
platform="test",
|
||||
@@ -1697,7 +1698,7 @@ async def test_domain_control_unauthorized(
|
||||
mock_registry(
|
||||
hass,
|
||||
{
|
||||
"light.kitchen": er.RegistryEntry(
|
||||
"light.kitchen": RegistryEntryWithDefaults(
|
||||
entity_id="light.kitchen",
|
||||
unique_id="kitchen",
|
||||
platform="test_domain",
|
||||
@@ -1738,7 +1739,7 @@ async def test_domain_control_admin(
|
||||
mock_registry(
|
||||
hass,
|
||||
{
|
||||
"light.kitchen": er.RegistryEntry(
|
||||
"light.kitchen": RegistryEntryWithDefaults(
|
||||
entity_id="light.kitchen",
|
||||
unique_id="kitchen",
|
||||
platform="test_domain",
|
||||
@@ -1776,7 +1777,7 @@ async def test_domain_control_no_user(hass: HomeAssistant) -> None:
|
||||
mock_registry(
|
||||
hass,
|
||||
{
|
||||
"light.kitchen": er.RegistryEntry(
|
||||
"light.kitchen": RegistryEntryWithDefaults(
|
||||
entity_id="light.kitchen",
|
||||
unique_id="kitchen",
|
||||
platform="test_domain",
|
||||
|
||||
Reference in New Issue
Block a user