Daikin AC : Round to nearest half degree (#70446) (#70452)

This commit is contained in:
Johann Vanackere 2022-04-24 23:47:09 +02:00 committed by Paulus Schoutsen
parent 6f6b16b410
commit 9925a19a75
2 changed files with 10 additions and 10 deletions

View file

@ -118,8 +118,8 @@ async def async_setup_entry(
def format_target_temperature(target_temperature):
"""Format target temperature to be sent to the Daikin unit, taking care of keeping at most 1 decimal digit."""
return str(round(float(target_temperature), 1)).rstrip("0").rstrip(".")
"""Format target temperature to be sent to the Daikin unit, rounding to nearest half degree."""
return str(round(float(target_temperature) * 2, 0) / 2).rstrip("0").rstrip(".")
class DaikinClimate(ClimateEntity):

View file

@ -8,13 +8,13 @@ def test_int_conversion():
assert formatted == "16"
def test_decimal_conversion():
def test_rounding():
"""Check 1 decimal is kept when target temp is a decimal."""
formatted = format_target_temperature("16.1")
assert formatted == "16.1"
def test_decimal_conversion_more_digits():
"""Check at most 1 decimal is kept when target temp is a decimal with more than 1 decimal."""
formatted = format_target_temperature("16.09")
assert formatted == "16.1"
assert formatted == "16"
formatted = format_target_temperature("16.3")
assert formatted == "16.5"
formatted = format_target_temperature("16.65")
assert formatted == "16.5"
formatted = format_target_temperature("16.9")
assert formatted == "17"