Fix template rounding

This commit is contained in:
Paulus Schoutsen 2015-12-11 18:45:53 -08:00
parent 0b325b2b7d
commit 5c63862054
2 changed files with 4 additions and 4 deletions

View File

@ -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

View File

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