parent
b049ffca23
commit
b0ed42a5a5
2 changed files with 28 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
20
tests/components/daikin/test_temperature_format.py
Normal file
20
tests/components/daikin/test_temperature_format.py
Normal 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"
|
Loading…
Add table
Reference in a new issue