From 41aff96375655f57333ea80ee3a1af7fc5dbe172 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 3 Oct 2016 10:46:31 +0200 Subject: [PATCH] Bugfix temp convert on none temp attribute / unittest for that (#3654) --- homeassistant/components/climate/__init__.py | 19 ++++++++++++++----- tests/components/climate/test_demo.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index f670cbc45e1..93330603828 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -58,6 +58,12 @@ ATTR_OPERATION_LIST = "operation_list" ATTR_SWING_MODE = "swing_mode" ATTR_SWING_LIST = "swing_list" +CONVERTIBLE_ATTRIBUTE = [ + ATTR_TEMPERATURE, + ATTR_TARGET_TEMP_LOW, + ATTR_TARGET_TEMP_HIGH, +] + _LOGGER = logging.getLogger(__name__) SET_AWAY_MODE_SCHEMA = vol.Schema({ @@ -239,11 +245,14 @@ def setup(hass, config): for climate in target_climate: kwargs = {} for value, temp in service.data.items(): - kwargs[value] = convert_temperature( - temp, - hass.config.units.temperature_unit, - climate.unit_of_measurement - ) + if value in CONVERTIBLE_ATTRIBUTE: + kwargs[value] = convert_temperature( + temp, + hass.config.units.temperature_unit, + climate.unit_of_measurement + ) + else: + kwargs[value] = temp climate.set_temperature(**kwargs) if climate.should_poll: diff --git a/tests/components/climate/test_demo.py b/tests/components/climate/test_demo.py index f44cb6aabf4..aa94bdf63c9 100644 --- a/tests/components/climate/test_demo.py +++ b/tests/components/climate/test_demo.py @@ -2,7 +2,7 @@ import unittest from homeassistant.util.unit_system import ( - METRIC_SYSTEM, + METRIC_SYSTEM ) from homeassistant.bootstrap import setup_component from homeassistant.components import climate @@ -12,6 +12,7 @@ from tests.common import get_test_home_assistant ENTITY_CLIMATE = 'climate.hvac' ENTITY_ECOBEE = 'climate.ecobee' +ENTITY_HEATPUMP = 'climate.heatpump' class TestDemoClimate(unittest.TestCase): @@ -68,6 +69,15 @@ class TestDemoClimate(unittest.TestCase): state = self.hass.states.get(ENTITY_CLIMATE) self.assertEqual(30.0, state.attributes.get('temperature')) + def test_set_only_target_temp_with_convert(self): + """Test the setting of the target temperature.""" + state = self.hass.states.get(ENTITY_HEATPUMP) + self.assertEqual(20, state.attributes.get('temperature')) + climate.set_temperature(self.hass, 21, ENTITY_HEATPUMP) + self.hass.block_till_done() + state = self.hass.states.get(ENTITY_HEATPUMP) + self.assertEqual(21.0, state.attributes.get('temperature')) + def test_set_target_temp_range(self): """Test the setting of the target temperature with range.""" state = self.hass.states.get(ENTITY_ECOBEE)