[substitutions] !include ${filename}, Substitutions in include filename paths (package refactor part 5) (#12213)

Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Javier Peletier
2026-04-07 15:12:55 -10:00
committed by GitHub
co-authored by J. Nick Koston J. Nick Koston
parent 801f3fadaa
commit d20d613c1d
14 changed files with 562 additions and 53 deletions
+25
View File
@@ -0,0 +1,25 @@
"""Helpers for detecting substitution variables and Jinja expressions."""
import re
from esphome.const import VALID_SUBSTITUTIONS_CHARACTERS
SUBSTITUTION_VARIABLE_PROG = re.compile(
rf"\$([{VALID_SUBSTITUTIONS_CHARACTERS}]+|\{{[{VALID_SUBSTITUTIONS_CHARACTERS}]*\}})"
)
_JINJA_RE = re.compile(
r"<%.+?%>" # Block: <% ... %>
r"|\$\{[^}]+\}", # Braced: ${ ... }
flags=re.MULTILINE,
)
def has_jinja(value: str) -> bool:
"""Check if a string contains Jinja expressions."""
return _JINJA_RE.search(value) is not None
def has_substitution_or_expression(value: str) -> bool:
"""Check if a string contains substitution variables ($name, ${name}) or Jinja expressions."""
return SUBSTITUTION_VARIABLE_PROG.search(value) is not None or has_jinja(value)