From 6694b0470ec7a0b84f5e3e297d96e2ea951a01a2 Mon Sep 17 00:00:00 2001 From: John Arild Berentsen Date: Tue, 27 Sep 2016 19:34:16 +0200 Subject: [PATCH] Update Climate slider code (#3394) * Update ecobee to use only range setpoints * Update nest to only use range setpoints * Update demo to use only range for ecobee test device * Update test * Fetch unit from ecobee * generic_thermostat did not have state * generic_thermostat test update --- homeassistant/components/climate/demo.py | 2 +- homeassistant/components/climate/ecobee.py | 20 ++----- .../components/climate/generic_thermostat.py | 2 +- homeassistant/components/climate/nest.py | 60 +++++-------------- tests/components/climate/test_demo.py | 15 +++-- .../climate/test_generic_thermostat.py | 2 +- 6 files changed, 33 insertions(+), 68 deletions(-) diff --git a/homeassistant/components/climate/demo.py b/homeassistant/components/climate/demo.py index cb85a153cc8..51346e62269 100644 --- a/homeassistant/components/climate/demo.py +++ b/homeassistant/components/climate/demo.py @@ -16,7 +16,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): None, None, "Auto", "heat", None, None, None), DemoClimate("Hvac", 21, TEMP_CELSIUS, True, 22, "On High", 67, 54, "Off", "cool", False, None, None), - DemoClimate("Ecobee", 23, TEMP_CELSIUS, None, 23, "Auto Low", + DemoClimate("Ecobee", None, TEMP_CELSIUS, None, 23, "Auto Low", None, None, "Auto", "auto", None, 24, 21) ]) diff --git a/homeassistant/components/climate/ecobee.py b/homeassistant/components/climate/ecobee.py index 8c090818442..10e56490c84 100644 --- a/homeassistant/components/climate/ecobee.py +++ b/homeassistant/components/climate/ecobee.py @@ -14,7 +14,7 @@ from homeassistant.components.climate import ( DOMAIN, STATE_COOL, STATE_HEAT, STATE_IDLE, ClimateDevice, ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH) from homeassistant.const import ( - ATTR_ENTITY_ID, STATE_OFF, STATE_ON, TEMP_FAHRENHEIT, ATTR_TEMPERATURE) + ATTR_ENTITY_ID, STATE_OFF, STATE_ON, TEMP_FAHRENHEIT, TEMP_CELSIUS) from homeassistant.config import load_yaml_config_file import homeassistant.helpers.config_validation as cv @@ -107,22 +107,16 @@ class Thermostat(ClimateDevice): @property def unit_of_measurement(self): """Return the unit of measurement.""" - return TEMP_FAHRENHEIT + if self.thermostat['settings']['useCelsius']: + return TEMP_CELSIUS + else: + return TEMP_FAHRENHEIT @property def current_temperature(self): """Return the current temperature.""" return self.thermostat['runtime']['actualTemperature'] / 10 - @property - def target_temperature(self): - """Return the temperature we try to reach.""" - if (self.operation_mode == 'heat' or - self.operation_mode == 'auxHeatOnly'): - return self.target_temperature_low - elif self.operation_mode == 'cool': - return self.target_temperature_high - @property def target_temperature_low(self): """Return the lower bound temperature we try to reach.""" @@ -226,10 +220,6 @@ class Thermostat(ClimateDevice): def set_temperature(self, **kwargs): """Set new target temperature.""" - if kwargs.get(ATTR_TEMPERATURE) is not None: - temperature = kwargs.get(ATTR_TEMPERATURE) - low_temp = int(temperature) - high_temp = int(temperature) if kwargs.get(ATTR_TARGET_TEMP_LOW) is not None and \ kwargs.get(ATTR_TARGET_TEMP_HIGH) is not None: high_temp = int(kwargs.get(ATTR_TARGET_TEMP_LOW)) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index b64a59c9364..97ca7fe012f 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -110,7 +110,7 @@ class GenericThermostat(ClimateDevice): return self._cur_temp @property - def operation(self): + def current_operation(self): """Return current operation ie. heat, cool, idle.""" if self.ac_mode: cooling = self._active and self._is_device_active diff --git a/homeassistant/components/climate/nest.py b/homeassistant/components/climate/nest.py index 86b63d4229b..91e5f5824e9 100644 --- a/homeassistant/components/climate/nest.py +++ b/homeassistant/components/climate/nest.py @@ -9,9 +9,9 @@ import voluptuous as vol import homeassistant.components.nest as nest from homeassistant.components.climate import ( STATE_AUTO, STATE_COOL, STATE_HEAT, STATE_IDLE, ClimateDevice, - PLATFORM_SCHEMA) + PLATFORM_SCHEMA, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW) from homeassistant.const import ( - TEMP_CELSIUS, CONF_SCAN_INTERVAL, ATTR_TEMPERATURE, STATE_ON) + TEMP_CELSIUS, CONF_SCAN_INTERVAL, STATE_ON, TEMP_FAHRENHEIT) from homeassistant.util.temperature import convert as convert_temperature DEPENDENCIES = ['nest'] @@ -57,7 +57,10 @@ class NestThermostat(ClimateDevice): @property def unit_of_measurement(self): """Return the unit of measurement.""" - return TEMP_CELSIUS + if self.device.measurment_scale == 'F': + return TEMP_FAHRENHEIT + elif self.device.measurement_scale == 'C': + return TEMP_CELSIUS @property def device_state_attributes(self): @@ -84,35 +87,6 @@ class NestThermostat(ClimateDevice): else: return STATE_IDLE - @property - def target_temperature(self): - """Return the temperature we try to reach.""" - if self.device.mode == 'range': - low, high = self.target_temperature_low, \ - self.target_temperature_high - if self.operation == STATE_COOL: - temp = high - elif self.operation == STATE_HEAT: - temp = low - else: - # If the outside temp is lower than the current temp, consider - # the 'low' temp to the target, otherwise use the high temp - if (self.device.structure.weather.current.temperature < - self.current_temperature): - temp = low - else: - temp = high - else: - if self.is_away_mode_on: - # away_temperature is a low, high tuple. Only one should be set - # if not in range mode, the other will be None - temp = self.device.away_temperature[0] or \ - self.device.away_temperature[1] - else: - temp = self.device.target - - return temp - @property def target_temperature_low(self): """Return the lower bound temperature we try to reach.""" @@ -140,18 +114,16 @@ class NestThermostat(ClimateDevice): def set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = convert_temperature(kwargs.get(ATTR_TEMPERATURE), - self._unit, TEMP_CELSIUS) - _LOGGER.debug("Nest set_temperature-input-value=%s", temperature) - if temperature is None: - return - if self.device.mode == 'range': - if self.target_temperature == self.target_temperature_low: - temperature = (temperature, self.target_temperature_high) - elif self.target_temperature == self.target_temperature_high: - temperature = (self.target_temperature_low, temperature) - _LOGGER.debug("Nest set_temperature-output-value=%s", temperature) - self.device.target = temperature + if kwargs.get(ATTR_TARGET_TEMP_LOW) is not None and \ + kwargs.get(ATTR_TARGET_TEMP_HIGH) is not None: + target_temp_high = convert_temperature(kwargs.get( + ATTR_TARGET_TEMP_HIGH), self._unit, TEMP_CELSIUS) + target_temp_low = convert_temperature(kwargs.get( + ATTR_TARGET_TEMP_LOW), self._unit, TEMP_CELSIUS) + + temp = (target_temp_low, target_temp_high) + _LOGGER.debug("Nest set_temperature-output-value=%s", temp) + self.device.target = temp def set_operation_mode(self, operation_mode): """Set operation mode.""" diff --git a/tests/components/climate/test_demo.py b/tests/components/climate/test_demo.py index cd05dcb2b4e..f44cb6aabf4 100644 --- a/tests/components/climate/test_demo.py +++ b/tests/components/climate/test_demo.py @@ -71,13 +71,14 @@ class TestDemoClimate(unittest.TestCase): def test_set_target_temp_range(self): """Test the setting of the target temperature with range.""" state = self.hass.states.get(ENTITY_ECOBEE) - self.assertEqual(23.0, state.attributes.get('temperature')) + self.assertEqual(None, state.attributes.get('temperature')) self.assertEqual(21.0, state.attributes.get('target_temp_low')) self.assertEqual(24.0, state.attributes.get('target_temp_high')) - climate.set_temperature(self.hass, 30, ENTITY_ECOBEE, 25, 20) + climate.set_temperature(self.hass, target_temp_high=25, + target_temp_low=20, entity_id=ENTITY_ECOBEE) self.hass.pool.block_till_done() state = self.hass.states.get(ENTITY_ECOBEE) - self.assertEqual(30.0, state.attributes.get('temperature')) + self.assertEqual(None, state.attributes.get('temperature')) self.assertEqual(20.0, state.attributes.get('target_temp_low')) self.assertEqual(25.0, state.attributes.get('target_temp_high')) @@ -85,13 +86,15 @@ class TestDemoClimate(unittest.TestCase): """Test setting the target temperature range without required attribute.""" state = self.hass.states.get(ENTITY_ECOBEE) - self.assertEqual(23, state.attributes.get('temperature')) + self.assertEqual(None, state.attributes.get('temperature')) self.assertEqual(21.0, state.attributes.get('target_temp_low')) self.assertEqual(24.0, state.attributes.get('target_temp_high')) - climate.set_temperature(self.hass, None, ENTITY_ECOBEE, None, None) + climate.set_temperature(self.hass, temperature=None, + entity_id=ENTITY_ECOBEE, target_temp_low=None, + target_temp_high=None) self.hass.pool.block_till_done() state = self.hass.states.get(ENTITY_ECOBEE) - self.assertEqual(23, state.attributes.get('temperature')) + self.assertEqual(None, state.attributes.get('temperature')) self.assertEqual(21.0, state.attributes.get('target_temp_low')) self.assertEqual(24.0, state.attributes.get('target_temp_high')) diff --git a/tests/components/climate/test_generic_thermostat.py b/tests/components/climate/test_generic_thermostat.py index e399749a027..313bfd6035f 100644 --- a/tests/components/climate/test_generic_thermostat.py +++ b/tests/components/climate/test_generic_thermostat.py @@ -93,7 +93,7 @@ class TestClimateGenericThermostat(unittest.TestCase): def test_setup_defaults_to_unknown(self): """Test the setting of defaults to unknown.""" - self.assertEqual('unknown', self.hass.states.get(ENTITY).state) + self.assertEqual('idle', self.hass.states.get(ENTITY).state) def test_default_setup_params(self): """Test the setup with default parameters."""