mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +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):
|
def forgiving_round(value, precision=0):
|
||||||
""" Rounding method that accepts strings. """
|
""" Rounding method that accepts strings. """
|
||||||
try:
|
try:
|
||||||
return int(float(value)) if precision == 0 else round(float(value),
|
value = round(float(value), precision)
|
||||||
precision)
|
return int(value) if precision == 0 else value
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# If value can't be converted to float
|
# If value can't be converted to float
|
||||||
return value
|
return value
|
||||||
|
@ -57,10 +57,10 @@ class TestUtilTemplate(unittest.TestCase):
|
|||||||
'{{ states.sensor.temperature.state | round(1) }}'))
|
'{{ states.sensor.temperature.state | round(1) }}'))
|
||||||
|
|
||||||
def test_rounding_value2(self):
|
def test_rounding_value2(self):
|
||||||
self.hass.states.set('sensor.temperature', 12.72)
|
self.hass.states.set('sensor.temperature', 12.78)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'127',
|
'128',
|
||||||
template.render(
|
template.render(
|
||||||
self.hass,
|
self.hass,
|
||||||
'{{ states.sensor.temperature.state | multiply(10) | round }}'))
|
'{{ states.sensor.temperature.state | multiply(10) | round }}'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user