Add Nest away binary sensor and eta sensor (#14406)

This commit is contained in:
Jason Hu 2018-05-23 12:40:33 -07:00 committed by Sebastian Muszynski
parent c13ebacce1
commit 3498234448
3 changed files with 65 additions and 17 deletions

View file

@ -36,10 +36,15 @@ PROTECT_VARS_DEPRECATED = ['battery_level']
SENSOR_TEMP_TYPES = ['temperature', 'target']
STRUCTURE_SENSOR_TYPES = ['eta']
VARIABLE_NAME_MAPPING = {'eta': 'eta_begin', 'operation_mode': 'mode'}
_SENSOR_TYPES_DEPRECATED = SENSOR_TYPES_DEPRECATED \
+ list(DEPRECATED_WEATHER_VARS.keys()) + PROTECT_VARS_DEPRECATED
_VALID_SENSOR_TYPES = SENSOR_TYPES + SENSOR_TEMP_TYPES + PROTECT_VARS
_VALID_SENSOR_TYPES = SENSOR_TYPES + SENSOR_TEMP_TYPES + PROTECT_VARS \
+ STRUCTURE_SENSOR_TYPES
_LOGGER = logging.getLogger(__name__)
@ -73,6 +78,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error(wstr)
all_sensors = []
for structure in nest.structures():
all_sensors += [NestBasicSensor(structure, None, variable)
for variable in conditions
if variable in STRUCTURE_SENSOR_TYPES]
for structure, device in chain(nest.thermostats(), nest.smoke_co_alarms()):
sensors = [NestBasicSensor(structure, device, variable)
for variable in conditions
@ -94,13 +103,20 @@ class NestSensor(Entity):
def __init__(self, structure, device, variable):
"""Initialize the sensor."""
self.structure = structure
self.device = device
self.variable = variable
# device specific
self._location = self.device.where
self._name = "{} {}".format(self.device.name_long,
self.variable.replace("_", " "))
if device is not None:
# device specific
self.device = device
self._location = self.device.where
self._name = "{} {}".format(self.device.name_long,
self.variable.replace('_', ' '))
else:
# structure only
self.device = structure
self._name = "{} {}".format(self.structure.name,
self.variable.replace('_', ' '))
self._state = None
self._unit = None
@ -127,8 +143,9 @@ class NestBasicSensor(NestSensor):
"""Retrieve latest state."""
self._unit = SENSOR_UNITS.get(self.variable, None)
if self.variable == 'operation_mode':
self._state = getattr(self.device, "mode")
if self.variable in VARIABLE_NAME_MAPPING:
self._state = getattr(self.device,
VARIABLE_NAME_MAPPING[self.variable])
else:
self._state = getattr(self.device, self.variable)