mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Enable jinja loop controls (break/continue) (#88625)
Enables jinja loop controls (break/continue)
This commit is contained in:
parent
9575cd9161
commit
af49b98475
@ -2063,6 +2063,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||
self.template_cache: weakref.WeakValueDictionary[
|
||||
str | jinja2.nodes.Template, CodeType | str | None
|
||||
] = weakref.WeakValueDictionary()
|
||||
self.add_extension("jinja2.ext.loopcontrols")
|
||||
self.filters["round"] = forgiving_round
|
||||
self.filters["multiply"] = multiply
|
||||
self.filters["log"] = logarithm
|
||||
|
@ -243,6 +243,26 @@ def test_iterating_domain_states(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_loop_controls(hass: HomeAssistant) -> None:
|
||||
"""Test that loop controls are enabled."""
|
||||
assert (
|
||||
template.Template(
|
||||
"""
|
||||
{%- for v in range(10) %}
|
||||
{%- if v == 1 -%}
|
||||
{%- continue -%}
|
||||
{%- elif v == 3 -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{{ v }}
|
||||
{%- endfor -%}
|
||||
""",
|
||||
hass,
|
||||
).async_render()
|
||||
== "02"
|
||||
)
|
||||
|
||||
|
||||
def test_float_function(hass: HomeAssistant) -> None:
|
||||
"""Test float function."""
|
||||
hass.states.async_set("sensor.temperature", "12")
|
||||
|
Loading…
x
Reference in New Issue
Block a user