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
pull/3527/merge
John Arild Berentsen 2016-09-27 19:34:16 +02:00 committed by GitHub
parent da6c09640c
commit 6694b0470e
6 changed files with 33 additions and 68 deletions

View File

@ -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)
])

View File

@ -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))

View File

@ -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

View File

@ -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."""

View File

@ -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'))

View File

@ -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."""