diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index bbc0979e38c..940c656ad94 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -23,10 +23,17 @@ SCAN_INTERVAL = 60 SERVICE_SET_AWAY_MODE = "set_away_mode" SERVICE_SET_TEMPERATURE = "set_temperature" +STATE_HEAT = "heat" +STATE_COOL = "cool" +STATE_IDLE = "idle" + 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__) @@ -134,7 +141,17 @@ 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: self.operation } is_away = self.is_away_mode_on @@ -159,11 +176,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..c724a4f6dea 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -5,7 +5,8 @@ Adds support for Nest thermostats. """ import logging -from homeassistant.components.thermostat import ThermostatDevice +from homeassistant.components.thermostat import (ThermostatDevice, STATE_COOL, + STATE_IDLE, STATE_HEAT) from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) REQUIREMENTS = ['python-nest==2.6.0'] @@ -83,25 +84,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 round(self.device.target[0], 1) + 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 round(self.device.target[1], 1) + return round(self.target_temperature, 1) + @property def is_away_mode_on(self): """ Returns if away mode is on. """ @@ -109,6 +137,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):