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:
1 parent
d240ea56d8
commit
321a8be339
4 files changed
+49
-67
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user