Add guard for invalid EntityCategory value (#66316)
This commit is contained in:
parent
1c087f5c70
commit
7a40ae13a4
2 changed files with 16 additions and 1 deletions
|
@ -223,7 +223,10 @@ def convert_to_entity_category(
|
||||||
"EntityCategory instead" % (type(value).__name__, value),
|
"EntityCategory instead" % (type(value).__name__, value),
|
||||||
error_if_core=False,
|
error_if_core=False,
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
return EntityCategory(value)
|
return EntityCategory(value)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1138,3 +1138,15 @@ async def test_deprecated_entity_category_str(hass, registry, caplog):
|
||||||
|
|
||||||
assert entry.entity_category is EntityCategory.DIAGNOSTIC
|
assert entry.entity_category is EntityCategory.DIAGNOSTIC
|
||||||
assert " should be updated to use EntityCategory" in caplog.text
|
assert " should be updated to use EntityCategory" 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue