core/homeassistant/components/nest.py

63 lines
1.5 KiB
Python
Raw Normal View History

"""
Support for Nest thermostats and protect smoke alarms.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/climate.nest/
"""
import logging
import socket
2016-04-01 14:31:11 +00:00
import voluptuous as vol
2016-02-19 05:27:50 +00:00
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
2016-05-21 18:57:33 +00:00
REQUIREMENTS = ['python-nest==2.9.2']
DOMAIN = 'nest'
NEST = None
2016-04-01 14:31:11 +00:00
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str
})
}, 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.")
def protect_devices():
"""Generator returning list of protect devices."""
try:
for structure in NEST.structures:
for device in structure.protectdevices:
yield(structure, device)
except socket.error:
_LOGGER.error("Connection error logging into the nest web service.")
# pylint: disable=unused-argument
def setup(hass, config):
2016-03-07 17:49:31 +00:00
"""Setup the Nest thermostat component."""
global NEST
conf = config[DOMAIN]
username = conf[CONF_USERNAME]
password = conf[CONF_PASSWORD]
2016-01-14 21:17:28 +00:00
import nest
NEST = nest.Nest(username, password)
return True