mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix template rounding
This commit is contained in:
parent
0b325b2b7d
commit
5c63862054
@ -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
|
||||
|
@ -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 }}'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user