Nest config validation (#1810)

* Config validation for Nest platforms.
pull/1811/head
Jan Harkes 2016-04-12 00:52:19 -04:00 committed by Paulus Schoutsen
parent 656e187729
commit 9d848731d9
4 changed files with 73 additions and 72 deletions

View File

@ -4,12 +4,14 @@ Support for Nest Thermostat Binary Sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.nest/ https://home-assistant.io/components/binary_sensor.nest/
""" """
import logging import voluptuous as vol
import socket
import homeassistant.components.nest as nest import homeassistant.components.nest as nest
from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.sensor.nest import NestSensor from homeassistant.components.sensor.nest import NestSensor
from homeassistant.const import (
CONF_PLATFORM, CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS
)
DEPENDENCIES = ['nest'] DEPENDENCIES = ['nest']
BINARY_TYPES = ['fan', BINARY_TYPES = ['fan',
@ -23,25 +25,19 @@ BINARY_TYPES = ['fan',
'hvac_emer_heat_state', 'hvac_emer_heat_state',
'online'] 'online']
PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): nest.DOMAIN,
vol.Optional(CONF_SCAN_INTERVAL):
vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Required(CONF_MONITORED_CONDITIONS): [vol.In(BINARY_TYPES)],
})
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Nest binary sensors.""" """Setup Nest binary sensors."""
logger = logging.getLogger(__name__) for structure, device in nest.devices():
try: add_devices([NestBinarySensor(structure, device, variable)
for structure in nest.NEST.structures: for variable in config[CONF_MONITORED_CONDITIONS]])
for device in structure.devices:
for variable in config['monitored_conditions']:
if variable in BINARY_TYPES:
add_devices([NestBinarySensor(structure,
device,
variable)])
else:
logger.error('Nest sensor type: "%s" does not exist',
variable)
except socket.error:
logger.error(
"Connection error logging into the nest web service."
)
class NestBinarySensor(NestSensor, BinarySensorDevice): class NestBinarySensor(NestSensor, BinarySensorDevice):

View File

@ -4,6 +4,9 @@ Support for Nest thermostats.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.nest/ https://home-assistant.io/components/thermostat.nest/
""" """
import logging
import socket
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
@ -20,14 +23,27 @@ CONFIG_SCHEMA = vol.Schema({
}) })
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
_LOGGER = logging.getLogger(__name__)
def devices():
"""Generator returning list of devices and their location."""
try:
for structure in NEST.structures:
for device in structure.devices:
yield (structure, device)
except socket.error:
_LOGGER.error("Connection error logging into the nest web service.")
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup(hass, config): def setup(hass, config):
"""Setup the Nest thermostat component.""" """Setup the Nest thermostat component."""
global NEST global NEST
username = config[DOMAIN].get(CONF_USERNAME) conf = config[DOMAIN]
password = config[DOMAIN].get(CONF_PASSWORD) username = conf[CONF_USERNAME]
password = conf[CONF_PASSWORD]
import nest import nest

View File

@ -4,12 +4,13 @@ Support for Nest Thermostat Sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.nest/ https://home-assistant.io/components/sensor.nest/
""" """
import logging import voluptuous as vol
import socket
import homeassistant.components.nest as nest import homeassistant.components.nest as nest
from homeassistant.const import TEMP_CELCIUS
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.const import (
TEMP_CELCIUS, CONF_PLATFORM, CONF_SCAN_INTERVAL, CONF_MONITORED_CONDITIONS
)
DEPENDENCIES = ['nest'] DEPENDENCIES = ['nest']
SENSOR_TYPES = ['humidity', SENSOR_TYPES = ['humidity',
@ -19,49 +20,42 @@ SENSOR_TYPES = ['humidity',
'last_connection', 'last_connection',
'battery_level'] 'battery_level']
WEATHER_VARIABLES = ['weather_condition', 'weather_temperature', WEATHER_VARS = {'weather_humidity': 'humidity',
'weather_humidity', 'weather_temperature': 'temperature',
'wind_speed', 'wind_direction'] 'weather_condition': 'condition',
'wind_speed': 'kph',
JSON_VARIABLE_NAMES = {'weather_humidity': 'humidity', 'wind_direction': 'direction'}
'weather_temperature': 'temperature',
'weather_condition': 'condition',
'wind_speed': 'kph',
'wind_direction': 'direction'}
SENSOR_UNITS = {'humidity': '%', 'battery_level': 'V', SENSOR_UNITS = {'humidity': '%', 'battery_level': 'V',
'kph': 'kph', 'temperature': '°C'} 'kph': 'kph', 'temperature': '°C'}
SENSOR_TEMP_TYPES = ['temperature', 'target'] SENSOR_TEMP_TYPES = ['temperature', 'target']
_VALID_SENSOR_TYPES = SENSOR_TYPES + SENSOR_TEMP_TYPES + \
list(WEATHER_VARS.keys())
PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): nest.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)],
})
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Nest Sensor.""" """Setup the Nest Sensor."""
logger = logging.getLogger(__name__) for structure, device in nest.devices():
try: sensors = [NestBasicSensor(structure, device, variable)
for structure in nest.NEST.structures: for variable in config[CONF_MONITORED_CONDITIONS]
for device in structure.devices: if variable in SENSOR_TYPES]
for variable in config['monitored_conditions']: sensors += [NestTempSensor(structure, device, variable)
if variable in SENSOR_TYPES: for variable in config[CONF_MONITORED_CONDITIONS]
add_devices([NestBasicSensor(structure, if variable in SENSOR_TEMP_TYPES]
device, sensors += [NestWeatherSensor(structure, device,
variable)]) WEATHER_VARS[variable])
elif variable in SENSOR_TEMP_TYPES: for variable in config[CONF_MONITORED_CONDITIONS]
add_devices([NestTempSensor(structure, if variable in WEATHER_VARS]
device, add_devices(sensors)
variable)])
elif variable in WEATHER_VARIABLES:
json_variable = JSON_VARIABLE_NAMES.get(variable, None)
add_devices([NestWeatherSensor(structure,
device,
json_variable)])
else:
logger.error('Nest sensor type: "%s" does not exist',
variable)
except socket.error:
logger.error(
"Connection error logging into the nest web service."
)
class NestSensor(Entity): class NestSensor(Entity):

View File

@ -4,31 +4,26 @@ Support for Nest thermostats.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.nest/ https://home-assistant.io/components/thermostat.nest/
""" """
import logging import voluptuous as vol
import socket
import homeassistant.components.nest as nest import homeassistant.components.nest as nest
from homeassistant.components.thermostat import ( from homeassistant.components.thermostat import (
STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice) STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice)
from homeassistant.const import TEMP_CELCIUS from homeassistant.const import TEMP_CELCIUS, CONF_PLATFORM, CONF_SCAN_INTERVAL
DEPENDENCIES = ['nest'] DEPENDENCIES = ['nest']
PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): nest.DOMAIN,
vol.Optional(CONF_SCAN_INTERVAL):
vol.All(vol.Coerce(int), vol.Range(min=1)),
})
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Nest thermostat.""" """Setup the Nest thermostat."""
logger = logging.getLogger(__name__) add_devices([NestThermostat(structure, device)
for structure, device in nest.devices()])
try:
add_devices([
NestThermostat(structure, device)
for structure in nest.NEST.structures
for device in structure.devices
])
except socket.error:
logger.error(
"Connection error logging into the nest web service."
)
class NestThermostat(ThermostatDevice): class NestThermostat(ThermostatDevice):