mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Address late review in entity registry (#64851)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
6af7425051
commit
f662e8669e
@ -202,7 +202,7 @@ class EntityCategory(StrEnum):
|
||||
|
||||
|
||||
def convert_to_entity_category(
|
||||
value: EntityCategory | str | None,
|
||||
value: EntityCategory | str | None, raise_report: bool = True
|
||||
) -> EntityCategory | None:
|
||||
"""Force incoming entity_category to be an enum."""
|
||||
|
||||
@ -210,11 +210,13 @@ def convert_to_entity_category(
|
||||
return value
|
||||
|
||||
if not isinstance(value, EntityCategory):
|
||||
report(
|
||||
"An entity_category should only be assigned an enum. Strings or other assignments are deprecated. Value %s is type %s"
|
||||
% (value, type(value)),
|
||||
error_if_core=False,
|
||||
)
|
||||
if raise_report:
|
||||
report(
|
||||
"uses %s (%s) for entity category. This is deprecated and will "
|
||||
"stop working in Home Assistant 2022.4, it should be updated to use "
|
||||
"EntityCategory instead" % (type(value).__name__, value),
|
||||
error_if_core=False,
|
||||
)
|
||||
return EntityCategory(value)
|
||||
return value
|
||||
|
||||
|
@ -94,13 +94,13 @@ DISABLED_USER = RegistryEntryDisabler.USER.value
|
||||
|
||||
|
||||
def _convert_to_entity_category(
|
||||
value: EntityCategory | str | None,
|
||||
value: EntityCategory | str | None, raise_report: bool = True
|
||||
) -> EntityCategory | None:
|
||||
"""Force incoming entity_category to be an enum."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from .entity import convert_to_entity_category
|
||||
|
||||
return convert_to_entity_category(value)
|
||||
return convert_to_entity_category(value, raise_report=raise_report)
|
||||
|
||||
|
||||
@attr.s(slots=True, frozen=True)
|
||||
@ -398,7 +398,7 @@ class EntityRegistry:
|
||||
config_entry_id=config_entry_id,
|
||||
device_id=device_id,
|
||||
disabled_by=disabled_by,
|
||||
entity_category=entity_category,
|
||||
entity_category=_convert_to_entity_category(entity_category),
|
||||
entity_id=entity_id,
|
||||
original_device_class=original_device_class,
|
||||
original_icon=original_icon,
|
||||
@ -628,7 +628,9 @@ class EntityRegistry:
|
||||
disabled_by=RegistryEntryDisabler(entity["disabled_by"])
|
||||
if entity["disabled_by"]
|
||||
else None,
|
||||
entity_category=entity["entity_category"],
|
||||
entity_category=_convert_to_entity_category(
|
||||
entity["entity_category"], raise_report=False
|
||||
),
|
||||
entity_id=entity["entity_id"],
|
||||
icon=entity["icon"],
|
||||
id=entity["id"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user