Nest config flow (#14921)

* Move nest to dir based component

* Add config flow for Nest

* Load Nest platforms via config entry

* Add tests for Nest config flow

* Import existing access tokens as config entries

* Lint

* Update coverage

* Update translation

* Fix tests

* Address strings

* Use python-nest token resolution

* Lint

* Do not do I/O inside constructor

* Lint

* Update test requirements
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2018-06-13 11:14:52 -04:00
1 parent d549e26a9b
commit e014a84215
21 files changed
+666 -153

No files matched your search

+32 -21
View File
@@ -6,7 +6,8 @@ https://home-assistant.io/components/sensor.nest/
"""
import logging
from homeassistant.components.nest import DATA_NEST, NestSensorDevice
from homeassistant.components.nest import (
DATA_NEST, DATA_NEST_CONFIG, CONF_SENSORS, NestSensorDevice)
from homeassistant.const import (
TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_MONITORED_CONDITIONS,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY)
@@ -51,12 +52,18 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Nest Sensor."""
if discovery_info is None:
return
"""Set up the Nest Sensor.
No longer used.
"""
async def async_setup_entry(hass, entry, async_add_devices):
"""Set up a Nest sensor based on a config entry."""
nest = hass.data[DATA_NEST]
discovery_info = hass.data.get(DATA_NEST_CONFIG, {}).get(CONF_SENSORS, {})
# Add all available sensors if no Nest sensor config is set
if discovery_info == {}:
conditions = _VALID_SENSOR_TYPES
@@ -77,26 +84,30 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"binary_sensor.nest/ for valid options.")
_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]
def get_sensors():
"""Get the Nest sensors."""
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 nest.thermostats():
all_sensors += [NestBasicSensor(structure, device, variable)
for variable in conditions
if variable in SENSOR_TYPES]
all_sensors += [NestTempSensor(structure, device, variable)
for variable in conditions
if variable in TEMP_SENSOR_TYPES]
for structure, device in nest.thermostats():
all_sensors += [NestBasicSensor(structure, device, variable)
for variable in conditions
if variable in SENSOR_TYPES]
all_sensors += [NestTempSensor(structure, device, variable)
for variable in conditions
if variable in TEMP_SENSOR_TYPES]
for structure, device in nest.smoke_co_alarms():
all_sensors += [NestBasicSensor(structure, device, variable)
for variable in conditions
if variable in PROTECT_SENSOR_TYPES]
for structure, device in nest.smoke_co_alarms():
all_sensors += [NestBasicSensor(structure, device, variable)
for variable in conditions
if variable in PROTECT_SENSOR_TYPES]
add_devices(all_sensors, True)
return all_sensors
async_add_devices(await hass.async_add_job(get_sensors), True)
class NestBasicSensor(NestSensorDevice):