From 5c63862054078224c01409fbb8b1f2df7de6ecb1 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 11 Dec 2015 18:45:53 -0800 Subject: [PATCH] Fix template rounding --- homeassistant/util/template.py | 4 ++-- tests/util/test_template.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/util/template.py b/homeassistant/util/template.py index 107532db776..bc89d053e60 100644 --- a/homeassistant/util/template.py +++ b/homeassistant/util/template.py @@ -66,8 +66,8 @@ class DomainStates(object): def forgiving_round(value, precision=0): """ Rounding method that accepts strings. """ try: - return int(float(value)) if precision == 0 else round(float(value), - precision) + value = round(float(value), precision) + return int(value) if precision == 0 else value except ValueError: # 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 5c1dfff1f85..bbb4de31626 100644 --- a/tests/util/test_template.py +++ b/tests/util/test_template.py @@ -57,10 +57,10 @@ class TestUtilTemplate(unittest.TestCase): '{{ states.sensor.temperature.state | round(1) }}')) def test_rounding_value2(self): - self.hass.states.set('sensor.temperature', 12.72) + self.hass.states.set('sensor.temperature', 12.78) self.assertEqual( - '127', + '128', template.render( self.hass, '{{ states.sensor.temperature.state | multiply(10) | round }}'))