mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
parent
b049ffca23
commit
b0ed42a5a5
@ -117,6 +117,11 @@ async def async_setup_entry(
|
|||||||
async_add_entities([DaikinClimate(daikin_api)], update_before_add=True)
|
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):
|
class DaikinClimate(ClimateEntity):
|
||||||
"""Representation of a Daikin HVAC."""
|
"""Representation of a Daikin HVAC."""
|
||||||
|
|
||||||
@ -163,9 +168,9 @@ class DaikinClimate(ClimateEntity):
|
|||||||
# temperature
|
# temperature
|
||||||
elif attr == ATTR_TEMPERATURE:
|
elif attr == ATTR_TEMPERATURE:
|
||||||
try:
|
try:
|
||||||
values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = str(
|
values[
|
||||||
round(float(value), 1)
|
HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]
|
||||||
)
|
] = format_target_temperature(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.error("Invalid temperature %s", value)
|
_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…
x
Reference in New Issue
Block a user