diff --git a/homeassistant/util/template.py b/homeassistant/util/template.py index 6fa4b6d55bf..30b90f85144 100644 --- a/homeassistant/util/template.py +++ b/homeassistant/util/template.py @@ -162,7 +162,7 @@ def multiply(value, amount): """Filter to convert value to float and multiply it.""" try: return float(value) * amount - except ValueError: + except (ValueError, TypeError): # If value can't be converted to float return value diff --git a/tests/util/test_template.py b/tests/util/test_template.py index d6882c9a219..c6c5f18f01c 100644 --- a/tests/util/test_template.py +++ b/tests/util/test_template.py @@ -84,6 +84,19 @@ class TestUtilTemplate(unittest.TestCase): '{{ "no_number" | round }}' )) + def test_multiply(self): + tests = { + None: 'None', + 10: '100', + '"abcd"': 'abcd' + } + + for inp, out in tests.items(): + self.assertEqual( + out, + template.render(self.hass, + '{{ %s | multiply(10) | round }}' % inp)) + def test_passing_vars_as_keywords(self): self.assertEqual( '127', template.render(self.hass, '{{ hello }}', hello=127))