From c6b08b28b2e07d02d3c6d1e3279dad36295c8a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Gonz=C3=A1lez=20Calleja?= Date: Fri, 4 Oct 2019 02:44:07 +0200 Subject: [PATCH] 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 --- homeassistant/components/homekit/type_sensors.py | 2 +- homeassistant/components/homekit/util.py | 2 +- tests/components/homekit/test_type_thermostats.py | 6 +++--- tests/components/homekit/test_util.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/homekit/type_sensors.py b/homeassistant/components/homekit/type_sensors.py index 87c8d5247a5..a1450518e0c 100644 --- a/homeassistant/components/homekit/type_sensors.py +++ b/homeassistant/components/homekit/type_sensors.py @@ -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 ) diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index d60c94d420d..608c9a974e5 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -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): diff --git a/tests/components/homekit/test_type_thermostats.py b/tests/components/homekit/test_type_thermostats.py index d967d325561..8ad46e489d6 100644 --- a/tests/components/homekit/test_type_thermostats.py +++ b/tests/components/homekit/test_type_thermostats.py @@ -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 diff --git a/tests/components/homekit/test_util.py b/tests/components/homekit/test_util.py index 923cbaca42f..8898f988f9a 100644 --- a/tests/components/homekit/test_util.py +++ b/tests/components/homekit/test_util.py @@ -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():