mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +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(
|
def convert_to_entity_category(
|
||||||
value: EntityCategory | str | None,
|
value: EntityCategory | str | None, raise_report: bool = True
|
||||||
) -> EntityCategory | None:
|
) -> EntityCategory | None:
|
||||||
"""Force incoming entity_category to be an enum."""
|
"""Force incoming entity_category to be an enum."""
|
||||||
|
|
||||||
@ -210,11 +210,13 @@ def convert_to_entity_category(
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
if not isinstance(value, EntityCategory):
|
if not isinstance(value, EntityCategory):
|
||||||
report(
|
if raise_report:
|
||||||
"An entity_category should only be assigned an enum. Strings or other assignments are deprecated. Value %s is type %s"
|
report(
|
||||||
% (value, type(value)),
|
"uses %s (%s) for entity category. This is deprecated and will "
|
||||||
error_if_core=False,
|
"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 EntityCategory(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -94,13 +94,13 @@ DISABLED_USER = RegistryEntryDisabler.USER.value
|
|||||||
|
|
||||||
|
|
||||||
def _convert_to_entity_category(
|
def _convert_to_entity_category(
|
||||||
value: EntityCategory | str | None,
|
value: EntityCategory | str | None, raise_report: bool = True
|
||||||
) -> EntityCategory | None:
|
) -> EntityCategory | None:
|
||||||
"""Force incoming entity_category to be an enum."""
|
"""Force incoming entity_category to be an enum."""
|
||||||
# pylint: disable=import-outside-toplevel
|
# pylint: disable=import-outside-toplevel
|
||||||
from .entity import convert_to_entity_category
|
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)
|
@attr.s(slots=True, frozen=True)
|
||||||
@ -398,7 +398,7 @@ class EntityRegistry:
|
|||||||
config_entry_id=config_entry_id,
|
config_entry_id=config_entry_id,
|
||||||
device_id=device_id,
|
device_id=device_id,
|
||||||
disabled_by=disabled_by,
|
disabled_by=disabled_by,
|
||||||
entity_category=entity_category,
|
entity_category=_convert_to_entity_category(entity_category),
|
||||||
entity_id=entity_id,
|
entity_id=entity_id,
|
||||||
original_device_class=original_device_class,
|
original_device_class=original_device_class,
|
||||||
original_icon=original_icon,
|
original_icon=original_icon,
|
||||||
@ -628,7 +628,9 @@ class EntityRegistry:
|
|||||||
disabled_by=RegistryEntryDisabler(entity["disabled_by"])
|
disabled_by=RegistryEntryDisabler(entity["disabled_by"])
|
||||||
if entity["disabled_by"]
|
if entity["disabled_by"]
|
||||||
else None,
|
else None,
|
||||||
entity_category=entity["entity_category"],
|
entity_category=_convert_to_entity_category(
|
||||||
|
entity["entity_category"], raise_report=False
|
||||||
|
),
|
||||||
entity_id=entity["entity_id"],
|
entity_id=entity["entity_id"],
|
||||||
icon=entity["icon"],
|
icon=entity["icon"],
|
||||||
id=entity["id"],
|
id=entity["id"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user