Fix #69952: Daikin AC Temperature jumps after being set (#70326)

This commit is contained in:
Johann Vanackere 2022-04-20 19:43:44 +02:00 committed by GitHub
parent b049ffca23
commit b0ed42a5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View file

@ -117,6 +117,11 @@ async def async_setup_entry(
async_add_entities([DaikinClimate(daikin_api)], update_before_add=True)
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(".")
class DaikinClimate(ClimateEntity):
"""Representation of a Daikin HVAC."""
@ -163,9 +168,9 @@ class DaikinClimate(ClimateEntity):
# temperature
elif attr == ATTR_TEMPERATURE:
try:
values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = str(
round(float(value), 1)
)
values[
HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]
] = format_target_temperature(value)
except ValueError:
_LOGGER.error("Invalid temperature %s", value)

View file

@ -0,0 +1,20 @@
"""The tests for the Daikin target temperature conversion."""
from homeassistant.components.daikin.climate import format_target_temperature
def test_int_conversion():
"""Check no decimal are kept when target temp is an integer."""
formatted = format_target_temperature("16")
assert formatted == "16"
def test_decimal_conversion():
"""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"