Add bitwise operations as template helpers (#16833)

This commit is contained in:
Blake Blackshear authored and Pascal Vizeli committed 2018-09-26 11:57:16 +02:00
1 parent 75c372021d
commit f13f723a04
2 files changed
+42

No files matched your search

+30
View File
@@ -562,6 +562,36 @@ class TestHelpersTemplate(unittest.TestCase):
""", self.hass)
self.assertEqual('LHR', tpl.render())
def test_bitwise_and(self):
"""Test bitwise_and method."""
tpl = template.Template("""
{{ 8 | bitwise_and(8) }}
""", self.hass)
self.assertEqual(str(8 & 8), tpl.render())
tpl = template.Template("""
{{ 10 | bitwise_and(2) }}
""", self.hass)
self.assertEqual(str(10 & 2), tpl.render())
tpl = template.Template("""
{{ 8 | bitwise_and(2) }}
""", self.hass)
self.assertEqual(str(8 & 2), tpl.render())
def test_bitwise_or(self):
"""Test bitwise_or method."""
tpl = template.Template("""
{{ 8 | bitwise_or(8) }}
""", self.hass)
self.assertEqual(str(8 | 8), tpl.render())
tpl = template.Template("""
{{ 10 | bitwise_or(2) }}
""", self.hass)
self.assertEqual(str(10 | 2), tpl.render())
tpl = template.Template("""
{{ 8 | bitwise_or(2) }}
""", self.hass)
self.assertEqual(str(8 | 2), tpl.render())
def test_distance_function_with_1_state(self):
"""Test distance function with 1 state."""
self.hass.states.set('test.object', 'happy', {