Address late review in entity registry (#64851)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-24 22:42:38 +01:00 committed by GitHub
parent 6af7425051
commit f662e8669e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -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

View File

@ -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"],