1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 08:41:59 +00:00
This commit is contained in:
J. Nick Koston
2025-12-22 20:10:36 -10:00
parent 9f2d2eed8c
commit e13f48b348

View File

@@ -276,12 +276,17 @@ def extract_object_id_from_expressions(expressions: list[str]) -> str | None:
Since object_id is now computed from the name (via snake_case + sanitize),
we extract the name from set_name() calls and compute the expected object_id.
For empty names, we fall back to CORE.friendly_name or CORE.name.
"""
for expr in expressions:
if match := SET_NAME_PATTERN.search(expr):
name = match.group(1)
# Compute object_id the same way as get_base_entity_object_id
return sanitize(snake_case(name)) if name else None
if name:
return sanitize(snake_case(name))
# Empty name - fall back to friendly_name or device name
if CORE.friendly_name:
return sanitize(snake_case(CORE.friendly_name))
return sanitize(snake_case(CORE.name)) if CORE.name else None
return None