From c12b7e70d956b67df259b672530b0aa8d0d2456c Mon Sep 17 00:00:00 2001 From: zyell Date: Thu, 13 Aug 2015 11:38:57 -0700 Subject: [PATCH] Updated to support Nest API changes and fix set_temp and away_mode and pull in new required python-nest version --- homeassistant/components/thermostat/nest.py | 42 +++++++++++++++++++-- requirements.txt | 2 +- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/thermostat/nest.py b/homeassistant/components/thermostat/nest.py index b2e48b96bcd70..5b50c444dc72e 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -34,7 +34,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): napi = nest.Nest(username, password) add_devices([ - NestThermostat(structure, device) + NestThermostat(nest.utils, structure, device) for structure in napi.structures for device in structure.devices ]) @@ -43,14 +43,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class NestThermostat(ThermostatDevice): """ Represents a Nest thermostat within Home Assistant. """ - def __init__(self, structure, device): + def __init__(self, nest_utils, structure, device): self.structure = structure self.device = device + self.nest_utils = nest_utils @property def name(self): """ Returns the name of the nest, if any. """ - return self.device.name + location = self.device.where + name = self.device.name + if location is None: + return name + else: + if name == '': + return location.capitalize() + else: + return location.capitalize() + '(' + name + ')' @property def unit_of_measurement(self): @@ -97,9 +106,16 @@ def is_away_mode_on(self): """ Returns if away mode is on. """ return self.structure.away + def enforce_temp_units(self, temperature): + """ Enforces temp units in C for nest API, returns temp """ + if self.hass.config.temperature_unit == self.unit_of_measurement: + return temperature + else: + return self.nest_utils.f_to_c(temperature) + def set_temperature(self, temperature): """ Set new target temperature """ - self.device.target = temperature + self.device.target = self.enforce_temp_units(temperature) def turn_away_mode_on(self): """ Turns away on. """ @@ -109,6 +125,24 @@ def turn_away_mode_off(self): """ Turns away off. """ self.structure.away = False + @property + def min_temp(self): + """ Identifies min_temp in Nest API or defaults if not available. """ + temp = self.device.away_temperature.low + if temp is None: + return super().min_temp + else: + return round(self.hass.config.temperature(temp, TEMP_CELCIUS)[0]) + + @property + def max_temp(self): + """ Identifies mxn_temp in Nest API or defaults if not available. """ + temp = self.device.away_temperature.high + if temp is None: + return super().max_temp + else: + return round(self.hass.config.temperature(temp, TEMP_CELCIUS)[0]) + def update(self): """ Python-nest has its own mechanism for staying up to date. """ pass diff --git a/requirements.txt b/requirements.txt index e284cad72b9c1..8bcd54700348e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,7 @@ python-libnmap>=0.6.3 pushbullet.py>=0.7.1 # Nest Thermostat bindings (thermostat.nest) -python-nest>=2.3.1 +python-nest>=2.4.0 # Z-Wave (*.zwave) pydispatcher>=2.0.5