From 3512d05467abe4d8daa4b8ca4b4d8746fceea650 Mon Sep 17 00:00:00 2001 From: aschamberger Date: Fri, 26 Jul 2019 00:06:51 +0200 Subject: [PATCH] Add ord() to template filters (#25398) * Add ord() to template filters * Remove trailing whitespace * add test --- homeassistant/helpers/template.py | 1 + tests/helpers/test_template.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 6149f28b50b..203a0f24fad 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -857,6 +857,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): self.filters['regex_findall_index'] = regex_findall_index self.filters['bitwise_and'] = bitwise_and self.filters['bitwise_or'] = bitwise_or + self.filters['ord'] = ord self.globals['log'] = logarithm self.globals['sin'] = sine self.globals['cos'] = cosine diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index f7e4e7dd2ec..9cc688de32e 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -388,6 +388,12 @@ def test_max(hass): hass).async_render() == '3' +def test_ord(hass): + """Test the ord filter.""" + assert template.Template('{{ "d" | ord }}', + hass).async_render() == '100' + + def test_base64_encode(hass): """Test the base64_encode filter.""" assert template.Template('{{ "homeassistant" | base64_encode }}',