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
|
from itertools import chain
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
from homeassistant.components.binary_sensor import (BinarySensorDevice)
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
|
||||||
BinarySensorDevice, PLATFORM_SCHEMA)
|
|
||||||
from homeassistant.components.sensor.nest import NestSensor
|
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
|
from homeassistant.components.nest import DATA_NEST
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
DEPENDENCIES = ['nest']
|
DEPENDENCIES = ['nest']
|
||||||
|
|
||||||
|
@ -42,17 +38,6 @@ _BINARY_TYPES_DEPRECATED = [
|
||||||
|
|
||||||
_VALID_BINARY_SENSOR_TYPES = BINARY_TYPES + CLIMATE_BINARY_TYPES \
|
_VALID_BINARY_SENSOR_TYPES = BINARY_TYPES + CLIMATE_BINARY_TYPES \
|
||||||
+ CAMERA_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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -63,15 +48,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
return
|
return
|
||||||
|
|
||||||
nest = hass.data[DATA_NEST]
|
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:
|
if variable in _BINARY_TYPES_DEPRECATED:
|
||||||
wstr = (variable + " is no a longer supported "
|
wstr = (variable + " is no a longer supported "
|
||||||
"monitored_conditions. See "
|
"monitored_conditions. See "
|
||||||
"https://home-assistant.io/components/binary_sensor.nest/ "
|
"https://home-assistant.io/components/binary_sensor.nest/ "
|
||||||
"for valid options, or remove monitored_conditions "
|
"for valid options.")
|
||||||
"entirely to get a reasonable default")
|
|
||||||
_LOGGER.error(wstr)
|
_LOGGER.error(wstr)
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
|
@ -80,16 +69,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
nest.cameras())
|
nest.cameras())
|
||||||
for structure, device in device_chain:
|
for structure, device in device_chain:
|
||||||
sensors += [NestBinarySensor(structure, device, variable)
|
sensors += [NestBinarySensor(structure, device, variable)
|
||||||
for variable in conf
|
for variable in conditions
|
||||||
if variable in BINARY_TYPES]
|
if variable in BINARY_TYPES]
|
||||||
sensors += [NestBinarySensor(structure, device, variable)
|
sensors += [NestBinarySensor(structure, device, variable)
|
||||||
for variable in conf
|
for variable in conditions
|
||||||
if variable in CLIMATE_BINARY_TYPES
|
if variable in CLIMATE_BINARY_TYPES
|
||||||
and device.is_thermostat]
|
and device.is_thermostat]
|
||||||
|
|
||||||
if device.is_camera:
|
if device.is_camera:
|
||||||
sensors += [NestBinarySensor(structure, device, variable)
|
sensors += [NestBinarySensor(structure, device, variable)
|
||||||
for variable in conf
|
for variable in conditions
|
||||||
if variable in CAMERA_BINARY_TYPES]
|
if variable in CAMERA_BINARY_TYPES]
|
||||||
for activity_zone in device.activity_zones:
|
for activity_zone in device.activity_zones:
|
||||||
sensors += [NestActivityZoneSensor(structure,
|
sensors += [NestActivityZoneSensor(structure,
|
||||||
|
|
|
@ -11,7 +11,9 @@ import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers import discovery
|
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
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
_CONFIGURING = {}
|
_CONFIGURING = {}
|
||||||
|
@ -30,11 +32,17 @@ NEST_CONFIG_FILE = 'nest.conf'
|
||||||
CONF_CLIENT_ID = 'client_id'
|
CONF_CLIENT_ID = 'client_id'
|
||||||
CONF_CLIENT_SECRET = 'client_secret'
|
CONF_CLIENT_SECRET = 'client_secret'
|
||||||
|
|
||||||
|
SENSOR_SCHEMA = vol.Schema({
|
||||||
|
vol.Optional(CONF_MONITORED_CONDITIONS): vol.All(cv.ensure_list)
|
||||||
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Required(CONF_CLIENT_ID): cv.string,
|
vol.Required(CONF_CLIENT_ID): cv.string,
|
||||||
vol.Required(CONF_CLIENT_SECRET): 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)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
@ -88,9 +96,15 @@ def setup_nest(hass, nest, config, pin=None):
|
||||||
|
|
||||||
_LOGGER.debug("proceeding with discovery")
|
_LOGGER.debug("proceeding with discovery")
|
||||||
discovery.load_platform(hass, 'climate', DOMAIN, {}, config)
|
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)
|
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")
|
_LOGGER.debug("setup done")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -7,15 +7,10 @@ https://home-assistant.io/components/sensor.nest/
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
from homeassistant.components.nest import DATA_NEST
|
||||||
|
|
||||||
from homeassistant.components.nest import (
|
|
||||||
DATA_NEST, DOMAIN)
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (TEMP_CELSIUS, TEMP_FAHRENHEIT,
|
||||||
TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_PLATFORM,
|
CONF_MONITORED_CONDITIONS)
|
||||||
CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS
|
|
||||||
)
|
|
||||||
|
|
||||||
DEPENDENCIES = ['nest']
|
DEPENDENCIES = ['nest']
|
||||||
SENSOR_TYPES = ['humidity',
|
SENSOR_TYPES = ['humidity',
|
||||||
|
@ -26,23 +21,15 @@ SENSOR_TYPES_DEPRECATED = ['last_ip',
|
||||||
'local_ip',
|
'local_ip',
|
||||||
'last_connection']
|
'last_connection']
|
||||||
|
|
||||||
SENSOR_TYPES_DEPRECATED = ['last_ip',
|
|
||||||
'local_ip']
|
|
||||||
|
|
||||||
WEATHER_VARS = {}
|
|
||||||
|
|
||||||
DEPRECATED_WEATHER_VARS = {'weather_humidity': 'humidity',
|
DEPRECATED_WEATHER_VARS = {'weather_humidity': 'humidity',
|
||||||
'weather_temperature': 'temperature',
|
'weather_temperature': 'temperature',
|
||||||
'weather_condition': 'condition',
|
'weather_condition': 'condition',
|
||||||
'wind_speed': 'kph',
|
'wind_speed': 'kph',
|
||||||
'wind_direction': 'direction'}
|
'wind_direction': 'direction'}
|
||||||
|
|
||||||
SENSOR_UNITS = {'humidity': '%',
|
SENSOR_UNITS = {'humidity': '%', 'temperature': '°C'}
|
||||||
'temperature': '°C'}
|
|
||||||
|
|
||||||
PROTECT_VARS = ['co_status',
|
PROTECT_VARS = ['co_status', 'smoke_status', 'battery_health']
|
||||||
'smoke_status',
|
|
||||||
'battery_health']
|
|
||||||
|
|
||||||
PROTECT_VARS_DEPRECATED = ['battery_level']
|
PROTECT_VARS_DEPRECATED = ['battery_level']
|
||||||
|
|
||||||
|
@ -51,19 +38,7 @@ SENSOR_TEMP_TYPES = ['temperature', 'target']
|
||||||
_SENSOR_TYPES_DEPRECATED = SENSOR_TYPES_DEPRECATED \
|
_SENSOR_TYPES_DEPRECATED = SENSOR_TYPES_DEPRECATED \
|
||||||
+ list(DEPRECATED_WEATHER_VARS.keys()) + PROTECT_VARS_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
|
||||||
+ 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)]
|
|
||||||
})
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -74,9 +49,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
return
|
return
|
||||||
|
|
||||||
nest = hass.data[DATA_NEST]
|
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 _SENSOR_TYPES_DEPRECATED:
|
||||||
if variable in DEPRECATED_WEATHER_VARS:
|
if variable in DEPRECATED_WEATHER_VARS:
|
||||||
wstr = ("Nest no longer provides weather data like %s. See "
|
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 "
|
wstr = (variable + " is no a longer supported "
|
||||||
"monitored_conditions. See "
|
"monitored_conditions. See "
|
||||||
"https://home-assistant.io/components/"
|
"https://home-assistant.io/components/"
|
||||||
"binary_sensor.nest/ "
|
"binary_sensor.nest/ for valid options.")
|
||||||
"for valid options, or remove monitored_conditions "
|
|
||||||
"entirely to get a reasonable default")
|
|
||||||
|
|
||||||
_LOGGER.error(wstr)
|
_LOGGER.error(wstr)
|
||||||
|
|
||||||
all_sensors = []
|
all_sensors = []
|
||||||
for structure, device in chain(nest.thermostats(), nest.smoke_co_alarms()):
|
for structure, device in chain(nest.thermostats(), nest.smoke_co_alarms()):
|
||||||
sensors = [NestBasicSensor(structure, device, variable)
|
sensors = [NestBasicSensor(structure, device, variable)
|
||||||
for variable in conf
|
for variable in conditions
|
||||||
if variable in SENSOR_TYPES and device.is_thermostat]
|
if variable in SENSOR_TYPES and device.is_thermostat]
|
||||||
sensors += [NestTempSensor(structure, device, variable)
|
sensors += [NestTempSensor(structure, device, variable)
|
||||||
for variable in conf
|
for variable in conditions
|
||||||
if variable in SENSOR_TEMP_TYPES and device.is_thermostat]
|
if variable in SENSOR_TEMP_TYPES and device.is_thermostat]
|
||||||
sensors += [NestProtectSensor(structure, device, variable)
|
sensors += [NestProtectSensor(structure, device, variable)
|
||||||
for variable in conf
|
for variable in conditions
|
||||||
if variable in PROTECT_VARS and device.is_smoke_co_alarm]
|
if variable in PROTECT_VARS and device.is_smoke_co_alarm]
|
||||||
all_sensors.extend(sensors)
|
all_sensors.extend(sensors)
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ CONF_AUTHENTICATION = 'authentication'
|
||||||
CONF_BASE = 'base'
|
CONF_BASE = 'base'
|
||||||
CONF_BEFORE = 'before'
|
CONF_BEFORE = 'before'
|
||||||
CONF_BELOW = 'below'
|
CONF_BELOW = 'below'
|
||||||
|
CONF_BINARY_SENSORS = 'binary_sensors'
|
||||||
CONF_BLACKLIST = 'blacklist'
|
CONF_BLACKLIST = 'blacklist'
|
||||||
CONF_BRIGHTNESS = 'brightness'
|
CONF_BRIGHTNESS = 'brightness'
|
||||||
CONF_CODE = 'code'
|
CONF_CODE = 'code'
|
||||||
|
|
Loading…
Add table
Reference in a new issue