Fix homekit temperaturesensor round (#27047)

* Fix homekit temperature sensor for round with one decimal

* Removing unnecesary operations

* Adapting tests for new temperature_to_homekit() result precision
This commit is contained in:
Javier González Calleja 2019-10-04 02:44:07 +02:00 committed by Paulus Schoutsen
parent 85947591c5
commit c6b08b28b2
4 changed files with 6 additions and 6 deletions

View file

@ -96,7 +96,7 @@ class TemperatureSensor(HomeAccessory):
temperature = temperature_to_homekit(temperature, unit)
self.char_temp.set_value(temperature)
_LOGGER.debug(
"%s: Current temperature set to %d°C", self.entity_id, temperature
"%s: Current temperature set to %.1f°C", self.entity_id, temperature
)

View file

@ -235,7 +235,7 @@ def convert_to_float(state):
def temperature_to_homekit(temperature, unit):
"""Convert temperature to Celsius for HomeKit."""
return round(temp_util.convert(temperature, unit, TEMP_CELSIUS) * 2) / 2
return round(temp_util.convert(temperature, unit, TEMP_CELSIUS), 1)
def temperature_to_states(temperature, unit):

View file

@ -96,10 +96,10 @@ async def test_thermostat(hass, hk_driver, cls, events):
},
)
await hass.async_block_till_done()
assert acc.char_target_temp.value == 22.0
assert acc.char_target_temp.value == 22.2
assert acc.char_current_heat_cool.value == 1
assert acc.char_target_heat_cool.value == 1
assert acc.char_current_temp.value == 18.0
assert acc.char_current_temp.value == 17.8
assert acc.char_display_units.value == 0
hass.states.async_set(
@ -432,7 +432,7 @@ async def test_thermostat_fahrenheit(hass, hk_driver, cls, events):
)
await hass.async_block_till_done()
assert acc.get_temperature_range() == (7.0, 35.0)
assert acc.char_heating_thresh_temp.value == 20.0
assert acc.char_heating_thresh_temp.value == 20.1
assert acc.char_cooling_thresh_temp.value == 24.0
assert acc.char_current_temp.value == 23.0
assert acc.char_target_temp.value == 22.0

View file

@ -173,7 +173,7 @@ def test_convert_to_float():
def test_temperature_to_homekit():
"""Test temperature conversion from HA to HomeKit."""
assert temperature_to_homekit(20.46, TEMP_CELSIUS) == 20.5
assert temperature_to_homekit(92.1, TEMP_FAHRENHEIT) == 33.5
assert temperature_to_homekit(92.1, TEMP_FAHRENHEIT) == 33.4
def test_temperature_to_states():