Support min()/max() as template function (#48996)
This commit is contained in:
parent
9368891b1b
commit
a610076001
2 changed files with 7 additions and 0 deletions
|
@ -1457,6 +1457,9 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||||
self.globals["timedelta"] = timedelta
|
self.globals["timedelta"] = timedelta
|
||||||
self.globals["strptime"] = strptime
|
self.globals["strptime"] = strptime
|
||||||
self.globals["urlencode"] = urlencode
|
self.globals["urlencode"] = urlencode
|
||||||
|
self.globals["max"] = max
|
||||||
|
self.globals["min"] = min
|
||||||
|
|
||||||
if hass is None:
|
if hass is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -567,11 +567,15 @@ def test_from_json(hass):
|
||||||
def test_min(hass):
|
def test_min(hass):
|
||||||
"""Test the min filter."""
|
"""Test the min filter."""
|
||||||
assert template.Template("{{ [1, 2, 3] | min }}", hass).async_render() == 1
|
assert template.Template("{{ [1, 2, 3] | min }}", hass).async_render() == 1
|
||||||
|
assert template.Template("{{ min([1, 2, 3]) }}", hass).async_render() == 1
|
||||||
|
assert template.Template("{{ min(1, 2, 3) }}", hass).async_render() == 1
|
||||||
|
|
||||||
|
|
||||||
def test_max(hass):
|
def test_max(hass):
|
||||||
"""Test the max filter."""
|
"""Test the max filter."""
|
||||||
assert template.Template("{{ [1, 2, 3] | max }}", hass).async_render() == 3
|
assert template.Template("{{ [1, 2, 3] | max }}", hass).async_render() == 3
|
||||||
|
assert template.Template("{{ max([1, 2, 3]) }}", hass).async_render() == 3
|
||||||
|
assert template.Template("{{ max(1, 2, 3) }}", hass).async_render() == 3
|
||||||
|
|
||||||
|
|
||||||
def test_ord(hass):
|
def test_ord(hass):
|
||||||
|
|
Loading…
Add table
Reference in a new issue