Nest further improvements (#4655)

* Further improvements on nest platform

- fix binary sensor
- add deprecations for monitored_conditions
- better names for sensors (includes device type)

* lint

* Remove unused weather sensor

* Fix to python-nest to a specific commit

* lint

* lint

* lint

* lint
This commit is contained in:
Josh Nichols authored and Paulus Schoutsen committed 2016-12-03 09:26:47 -08:00
1 parent af7de8d5ae
commit 64a5bff5b2
4 files changed
+143 -56

No files matched your search

+38 -36
View File
@@ -5,6 +5,7 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.nest/
"""
from itertools import chain
import logging
import voluptuous as vol
@@ -17,11 +18,13 @@ from homeassistant.const import (
DEPENDENCIES = ['nest']
SENSOR_TYPES = ['humidity',
'operation_mode',
'last_connection']
'operation_mode']
SENSOR_TYPES_DEPRECATED = ['battery_health',
'last_ip',
SENSOR_TYPES_DEPRECATED = ['last_ip',
'local_ip',
'last_connection']
SENSOR_TYPES_DEPRECATED = ['last_ip',
'local_ip']
WEATHER_VARS = {}
@@ -43,22 +46,48 @@ PROTECT_VARS_DEPRECATED = ['battery_level']
SENSOR_TEMP_TYPES = ['temperature', 'target']
_VALID_SENSOR_TYPES = SENSOR_TYPES + SENSOR_TEMP_TYPES + PROTECT_VARS + \
list(WEATHER_VARS.keys())
_SENSOR_TYPES_DEPRECATED = SENSOR_TYPES_DEPRECATED \
+ list(DEPRECATED_WEATHER_VARS.keys()) + PROTECT_VARS_DEPRECATED
_VALID_SENSOR_TYPES = SENSOR_TYPES + SENSOR_TEMP_TYPES + PROTECT_VARS \
+ list(WEATHER_VARS.keys())
_VALID_SENSOR_TYPES_WITH_DEPRECATED = _VALID_SENSOR_TYPES \
+ _SENSOR_TYPES_DEPRECATED
PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): DOMAIN,
vol.Optional(CONF_SCAN_INTERVAL):
vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Required(CONF_MONITORED_CONDITIONS): [vol.In(_VALID_SENSOR_TYPES)],
vol.Required(CONF_MONITORED_CONDITIONS):
[vol.In(_VALID_SENSOR_TYPES_WITH_DEPRECATED)]
})
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Nest Sensor."""
nest = hass.data[DATA_NEST]
conf = config.get(CONF_MONITORED_CONDITIONS, _VALID_SENSOR_TYPES)
for variable in conf:
if variable in _SENSOR_TYPES_DEPRECATED:
if variable in DEPRECATED_WEATHER_VARS:
wstr = ("Nest no longer provides weather data like %s. See "
"https://home-assistant.io/components/#weather "
"for a list of other weather components to use." %
variable)
else:
wstr = (variable + " is no a longer supported "
"monitored_conditions. See "
"https://home-assistant.io/components/"
"binary_sensor.nest/ "
"for valid options, or remove monitored_conditions "
"entirely to get a reasonable default")
_LOGGER.error(wstr)
all_sensors = []
for structure, device in chain(nest.devices(), nest.protect_devices()):
sensors = [NestBasicSensor(structure, device, variable)
@@ -67,10 +96,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
sensors += [NestTempSensor(structure, device, variable)
for variable in conf
if variable in SENSOR_TEMP_TYPES and is_thermostat(device)]
sensors += [NestWeatherSensor(structure, device,
WEATHER_VARS[variable])
for variable in conf
if variable in WEATHER_VARS and is_thermostat(device)]
sensors += [NestProtectSensor(structure, device, variable)
for variable in conf
if variable in PROTECT_VARS and is_protect(device)]
@@ -100,13 +125,13 @@ class NestSensor(Entity):
# device specific
self._location = self.device.where
self._name = self.device.name
self._name = self.device.name_long
self._state = None
@property
def name(self):
"""Return the name of the nest, if any."""
return "{} {}".format(self._name, self.variable)
return "{} {}".format(self._name, self.variable.replace("_", " "))
class NestBasicSensor(NestSensor):
@@ -159,29 +184,6 @@ class NestTempSensor(NestSensor):
self._state = round(temp, 1)
class NestWeatherSensor(NestSensor):
"""Representation a basic Nest Weather Conditions sensor."""
@property
def state(self):
"""Return the state of the sensor."""
return self._state
def update(self):
"""Retrieve latest state."""
if self.variable == 'kph' or self.variable == 'direction':
self._state = getattr(self.structure.weather.current.wind,
self.variable)
else:
self._state = getattr(self.structure.weather.current,
self.variable)
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return SENSOR_UNITS.get(self.variable, None)
class NestProtectSensor(NestSensor):
"""Return the state of nest protect."""