mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Updated to support Nest API changes and fix set_temp and away_mode and pull in new required python-nest version
This commit is contained in:
parent
917db18b29
commit
c12b7e70d9
@ -34,7 +34,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
napi = nest.Nest(username, password)
|
napi = nest.Nest(username, password)
|
||||||
|
|
||||||
add_devices([
|
add_devices([
|
||||||
NestThermostat(structure, device)
|
NestThermostat(nest.utils, structure, device)
|
||||||
for structure in napi.structures
|
for structure in napi.structures
|
||||||
for device in structure.devices
|
for device in structure.devices
|
||||||
])
|
])
|
||||||
@ -43,14 +43,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
class NestThermostat(ThermostatDevice):
|
class NestThermostat(ThermostatDevice):
|
||||||
""" Represents a Nest thermostat within Home Assistant. """
|
""" Represents a Nest thermostat within Home Assistant. """
|
||||||
|
|
||||||
def __init__(self, structure, device):
|
def __init__(self, nest_utils, structure, device):
|
||||||
self.structure = structure
|
self.structure = structure
|
||||||
self.device = device
|
self.device = device
|
||||||
|
self.nest_utils = nest_utils
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" Returns the name of the nest, if any. """
|
""" 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
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
@ -97,9 +106,16 @@ class NestThermostat(ThermostatDevice):
|
|||||||
""" Returns if away mode is on. """
|
""" Returns if away mode is on. """
|
||||||
return self.structure.away
|
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):
|
def set_temperature(self, temperature):
|
||||||
""" Set new target temperature """
|
""" Set new target temperature """
|
||||||
self.device.target = temperature
|
self.device.target = self.enforce_temp_units(temperature)
|
||||||
|
|
||||||
def turn_away_mode_on(self):
|
def turn_away_mode_on(self):
|
||||||
""" Turns away on. """
|
""" Turns away on. """
|
||||||
@ -109,6 +125,24 @@ class NestThermostat(ThermostatDevice):
|
|||||||
""" Turns away off. """
|
""" Turns away off. """
|
||||||
self.structure.away = False
|
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):
|
def update(self):
|
||||||
""" Python-nest has its own mechanism for staying up to date. """
|
""" Python-nest has its own mechanism for staying up to date. """
|
||||||
pass
|
pass
|
||||||
|
@ -30,7 +30,7 @@ python-libnmap>=0.6.3
|
|||||||
pushbullet.py>=0.7.1
|
pushbullet.py>=0.7.1
|
||||||
|
|
||||||
# Nest Thermostat bindings (thermostat.nest)
|
# Nest Thermostat bindings (thermostat.nest)
|
||||||
python-nest>=2.3.1
|
python-nest>=2.4.0
|
||||||
|
|
||||||
# Z-Wave (*.zwave)
|
# Z-Wave (*.zwave)
|
||||||
pydispatcher>=2.0.5
|
pydispatcher>=2.0.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user