Implement support for NEST structures. (#2736)
* Implement support for NEST structures. * Conform to balloobbot style preferences. * Log to debug level rather than info level. * Use config validation to coerce list format if supplied as string. * Use list comprehension for more succinct code. * Conform to project linting standards.
This commit is contained in:
parent
5d4dc713f2
commit
78b2c87b54
2 changed files with 26 additions and 6 deletions
|
@ -8,18 +8,22 @@ import logging
|
|||
import socket
|
||||
|
||||
import voluptuous as vol
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONF_STRUCTURE
|
||||
|
||||
REQUIREMENTS = ['python-nest==2.9.2']
|
||||
DOMAIN = 'nest'
|
||||
|
||||
NEST = None
|
||||
|
||||
STRUCTURES_TO_INCLUDE = None
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_USERNAME): str,
|
||||
vol.Required(CONF_PASSWORD): str
|
||||
vol.Required(CONF_PASSWORD): str,
|
||||
vol.Optional(CONF_STRUCTURE): vol.All(cv.ensure_list, cv.string)
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -30,8 +34,12 @@ def devices():
|
|||
"""Generator returning list of devices and their location."""
|
||||
try:
|
||||
for structure in NEST.structures:
|
||||
for device in structure.devices:
|
||||
yield (structure, device)
|
||||
if structure.name in STRUCTURES_TO_INCLUDE:
|
||||
for device in structure.devices:
|
||||
yield (structure, device)
|
||||
else:
|
||||
_LOGGER.debug("Ignoring structure %s, not in %s",
|
||||
structure.name, STRUCTURES_TO_INCLUDE)
|
||||
except socket.error:
|
||||
_LOGGER.error("Connection error logging into the nest web service.")
|
||||
|
||||
|
@ -40,8 +48,12 @@ def protect_devices():
|
|||
"""Generator returning list of protect devices."""
|
||||
try:
|
||||
for structure in NEST.structures:
|
||||
for device in structure.protectdevices:
|
||||
yield(structure, device)
|
||||
if structure.name in STRUCTURES_TO_INCLUDE:
|
||||
for device in structure.protectdevices:
|
||||
yield(structure, device)
|
||||
else:
|
||||
_LOGGER.info("Ignoring structure %s, not in %s",
|
||||
structure.name, STRUCTURES_TO_INCLUDE)
|
||||
except socket.error:
|
||||
_LOGGER.error("Connection error logging into the nest web service.")
|
||||
|
||||
|
@ -50,6 +62,7 @@ def protect_devices():
|
|||
def setup(hass, config):
|
||||
"""Setup the Nest thermostat component."""
|
||||
global NEST
|
||||
global STRUCTURES_TO_INCLUDE
|
||||
|
||||
conf = config[DOMAIN]
|
||||
username = conf[CONF_USERNAME]
|
||||
|
@ -59,4 +72,10 @@ def setup(hass, config):
|
|||
|
||||
NEST = nest.Nest(username, password)
|
||||
|
||||
if CONF_STRUCTURE not in conf:
|
||||
STRUCTURES_TO_INCLUDE = [s.name for s in NEST.structures]
|
||||
else:
|
||||
STRUCTURES_TO_INCLUDE = conf[CONF_STRUCTURE]
|
||||
|
||||
_LOGGER.debug("Structures to include: %s", STRUCTURES_TO_INCLUDE)
|
||||
return True
|
||||
|
|
|
@ -59,6 +59,7 @@ CONF_SCAN_INTERVAL = 'scan_interval'
|
|||
CONF_SENSOR_CLASS = 'sensor_class'
|
||||
CONF_SSL = 'ssl'
|
||||
CONF_STATE = 'state'
|
||||
CONF_STRUCTURE = 'structure'
|
||||
CONF_TEMPERATURE_UNIT = 'temperature_unit'
|
||||
CONF_TIME_ZONE = 'time_zone'
|
||||
CONF_TOKEN = 'token'
|
||||
|
|
Loading…
Add table
Reference in a new issue