Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 31 additions & 4 deletions homeassistant/components/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from concurrent.futures import ThreadPoolExecutor
import logging
import socket
from datetime import datetime, timedelta

import voluptuous as vol

Expand All @@ -19,7 +20,7 @@
async_dispatcher_connect
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['python-nest==4.0.1']
REQUIREMENTS = ['python-nest==4.0.2']

_CONFIGURING = {}
_LOGGER = logging.getLogger(__name__)
Expand All @@ -36,14 +37,23 @@

ATTR_HOME_MODE = 'home_mode'
ATTR_STRUCTURE = 'structure'
ATTR_TRIP_ID = 'trip_id'
ATTR_ETA = 'eta'
ATTR_ETA_WINDOW = 'eta_window'

HOME_MODE_AWAY = 'away'
HOME_MODE_HOME = 'home'

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)
vol.Required(ATTR_HOME_MODE): vol.In([HOME_MODE_AWAY, HOME_MODE_HOME]),
vol.Optional(ATTR_STRUCTURE): vol.All(cv.ensure_list, cv.string),
vol.Optional(ATTR_TRIP_ID): cv.string,
vol.Optional(ATTR_ETA): cv.time_period_str,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a time_period instead of time_period_str.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in #14938

vol.Optional(ATTR_ETA_WINDOW): cv.time_period_str
})

CONFIG_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -148,7 +158,11 @@ async def async_setup_nest(hass, nest, config, pin=None):
hass, component, DOMAIN, discovered, config)

def set_mode(service):
"""Set the home/away mode for a Nest structure."""
"""
Set the home/away mode for a Nest structure.

You can set optional eta information when set mode to away.
"""
if ATTR_STRUCTURE in service.data:
structures = service.data[ATTR_STRUCTURE]
else:
Expand All @@ -158,6 +172,19 @@ def set_mode(service):
if structure.name in structures:
_LOGGER.info("Setting mode for %s", structure.name)
structure.away = service.data[ATTR_HOME_MODE]

if service.data[ATTR_HOME_MODE] == HOME_MODE_AWAY \
and ATTR_ETA in service.data:
now = datetime.utcnow()
eta_begin = now + service.data[ATTR_ETA]
eta_window = service.data.get(ATTR_ETA_WINDOW,
timedelta(minutes=1))
eta_end = eta_begin + eta_window
trip_id = service.data.get(
ATTR_TRIP_ID, "trip_{}".format(int(now.timestamp())))
_LOGGER.info("Setting eta for %s, eta window starts at "
"%s ends at %s", trip_id, eta_begin, eta_end)
structure.set_eta(trip_id, eta_begin, eta_end)
else:
_LOGGER.error("Invalid structure %s",
service.data[ATTR_STRUCTURE])
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# color_status: "gray", "green", "yellow", "red"
'color_status']

STRUCTURE_SENSOR_TYPES = ['eta']
STRUCTURE_SENSOR_TYPES = ['eta', 'security_state']

_VALID_SENSOR_TYPES = SENSOR_TYPES + TEMP_SENSOR_TYPES + PROTECT_SENSOR_TYPES \
+ STRUCTURE_SENSOR_TYPES
Expand Down
25 changes: 25 additions & 0 deletions homeassistant/components/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,28 @@ shopping_list:
name:
description: The name of the item to mark as completed.
example: Beer

nest:
set_mode:
description: >
Set the home/away mode for a Nest structure.
Set to away mode will also set Estimated Arrival Time if provided.
Set ETA will cause the thermostat to begin warming or cooling the home before the user arrives.
After ETA set other Automation can read ETA sensor as a signal to prepare the home for
the user's arrival.
fields:
home_mode:
description: home or away
example: home
structure:
description: Optional structure name. Default set all structures managed by Home Assistant.
example: My Home
eta:
description: Optional Estimated Arrival Time from now.
example: 0:10
eta_window:
description: Optional ETA window. Default is 1 minute.
example: 0:5
trip_id:
description: Optional identity of a trip. Using the same trip_ID will update the estimation.
example: trip_back_home
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ python-mpd2==1.0.0
python-mystrom==0.4.2

# homeassistant.components.nest
python-nest==4.0.1
python-nest==4.0.2

# homeassistant.components.device_tracker.nmap_tracker
python-nmap==0.6.1
Expand Down