From fe75a1bb9de0ce5f1d01d30d00127095ae0a2d69 Mon Sep 17 00:00:00 2001 From: jjlawren <jjlawren@users.noreply.github.com> Date: Tue, 25 May 2021 12:32:59 -0500 Subject: [PATCH] Set Fahrenheit reporting precision to tenths for Homekit Controller climate entities (#50415) --- .../components/homekit_controller/climate.py | 12 +++++++++++- tests/components/homekit_controller/test_climate.py | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/homekit_controller/climate.py b/homeassistant/components/homekit_controller/climate.py index 2c251d41fb3..a2c9c2540ac 100644 --- a/homeassistant/components/homekit_controller/climate.py +++ b/homeassistant/components/homekit_controller/climate.py @@ -36,7 +36,7 @@ from homeassistant.components.climate.const import ( SWING_OFF, SWING_VERTICAL, ) -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, TEMP_CELSIUS from homeassistant.core import callback from . import KNOWN_DEVICES, HomeKitEntity @@ -323,6 +323,11 @@ class HomeKitHeaterCoolerEntity(HomeKitEntity, ClimateEntity): """Return the unit of measurement.""" return TEMP_CELSIUS + @property + def precision(self): + """Return the precision of the system.""" + return PRECISION_TENTHS + class HomeKitClimateEntity(HomeKitEntity, ClimateEntity): """Representation of a Homekit climate device.""" @@ -536,6 +541,11 @@ class HomeKitClimateEntity(HomeKitEntity, ClimateEntity): """Return the unit of measurement.""" return TEMP_CELSIUS + @property + def precision(self): + """Return the precision of the system.""" + return PRECISION_TENTHS + ENTITY_TYPES = { ServicesTypes.HEATER_COOLER: HomeKitHeaterCoolerEntity, diff --git a/tests/components/homekit_controller/test_climate.py b/tests/components/homekit_controller/test_climate.py index 52671703cca..bc9fdaa1013 100644 --- a/tests/components/homekit_controller/test_climate.py +++ b/tests/components/homekit_controller/test_climate.py @@ -1,4 +1,6 @@ """Basic checks for HomeKitclimate.""" +from unittest.mock import patch + from aiohomekit.model.characteristics import ( ActivationStateValues, CharacteristicsTypes, @@ -19,6 +21,7 @@ from homeassistant.components.climate.const import ( SERVICE_SET_SWING_MODE, SERVICE_SET_TEMPERATURE, ) +from homeassistant.const import TEMP_FAHRENHEIT from tests.components.homekit_controller.common import setup_test_component @@ -445,6 +448,11 @@ async def test_climate_read_thermostat_state(hass, utcnow): state = await helper.poll_and_get_state() assert state.state == HVAC_MODE_HEAT_COOL + # Ensure converted Fahrenheit precision is reported in tenths + with patch.object(hass.config.units, "temperature_unit", TEMP_FAHRENHEIT): + state = await helper.poll_and_get_state() + assert state.attributes["current_temperature"] == 69.8 + async def test_hvac_mode_vs_hvac_action(hass, utcnow): """Check that we haven't conflated hvac_mode and hvac_action."""