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 }}'))