mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
add min and max jinja filters (#5765)
This commit is contained in:
parent
1546ec7778
commit
7927a6b588
@ -425,6 +425,8 @@ ENV.filters['timestamp_custom'] = timestamp_custom
|
|||||||
ENV.filters['timestamp_local'] = timestamp_local
|
ENV.filters['timestamp_local'] = timestamp_local
|
||||||
ENV.filters['timestamp_utc'] = timestamp_utc
|
ENV.filters['timestamp_utc'] = timestamp_utc
|
||||||
ENV.filters['is_defined'] = fail_when_undefined
|
ENV.filters['is_defined'] = fail_when_undefined
|
||||||
|
ENV.filters['max'] = max
|
||||||
|
ENV.filters['min'] = min
|
||||||
ENV.globals['float'] = forgiving_float
|
ENV.globals['float'] = forgiving_float
|
||||||
ENV.globals['now'] = dt_util.now
|
ENV.globals['now'] = dt_util.now
|
||||||
ENV.globals['utcnow'] = dt_util.utcnow
|
ENV.globals['utcnow'] = dt_util.utcnow
|
||||||
|
@ -186,6 +186,20 @@ class TestHelpersTemplate(unittest.TestCase):
|
|||||||
template.Template('{{ %s | timestamp_local }}' % inp,
|
template.Template('{{ %s | timestamp_local }}' % inp,
|
||||||
self.hass).render())
|
self.hass).render())
|
||||||
|
|
||||||
|
def test_min(self):
|
||||||
|
"""Test the min filter."""
|
||||||
|
self.assertEqual(
|
||||||
|
'1',
|
||||||
|
template.Template('{{ [1, 2, 3] | min }}',
|
||||||
|
self.hass).render())
|
||||||
|
|
||||||
|
def test_max(self):
|
||||||
|
"""Test the max filter."""
|
||||||
|
self.assertEqual(
|
||||||
|
'3',
|
||||||
|
template.Template('{{ [1, 2, 3] | max }}',
|
||||||
|
self.hass).render())
|
||||||
|
|
||||||
def test_timestamp_utc(self):
|
def test_timestamp_utc(self):
|
||||||
"""Test the timestamps to local filter."""
|
"""Test the timestamps to local filter."""
|
||||||
tests = {
|
tests = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user