Move Nest sensors configuration to Nest component (#4983)
* Move Nest sensor config to Nest Component * Ensure Nest Protect sensors are added without specified sensor config * Fix pylint warnings * Remove support for empty monitored condion list * Remove scan interval * Remove scan interval import * Add Nest sensors by default with opt-out
This commit is contained in:
parent
d240ea56d8
commit
321a8be339
4 changed files with 49 additions and 67 deletions
|
@ -7,14 +7,10 @@ https://home-assistant.io/components/binary_sensor.nest/
|
|||
from itertools import chain
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDevice, PLATFORM_SCHEMA)
|
||||
from homeassistant.components.binary_sensor import (BinarySensorDevice)
|
||||
from homeassistant.components.sensor.nest import NestSensor
|
||||
from homeassistant.const import (CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS)
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.components.nest import DATA_NEST
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
DEPENDENCIES = ['nest']
|
||||
|
||||
|
@ -42,17 +38,6 @@ _BINARY_TYPES_DEPRECATED = [
|
|||
|
||||
_VALID_BINARY_SENSOR_TYPES = BINARY_TYPES + CLIMATE_BINARY_TYPES \
|
||||
+ CAMERA_BINARY_TYPES
|
||||
_VALID_BINARY_SENSOR_TYPES_WITH_DEPRECATED = _VALID_BINARY_SENSOR_TYPES \
|
||||
+ _BINARY_TYPES_DEPRECATED
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_SCAN_INTERVAL):
|
||||
vol.All(vol.Coerce(int), vol.Range(min=1)),
|
||||
vol.Required(CONF_MONITORED_CONDITIONS):
|
||||
vol.All(cv.ensure_list,
|
||||
[vol.In(_VALID_BINARY_SENSOR_TYPES_WITH_DEPRECATED)])
|
||||
})
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -63,15 +48,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
return
|
||||
|
||||
nest = hass.data[DATA_NEST]
|
||||
conf = config.get(CONF_MONITORED_CONDITIONS, _VALID_BINARY_SENSOR_TYPES)
|
||||
|
||||
for variable in conf:
|
||||
# Add all available binary sensors if no Nest binary sensor config is set
|
||||
if discovery_info == {}:
|
||||
conditions = _VALID_BINARY_SENSOR_TYPES
|
||||
else:
|
||||
conditions = discovery_info.get(CONF_MONITORED_CONDITIONS, {})
|
||||
|
||||
for variable in conditions:
|
||||
if variable in _BINARY_TYPES_DEPRECATED:
|
||||
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")
|
||||
"for valid options.")
|
||||
_LOGGER.error(wstr)
|
||||
|
||||
sensors = []
|
||||
|
@ -80,16 +69,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
nest.cameras())
|
||||
for structure, device in device_chain:
|
||||
sensors += [NestBinarySensor(structure, device, variable)
|
||||
for variable in conf
|
||||
for variable in conditions
|
||||
if variable in BINARY_TYPES]
|
||||
sensors += [NestBinarySensor(structure, device, variable)
|
||||
for variable in conf
|
||||
for variable in conditions
|
||||
if variable in CLIMATE_BINARY_TYPES
|
||||
and device.is_thermostat]
|
||||
|
||||
if device.is_camera:
|
||||
sensors += [NestBinarySensor(structure, device, variable)
|
||||
for variable in conf
|
||||
for variable in conditions
|
||||
if variable in CAMERA_BINARY_TYPES]
|
||||
for activity_zone in device.activity_zones:
|
||||
sensors += [NestActivityZoneSensor(structure,
|
||||
|
|
|
@ -11,7 +11,9 @@ import voluptuous as vol
|
|||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.const import (CONF_STRUCTURE, CONF_FILENAME)
|
||||
from homeassistant.const import (CONF_STRUCTURE, CONF_FILENAME,
|
||||
CONF_BINARY_SENSORS, CONF_SENSORS,
|
||||
CONF_MONITORED_CONDITIONS)
|
||||
from homeassistant.loader import get_component
|
||||
|
||||
_CONFIGURING = {}
|
||||
|
@ -30,11 +32,17 @@ NEST_CONFIG_FILE = 'nest.conf'
|
|||
CONF_CLIENT_ID = 'client_id'
|
||||
CONF_CLIENT_SECRET = 'client_secret'
|
||||
|
||||
SENSOR_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS): vol.All(cv.ensure_list)
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_CLIENT_ID): cv.string,
|
||||
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
||||
vol.Optional(CONF_STRUCTURE): vol.All(cv.ensure_list, cv.string)
|
||||
vol.Optional(CONF_STRUCTURE): vol.All(cv.ensure_list, cv.string),
|
||||
vol.Optional(CONF_SENSORS): SENSOR_SCHEMA,
|
||||
vol.Optional(CONF_BINARY_SENSORS): SENSOR_SCHEMA
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -88,9 +96,15 @@ def setup_nest(hass, nest, config, pin=None):
|
|||
|
||||
_LOGGER.debug("proceeding with discovery")
|
||||
discovery.load_platform(hass, 'climate', DOMAIN, {}, config)
|
||||
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
|
||||
discovery.load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
|
||||
discovery.load_platform(hass, 'camera', DOMAIN, {}, config)
|
||||
|
||||
sensor_config = conf.get(CONF_SENSORS, {})
|
||||
discovery.load_platform(hass, 'sensor', DOMAIN, sensor_config, config)
|
||||
|
||||
binary_sensor_config = conf.get(CONF_BINARY_SENSORS, {})
|
||||
discovery.load_platform(hass, 'binary_sensor', DOMAIN,
|
||||
binary_sensor_config, config)
|
||||
|
||||
_LOGGER.debug("setup done")
|
||||
|
||||
return True
|
||||
|
|
|
@ -7,15 +7,10 @@ https://home-assistant.io/components/sensor.nest/
|
|||
from itertools import chain
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.nest import (
|
||||
DATA_NEST, DOMAIN)
|
||||
from homeassistant.components.nest import DATA_NEST
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_PLATFORM,
|
||||
CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS
|
||||
)
|
||||
from homeassistant.const import (TEMP_CELSIUS, TEMP_FAHRENHEIT,
|
||||
CONF_MONITORED_CONDITIONS)
|
||||
|
||||
DEPENDENCIES = ['nest']
|
||||
SENSOR_TYPES = ['humidity',
|
||||
|
@ -26,23 +21,15 @@ SENSOR_TYPES_DEPRECATED = ['last_ip',
|
|||
'local_ip',
|
||||
'last_connection']
|
||||
|
||||
SENSOR_TYPES_DEPRECATED = ['last_ip',
|
||||
'local_ip']
|
||||
|
||||
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'}
|
||||
SENSOR_UNITS = {'humidity': '%', 'temperature': '°C'}
|
||||
|
||||
PROTECT_VARS = ['co_status',
|
||||
'smoke_status',
|
||||
'battery_health']
|
||||
PROTECT_VARS = ['co_status', 'smoke_status', 'battery_health']
|
||||
|
||||
PROTECT_VARS_DEPRECATED = ['battery_level']
|
||||
|
||||
|
@ -51,19 +38,7 @@ SENSOR_TEMP_TYPES = ['temperature', 'target']
|
|||
_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_WITH_DEPRECATED)]
|
||||
})
|
||||
_VALID_SENSOR_TYPES = SENSOR_TYPES + SENSOR_TEMP_TYPES + PROTECT_VARS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -74,9 +49,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
return
|
||||
|
||||
nest = hass.data[DATA_NEST]
|
||||
conf = config.get(CONF_MONITORED_CONDITIONS, _VALID_SENSOR_TYPES)
|
||||
|
||||
for variable in conf:
|
||||
# Add all available sensors if no Nest sensor config is set
|
||||
if discovery_info == {}:
|
||||
conditions = _VALID_SENSOR_TYPES
|
||||
else:
|
||||
conditions = discovery_info.get(CONF_MONITORED_CONDITIONS, {})
|
||||
|
||||
for variable in conditions:
|
||||
if variable in _SENSOR_TYPES_DEPRECATED:
|
||||
if variable in DEPRECATED_WEATHER_VARS:
|
||||
wstr = ("Nest no longer provides weather data like %s. See "
|
||||
|
@ -87,22 +67,20 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
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")
|
||||
"binary_sensor.nest/ for valid options.")
|
||||
|
||||
_LOGGER.error(wstr)
|
||||
|
||||
all_sensors = []
|
||||
for structure, device in chain(nest.thermostats(), nest.smoke_co_alarms()):
|
||||
sensors = [NestBasicSensor(structure, device, variable)
|
||||
for variable in conf
|
||||
for variable in conditions
|
||||
if variable in SENSOR_TYPES and device.is_thermostat]
|
||||
sensors += [NestTempSensor(structure, device, variable)
|
||||
for variable in conf
|
||||
for variable in conditions
|
||||
if variable in SENSOR_TEMP_TYPES and device.is_thermostat]
|
||||
sensors += [NestProtectSensor(structure, device, variable)
|
||||
for variable in conf
|
||||
for variable in conditions
|
||||
if variable in PROTECT_VARS and device.is_smoke_co_alarm]
|
||||
all_sensors.extend(sensors)
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ CONF_AUTHENTICATION = 'authentication'
|
|||
CONF_BASE = 'base'
|
||||
CONF_BEFORE = 'before'
|
||||
CONF_BELOW = 'below'
|
||||
CONF_BINARY_SENSORS = 'binary_sensors'
|
||||
CONF_BLACKLIST = 'blacklist'
|
||||
CONF_BRIGHTNESS = 'brightness'
|
||||
CONF_CODE = 'code'
|
||||
|
|
Loading…
Add table
Reference in a new issue