mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
[substitutions] fix jinja parsing strings that look like sets as sets (#11611)
This commit is contained in:
@@ -138,6 +138,7 @@ def _concat_nodes_override(values: Iterator[Any]) -> Any:
|
||||
values = chain(head, values)
|
||||
raw = "".join([str(v) for v in values])
|
||||
|
||||
result = None
|
||||
try:
|
||||
# Attempt to parse the concatenated string into a Python literal.
|
||||
# This allows expressions like "1 + 2" to be evaluated to the integer 3.
|
||||
@@ -145,11 +146,16 @@ def _concat_nodes_override(values: Iterator[Any]) -> Any:
|
||||
# fall back to returning the raw string. This is consistent with
|
||||
# Home Assistant's behavior when evaluating templates
|
||||
result = literal_eval(raw)
|
||||
except (ValueError, SyntaxError, MemoryError, TypeError):
|
||||
pass
|
||||
else:
|
||||
if isinstance(result, set):
|
||||
# Sets are not supported, return raw string
|
||||
return raw
|
||||
|
||||
if not isinstance(result, str):
|
||||
return result
|
||||
|
||||
except (ValueError, SyntaxError, MemoryError, TypeError):
|
||||
pass
|
||||
return raw
|
||||
|
||||
|
||||
|
||||
@@ -33,3 +33,4 @@ test_list:
|
||||
{{{ "x", "79"}, { "y", "82"}}}
|
||||
- '{{{"AA"}}}'
|
||||
- '"HELLO"'
|
||||
- '{ 79, 82 }'
|
||||
|
||||
@@ -34,3 +34,4 @@ test_list:
|
||||
{{{ "x", "${ position.x }"}, { "y", "${ position.y }"}}}
|
||||
- ${ '{{{"AA"}}}' }
|
||||
- ${ '"HELLO"' }
|
||||
- '{ ${position.x}, ${position.y} }'
|
||||
|
||||
Reference in New Issue
Block a user