mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Merge pull request #279 from Zyell/dev
Updated Thermostat unit handling and Nest support
This commit is contained in:
commit
c50a47a307
@ -10,6 +10,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
||||
import homeassistant.util as util
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.temperature import convert
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, TEMP_CELCIUS)
|
||||
|
||||
@ -86,7 +87,9 @@ def setup(hass, config):
|
||||
return
|
||||
|
||||
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:
|
||||
thermostat.update_ha_state(True)
|
||||
@ -118,9 +121,20 @@ class ThermostatDevice(Entity):
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns optional state attributes. """
|
||||
|
||||
thermostat_unit = self.unit_of_measurement
|
||||
user_unit = self.hass.config.temperature_unit
|
||||
|
||||
data = {
|
||||
ATTR_CURRENT_TEMPERATURE: self.hass.config.temperature(
|
||||
self.current_temperature, self.unit_of_measurement)[0]
|
||||
ATTR_CURRENT_TEMPERATURE: round(convert(self.current_temperature,
|
||||
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
|
||||
@ -133,11 +147,13 @@ class ThermostatDevice(Entity):
|
||||
if device_attr is not None:
|
||||
data.update(device_attr)
|
||||
|
||||
data[ATTR_MIN_TEMP] = self.min_temp
|
||||
data[ATTR_MAX_TEMP] = self.max_temp
|
||||
|
||||
return data
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit of measurement this thermostat expresses itself in. """
|
||||
return NotImplementedError
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
""" Returns the current temperature. """
|
||||
@ -171,9 +187,9 @@ class ThermostatDevice(Entity):
|
||||
@property
|
||||
def min_temp(self):
|
||||
""" Return minimum temperature. """
|
||||
return self.hass.config.temperature(7, TEMP_CELCIUS)[0]
|
||||
return convert(7, TEMP_CELCIUS, self.unit_of_measurement)
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
""" Return maxmum temperature. """
|
||||
return self.hass.config.temperature(35, TEMP_CELCIUS)[0]
|
||||
return convert(35, TEMP_CELCIUS, self.unit_of_measurement)
|
||||
|
@ -6,7 +6,7 @@ import logging
|
||||
from homeassistant.components.thermostat import ThermostatDevice
|
||||
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
|
||||
@ -50,11 +50,19 @@ class NestThermostat(ThermostatDevice):
|
||||
@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):
|
||||
""" Returns the unit of measurement. """
|
||||
""" Unit of measurement this thermostat expresses itself in. """
|
||||
return TEMP_CELCIUS
|
||||
|
||||
@property
|
||||
@ -109,6 +117,24 @@ class NestThermostat(ThermostatDevice):
|
||||
""" 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 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):
|
||||
""" Python-nest has its own mechanism for staying up to date. """
|
||||
pass
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user