Nest Cam support (#4292)

* start nestcam support

* start nestcam support

* introduce a access_token_cache_file

* Bare minimum to get nest thermostat loading

* occaisonally the image works

* switch to nest-aware interval for testing

* Add Nest Aware awareness

* remove duplicate error logging line

* Fix nest protect support

* address baloobot

* fix copy pasta

* fix more baloobot

* last baloobot thing for now?

* Use streaming status to determine online or not. online from nest means its on the network

* Fix temperature scale for climate

* Add support for eco mode

* Fix auto mode for nest climate

* update update current_operation and set_operation mode to use constant when possible. try to get setting something working

* remove stale comment

* unused-argument already disabled globally

* Add eco to the end, instead of after off

* Simplify conditional when the hass mode is the same as the nest one

* away_temperature became eco_temperature, and works with eco mode

* Update min/max temp based on locked temperature

* Forgot to set locked stuff during construction

* Cache image instead of throttling (which returns none), respect NestAware subscription

* Fix _time_between_snapshots before the first update

* WIP pin authorization

* Add some more logging

* Working configurator, woo. Fix some hound errors

* Updated pin workflow

* Deprecate more sensors

* Don't update during access of name

* Don't update during access of name

* Add camera brand

* Fix up some syntastic errors

* Fix ups ome hound errors

* Maybe fix some more?

* Move snapshot simulator url checking down into python-nest

* Rename _ready_to_update_camera_image to _ready_for_snapshot

* More fixes

* Set the next time a snapshot can be taken when one is taken to simplify logic

* Add a FIXME about update not getting called

* Call update during constructor, so values get set at least once

* Fix up names

* Remove todo about eco, since that's pretty nest

* thanks hound

* Fix temperature being off for farenheight.

* Fix some lint errors, which includes using a git version of python-nest with updated code

* generate requirements_all.py

* fix pylint

* Update nestcam before adding

* Fix polling of NestCamera

* Lint
This commit is contained in:
Josh Nichols 2016-11-27 19:18:47 -05:00 committed by Paulus Schoutsen
parent 601193b1d2
commit 84b12ab007
5 changed files with 289 additions and 118 deletions

View file

@ -11,29 +11,35 @@ import voluptuous as vol
from homeassistant.components.nest import DATA_NEST, DOMAIN
from homeassistant.helpers.entity import Entity
from homeassistant.const import (
TEMP_CELSIUS, CONF_PLATFORM, CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS
TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_PLATFORM,
CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS
)
DEPENDENCIES = ['nest']
SENSOR_TYPES = ['humidity',
'operation_mode',
'last_ip',
'local_ip',
'last_connection',
'battery_level']
'last_connection']
WEATHER_VARS = {'weather_humidity': 'humidity',
'weather_temperature': 'temperature',
'weather_condition': 'condition',
'wind_speed': 'kph',
'wind_direction': 'direction'}
SENSOR_TYPES_DEPRECATED = ['battery_health',
'last_ip',
'local_ip']
SENSOR_UNITS = {'humidity': '%', 'battery_level': 'V',
'kph': 'kph', 'temperature': '°C'}
WEATHER_VARS = {}
DEPRECATED_WEATHER_VARS = {'weather_humidity': 'humidity',
'weather_temperature': 'temperature',
'weather_condition': 'condition',
'wind_speed': 'kph',
'wind_direction': 'direction'}
SENSOR_UNITS = {'humidity': '%',
'temperature': '°C'}
PROTECT_VARS = ['co_status',
'smoke_status',
'battery_level']
'battery_health']
PROTECT_VARS_DEPRECATED = ['battery_level']
SENSOR_TEMP_TYPES = ['temperature', 'target']
@ -51,21 +57,22 @@ PLATFORM_SCHEMA = vol.Schema({
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)
all_sensors = []
for structure, device in chain(nest.devices(), nest.protect_devices()):
sensors = [NestBasicSensor(structure, device, variable)
for variable in config[CONF_MONITORED_CONDITIONS]
for variable in conf
if variable in SENSOR_TYPES and is_thermostat(device)]
sensors += [NestTempSensor(structure, device, variable)
for variable in config[CONF_MONITORED_CONDITIONS]
for variable in conf
if variable in SENSOR_TEMP_TYPES and is_thermostat(device)]
sensors += [NestWeatherSensor(structure, device,
WEATHER_VARS[variable])
for variable in config[CONF_MONITORED_CONDITIONS]
for variable in conf
if variable in WEATHER_VARS and is_thermostat(device)]
sensors += [NestProtectSensor(structure, device, variable)
for variable in config[CONF_MONITORED_CONDITIONS]
for variable in conf
if variable in PROTECT_VARS and is_protect(device)]
all_sensors.extend(sensors)
@ -99,16 +106,7 @@ class NestSensor(Entity):
@property
def name(self):
"""Return the name of the nest, if any."""
if self._location is None:
return "{} {}".format(self._name, self.variable)
else:
if self._name == '':
return "{} {}".format(self._location.capitalize(),
self.variable)
else:
return "{}({}){}".format(self._location.capitalize(),
self._name,
self.variable)
return "{} {}".format(self._name, self.variable)
class NestBasicSensor(NestSensor):
@ -138,7 +136,10 @@ class NestTempSensor(NestSensor):
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return TEMP_CELSIUS
if self.device.temperature_scale == 'C':
return TEMP_CELSIUS
else:
return TEMP_FAHRENHEIT
@property
def state(self):
@ -191,19 +192,4 @@ class NestProtectSensor(NestSensor):
def update(self):
"""Retrieve latest state."""
state = getattr(self.device, self.variable)
if self.variable == 'battery_level':
self._state = getattr(self.device, self.variable)
else:
self._state = 'Unknown'
if state == 0:
self._state = 'Ok'
if state == 1 or state == 2:
self._state = 'Warning'
if state == 3:
self._state = 'Emergency'
@property
def name(self):
"""Return the name of the nest, if any."""
return "{} {}".format(self._location.capitalize(), self.variable)
self._state = getattr(self.device, self.variable).capitalize()