From 233647e82b1d4e9f7db5325585738ffc448cc4ca Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Sat, 9 Jun 2018 14:12:53 -0700 Subject: [PATCH 1/5] Upgrade python-nest to 4.0.2 --- homeassistant/components/nest.py | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/nest.py b/homeassistant/components/nest.py index 16a0b80d1fd33..7ae8d172066e2 100644 --- a/homeassistant/components/nest.py +++ b/homeassistant/components/nest.py @@ -19,7 +19,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__) diff --git a/requirements_all.txt b/requirements_all.txt index f47bbbdf23e81..6148f6b2adc71 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 From 20595745f17b7eabd5f58c4c9a263b7220f5f045 Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Sat, 9 Jun 2018 17:04:09 -0700 Subject: [PATCH 2/5] Add security_state sensor --- homeassistant/components/sensor/nest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index 88464675c2158..ea7a943881e00 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -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 From 2aaf68ffc3d4736cd770016b9919c27dd8b1dd8c Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Sat, 9 Jun 2018 17:05:34 -0700 Subject: [PATCH 3/5] Extend nest.set_mode service to set eta --- homeassistant/components/nest.py | 32 +++++++++++++++++++++++--- homeassistant/components/services.yaml | 25 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/nest.py b/homeassistant/components/nest.py index 7ae8d172066e2..e835017122af2 100644 --- a/homeassistant/components/nest.py +++ b/homeassistant/components/nest.py @@ -7,6 +7,7 @@ from concurrent.futures import ThreadPoolExecutor import logging import socket +from datetime import datetime, timedelta import voluptuous as vol @@ -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, + vol.Optional(ATTR_ETA_WINDOW): cv.time_period_str }) CONFIG_SCHEMA = vol.Schema({ @@ -148,7 +158,10 @@ 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: @@ -158,6 +171,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]) diff --git a/homeassistant/components/services.yaml b/homeassistant/components/services.yaml index 19bf19a799a26..5d4cd51957aae 100644 --- a/homeassistant/components/services.yaml +++ b/homeassistant/components/services.yaml @@ -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 the identity of a trip. Use same trip_id will update the estimation for a trip. + example: trip_back_home From 751e87716bd485e875d30c5c59224ad3855b4568 Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Sat, 9 Jun 2018 17:35:45 -0700 Subject: [PATCH 4/5] flake8 lint --- homeassistant/components/nest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/nest.py b/homeassistant/components/nest.py index e835017122af2..739572223c61e 100644 --- a/homeassistant/components/nest.py +++ b/homeassistant/components/nest.py @@ -160,6 +160,7 @@ async def async_setup_nest(hass, nest, config, pin=None): def set_mode(service): """ 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: From 41bf7d30a30ed9c93d93d2191f12cd65b57169b4 Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Sun, 10 Jun 2018 07:11:20 -0700 Subject: [PATCH 5/5] Minor wording change. --- homeassistant/components/services.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/services.yaml b/homeassistant/components/services.yaml index 5d4cd51957aae..6b8bded59b83a 100644 --- a/homeassistant/components/services.yaml +++ b/homeassistant/components/services.yaml @@ -599,5 +599,5 @@ nest: description: Optional ETA window. Default is 1 minute. example: 0:5 trip_id: - description: Optional the identity of a trip. Use same trip_id will update the estimation for a trip. + description: Optional identity of a trip. Using the same trip_ID will update the estimation. example: trip_back_home