Add guard for invalid EntityCategory value (#66316)

This commit is contained in:
Joakim Sørensen 2022-02-11 14:57:45 +01:00 committed by Paulus Schoutsen
parent 60b4600019
commit 27c5460feb
2 changed files with 16 additions and 1 deletions

View File

@ -223,7 +223,10 @@ def convert_to_entity_category(
"EntityCategory instead" % (type(value).__name__, value),
error_if_core=False,
)
return EntityCategory(value)
try:
return EntityCategory(value)
except ValueError:
return None
return value

View File

@ -1124,3 +1124,15 @@ async def test_deprecated_disabled_by_str(hass, registry, caplog):
assert entry.disabled_by is er.RegistryEntryDisabler.USER
assert " str for entity registry disabled_by. This is deprecated " in caplog.text
async def test_invalid_entity_category_str(hass, registry, caplog):
"""Test use of invalid entity category."""
entry = er.RegistryEntry(
"light",
"hue",
"5678",
entity_category="invalid",
)
assert entry.entity_category is None