diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index bbc0979e38c..93e264091b9 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -27,6 +27,9 @@ ATTR_CURRENT_TEMPERATURE = "current_temperature" ATTR_AWAY_MODE = "away_mode" ATTR_MAX_TEMP = "max_temp" ATTR_MIN_TEMP = "min_temp" +ATTR_TEMPERATURE_LOW = "target_temp_low" +ATTR_TEMPERATURE_HIGH = "target_temp_high" +ATTR_OPERATION = "current_operation" _LOGGER = logging.getLogger(__name__) @@ -111,7 +114,7 @@ class ThermostatDevice(Entity): @property def state(self): """ Returns the current state. """ - return self.target_temperature + return self.operation @property def device_state_attributes(self): @@ -134,7 +137,20 @@ class ThermostatDevice(Entity): user_unit), 0), ATTR_MAX_TEMP: round(convert(self.max_temp, thermostat_unit, - user_unit), 0) + user_unit), 0), + ATTR_TEMPERATURE: round(convert(self.target_temperature, + thermostat_unit, + user_unit), 0), + ATTR_TEMPERATURE_LOW: round(convert(self.target_temperature_low, + thermostat_unit, + user_unit), 0), + ATTR_TEMPERATURE_HIGH: round(convert(self.target_temperature_high, + thermostat_unit, + user_unit), 0), + ATTR_OPERATION: round(convert(self.operation, + thermostat_unit, + user_unit), 0) + } is_away = self.is_away_mode_on @@ -159,11 +175,26 @@ class ThermostatDevice(Entity): """ Returns the current temperature. """ raise NotImplementedError + @property + def operation(self): + """ Returns current operation ie. heat, cool, idle """ + return NotImplementedError + @property def target_temperature(self): """ Returns the temperature we try to reach. """ raise NotImplementedError + @property + def target_temperature_low(self): + """ Returns the lower bound temperature we try to reach. """ + return self.target_temperature + + @property + def target_temperature_high(self): + """ Returns the upper bound temperature we try to reach. """ + return self.target_temperature + @property def is_away_mode_on(self): """ diff --git a/homeassistant/components/thermostat/nest.py b/homeassistant/components/thermostat/nest.py index 72f10033a91..39480daa731 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -8,6 +8,10 @@ import logging from homeassistant.components.thermostat import ThermostatDevice from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) +STATE_HEAT = "heat" +STATE_COOL = "cool" +STATE_IDLE = "idle" + REQUIREMENTS = ['python-nest==2.6.0'] @@ -83,25 +87,52 @@ class NestThermostat(ThermostatDevice): """ Returns the current temperature. """ return round(self.device.temperature, 1) + @property + def operation(self): + """ Returns current operation ie. heat, cool, idle """ + if self.device.hvac_ac_state is True: + return STATE_COOL + elif self.device.hvac_heater_state is True: + return STATE_HEAT + else: + return STATE_IDLE + @property def target_temperature(self): """ Returns the temperature we try to reach. """ target = self.device.target - if isinstance(target, tuple): + if self.device.mode == 'range': low, high = target - - if self.current_temperature < low: - temp = low - elif self.current_temperature > high: + if self.operation == STATE_COOL: temp = high + elif self.operation == STATE_HEAT: + temp = low else: - temp = (low + high)/2 + range_average = (low + high)/2 + if self.current_temperature < range_average: + temp = low + elif self.current_temperature > range_average: + temp = high else: temp = target return round(temp, 1) + @property + def target_temperature_low(self): + """ Returns the lower bound temperature we try to reach. """ + if self.device.mode == 'range': + return self.device.target["low"] + return round(self.target_temperature, 1) + + @property + def target_temperature_high(self): + """ Returns the upper bound temperature we try to reach. """ + if self.device.mode == 'range': + return self.device.target["high"] + return round(self.target_temperature, 1) + @property def is_away_mode_on(self): """ Returns if away mode is on. """ @@ -109,6 +140,11 @@ class NestThermostat(ThermostatDevice): def set_temperature(self, temperature): """ Set new target temperature """ + 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) self.device.target = temperature def turn_away_mode_on(self):