add min and max jinja filters (#5765)

This commit is contained in:
Stéphane Bidoul (ACSONE) 2017-02-07 09:25:47 +01:00 committed by Paulus Schoutsen
parent 1546ec7778
commit 7927a6b588
2 changed files with 16 additions and 0 deletions

View File

@ -425,6 +425,8 @@ ENV.filters['timestamp_custom'] = timestamp_custom
ENV.filters['timestamp_local'] = timestamp_local
ENV.filters['timestamp_utc'] = timestamp_utc
ENV.filters['is_defined'] = fail_when_undefined
ENV.filters['max'] = max
ENV.filters['min'] = min
ENV.globals['float'] = forgiving_float
ENV.globals['now'] = dt_util.now
ENV.globals['utcnow'] = dt_util.utcnow

View File

@ -186,6 +186,20 @@ class TestHelpersTemplate(unittest.TestCase):
template.Template('{{ %s | timestamp_local }}' % inp,
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):
"""Test the timestamps to local filter."""
tests = {