Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions homeassistant/components/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@
CONF_CLIENT_ID = 'client_id'
CONF_CLIENT_SECRET = 'client_secret'

ATTR_HOME_MODE = 'home_mode'
ATTR_STRUCTURE = 'structure'

SENSOR_SCHEMA = vol.Schema({
vol.Optional(CONF_MONITORED_CONDITIONS): vol.All(cv.ensure_list)
})

AWAY_SCHEMA = vol.Schema({
vol.Required(ATTR_HOME_MODE): cv.string,
vol.Optional(ATTR_STRUCTURE): vol.All(cv.ensure_list, cv.string)
})

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_CLIENT_ID): cv.string,
Expand Down Expand Up @@ -126,6 +134,24 @@ def setup(hass, config):
client_id=client_id, client_secret=client_secret)
setup_nest(hass, nest, config)

def set_mode(service):
"""Set the home/away mode for a Nest structure."""
if ATTR_STRUCTURE in service.data:
structures = service.data[ATTR_STRUCTURE]
else:
structures = hass.data[DATA_NEST].local_structure

for structure in nest.structures:
if structure.name in structures:
_LOGGER.info("Setting mode for %s", structure.name)
structure.away = service.data[ATTR_HOME_MODE]
else:
_LOGGER.error("Invalid structure %s",
service.data[ATTR_STRUCTURE])

hass.services.register(
DOMAIN, 'set_mode', set_mode, schema=AWAY_SCHEMA)

return True


Expand All @@ -138,21 +164,21 @@ def __init__(self, hass, conf, nest):
self.nest = nest

if CONF_STRUCTURE not in conf:
self._structure = [s.name for s in nest.structures]
self.local_structure = [s.name for s in nest.structures]
else:
self._structure = conf[CONF_STRUCTURE]
_LOGGER.debug("Structures to include: %s", self._structure)
self.local_structure = conf[CONF_STRUCTURE]
_LOGGER.debug("Structures to include: %s", self.local_structure)

def thermostats(self):
"""Generate a list of thermostats and their location."""
try:
for structure in self.nest.structures:
if structure.name in self._structure:
if structure.name in self.local_structure:
for device in structure.thermostats:
yield (structure, device)
else:
_LOGGER.debug("Ignoring structure %s, not in %s",
structure.name, self._structure)
structure.name, self.local_structure)
except socket.error:
_LOGGER.error(
"Connection error logging into the nest web service.")
Expand All @@ -161,12 +187,12 @@ def smoke_co_alarms(self):
"""Generate a list of smoke co alarams."""
try:
for structure in self.nest.structures:
if structure.name in self._structure:
if structure.name in self.local_structure:
for device in structure.smoke_co_alarms:
yield(structure, device)
else:
_LOGGER.info("Ignoring structure %s, not in %s",
structure.name, self._structure)
structure.name, self.local_structure)
except socket.error:
_LOGGER.error(
"Connection error logging into the nest web service.")
Expand All @@ -175,12 +201,12 @@ def cameras(self):
"""Generate a list of cameras."""
try:
for structure in self.nest.structures:
if structure.name in self._structure:
if structure.name in self.local_structure:
for device in structure.cameras:
yield(structure, device)
else:
_LOGGER.info("Ignoring structure %s, not in %s",
structure.name, self._structure)
structure.name, self.local_structure)
except socket.error:
_LOGGER.error(
"Connection error logging into the nest web service.")