mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Don't report entities with invalid unique id when loading the entity registry (#118290)
This commit is contained in:
parent
4d7b1288d1
commit
7abffd7cc8
@ -618,17 +618,22 @@ def _validate_item(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
domain: str,
|
domain: str,
|
||||||
platform: str,
|
platform: str,
|
||||||
unique_id: str | Hashable | UndefinedType | Any,
|
|
||||||
*,
|
*,
|
||||||
disabled_by: RegistryEntryDisabler | None | UndefinedType = None,
|
disabled_by: RegistryEntryDisabler | None | UndefinedType = None,
|
||||||
entity_category: EntityCategory | None | UndefinedType = None,
|
entity_category: EntityCategory | None | UndefinedType = None,
|
||||||
hidden_by: RegistryEntryHider | None | UndefinedType = None,
|
hidden_by: RegistryEntryHider | None | UndefinedType = None,
|
||||||
|
report_non_string_unique_id: bool = True,
|
||||||
|
unique_id: str | Hashable | UndefinedType | Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Validate entity registry item."""
|
"""Validate entity registry item."""
|
||||||
if unique_id is not UNDEFINED and not isinstance(unique_id, Hashable):
|
if unique_id is not UNDEFINED and not isinstance(unique_id, Hashable):
|
||||||
raise TypeError(f"unique_id must be a string, got {unique_id}")
|
raise TypeError(f"unique_id must be a string, got {unique_id}")
|
||||||
if unique_id is not UNDEFINED and not isinstance(unique_id, str):
|
if (
|
||||||
# In HA Core 2025.4, we should fail if unique_id is not a string
|
report_non_string_unique_id
|
||||||
|
and unique_id is not UNDEFINED
|
||||||
|
and not isinstance(unique_id, str)
|
||||||
|
):
|
||||||
|
# In HA Core 2025.10, we should fail if unique_id is not a string
|
||||||
report_issue = async_suggest_report_issue(hass, integration_domain=platform)
|
report_issue = async_suggest_report_issue(hass, integration_domain=platform)
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
("'%s' from integration %s has a non string unique_id" " '%s', please %s"),
|
("'%s' from integration %s has a non string unique_id" " '%s', please %s"),
|
||||||
@ -1227,7 +1232,11 @@ class EntityRegistry(BaseRegistry):
|
|||||||
try:
|
try:
|
||||||
domain = split_entity_id(entity["entity_id"])[0]
|
domain = split_entity_id(entity["entity_id"])[0]
|
||||||
_validate_item(
|
_validate_item(
|
||||||
self.hass, domain, entity["platform"], entity["unique_id"]
|
self.hass,
|
||||||
|
domain,
|
||||||
|
entity["platform"],
|
||||||
|
report_non_string_unique_id=False,
|
||||||
|
unique_id=entity["unique_id"],
|
||||||
)
|
)
|
||||||
except (TypeError, ValueError) as err:
|
except (TypeError, ValueError) as err:
|
||||||
report_issue = async_suggest_report_issue(
|
report_issue = async_suggest_report_issue(
|
||||||
@ -1283,7 +1292,11 @@ class EntityRegistry(BaseRegistry):
|
|||||||
try:
|
try:
|
||||||
domain = split_entity_id(entity["entity_id"])[0]
|
domain = split_entity_id(entity["entity_id"])[0]
|
||||||
_validate_item(
|
_validate_item(
|
||||||
self.hass, domain, entity["platform"], entity["unique_id"]
|
self.hass,
|
||||||
|
domain,
|
||||||
|
entity["platform"],
|
||||||
|
report_non_string_unique_id=False,
|
||||||
|
unique_id=entity["unique_id"],
|
||||||
)
|
)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
continue
|
continue
|
||||||
|
@ -511,7 +511,7 @@ async def test_load_bad_data(
|
|||||||
"id": "00003",
|
"id": "00003",
|
||||||
"orphaned_timestamp": None,
|
"orphaned_timestamp": None,
|
||||||
"platform": "super_platform",
|
"platform": "super_platform",
|
||||||
"unique_id": 234, # Should trigger warning
|
"unique_id": 234, # Should not load
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"config_entry_id": None,
|
"config_entry_id": None,
|
||||||
@ -536,7 +536,11 @@ async def test_load_bad_data(
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
"'test' from integration super_platform has a non string unique_id '123', "
|
"'test' from integration super_platform has a non string unique_id '123', "
|
||||||
"please create a bug report" in caplog.text
|
"please create a bug report" not in caplog.text
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
"'test' from integration super_platform has a non string unique_id '234', "
|
||||||
|
"please create a bug report" not in caplog.text
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"Entity registry entry 'test.test2' from integration super_platform could not "
|
"Entity registry entry 'test.test2' from integration super_platform could not "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user