Merge pull request #279 from Zyell/dev

Updated Thermostat unit handling and Nest support
This commit is contained in:
Paulus Schoutsen 2015-08-25 19:08:52 -07:00
commit c50a47a307
3 changed files with 54 additions and 12 deletions

View File

@ -10,6 +10,7 @@ from homeassistant.helpers.entity_component import EntityComponent
import homeassistant.util as util import homeassistant.util as util
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.temperature import convert
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, TEMP_CELCIUS) ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, TEMP_CELCIUS)
@ -86,7 +87,9 @@ def setup(hass, config):
return return
for thermostat in target_thermostats: for thermostat in target_thermostats:
thermostat.set_temperature(temperature) thermostat.set_temperature(convert(
temperature, hass.config.temperature_unit,
thermostat.unit_of_measurement))
for thermostat in target_thermostats: for thermostat in target_thermostats:
thermostat.update_ha_state(True) thermostat.update_ha_state(True)
@ -118,9 +121,20 @@ class ThermostatDevice(Entity):
@property @property
def state_attributes(self): def state_attributes(self):
""" Returns optional state attributes. """ """ Returns optional state attributes. """
thermostat_unit = self.unit_of_measurement
user_unit = self.hass.config.temperature_unit
data = { data = {
ATTR_CURRENT_TEMPERATURE: self.hass.config.temperature( ATTR_CURRENT_TEMPERATURE: round(convert(self.current_temperature,
self.current_temperature, self.unit_of_measurement)[0] thermostat_unit,
user_unit), 1),
ATTR_MIN_TEMP: round(convert(self.min_temp,
thermostat_unit,
user_unit), 0),
ATTR_MAX_TEMP: round(convert(self.max_temp,
thermostat_unit,
user_unit), 0)
} }
is_away = self.is_away_mode_on is_away = self.is_away_mode_on
@ -133,11 +147,13 @@ class ThermostatDevice(Entity):
if device_attr is not None: if device_attr is not None:
data.update(device_attr) data.update(device_attr)
data[ATTR_MIN_TEMP] = self.min_temp
data[ATTR_MAX_TEMP] = self.max_temp
return data return data
@property
def unit_of_measurement(self):
""" Unit of measurement this thermostat expresses itself in. """
return NotImplementedError
@property @property
def current_temperature(self): def current_temperature(self):
""" Returns the current temperature. """ """ Returns the current temperature. """
@ -171,9 +187,9 @@ class ThermostatDevice(Entity):
@property @property
def min_temp(self): def min_temp(self):
""" Return minimum temperature. """ """ Return minimum temperature. """
return self.hass.config.temperature(7, TEMP_CELCIUS)[0] return convert(7, TEMP_CELCIUS, self.unit_of_measurement)
@property @property
def max_temp(self): def max_temp(self):
""" Return maxmum temperature. """ """ Return maxmum temperature. """
return self.hass.config.temperature(35, TEMP_CELCIUS)[0] return convert(35, TEMP_CELCIUS, self.unit_of_measurement)

View File

@ -6,7 +6,7 @@ import logging
from homeassistant.components.thermostat import ThermostatDevice from homeassistant.components.thermostat import ThermostatDevice
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS)
REQUIREMENTS = ['python-nest>=2.3.1'] REQUIREMENTS = ['python-nest>=2.4.0']
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -50,11 +50,19 @@ class NestThermostat(ThermostatDevice):
@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):
""" Returns the unit of measurement. """ """ Unit of measurement this thermostat expresses itself in. """
return TEMP_CELCIUS return TEMP_CELCIUS
@property @property
@ -109,6 +117,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 temp
@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 temp
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

View File

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