From f899ce8fbf769f8bd211120fa2aa1f000ca3ec1c Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Thu, 22 Feb 2018 15:24:41 -0800 Subject: [PATCH] Adding RoomHinting to GoogleAssistant to allow for room annotations. (#12598) --- homeassistant/components/google_assistant/__init__.py | 5 +++-- homeassistant/components/google_assistant/const.py | 1 + homeassistant/components/google_assistant/smart_home.py | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google_assistant/__init__.py b/homeassistant/components/google_assistant/__init__.py index aac258b4e93..20dee082a08 100644 --- a/homeassistant/components/google_assistant/__init__.py +++ b/homeassistant/components/google_assistant/__init__.py @@ -27,7 +27,7 @@ from .const import ( CONF_EXPOSE_BY_DEFAULT, DEFAULT_EXPOSE_BY_DEFAULT, CONF_EXPOSED_DOMAINS, DEFAULT_EXPOSED_DOMAINS, CONF_AGENT_USER_ID, CONF_API_KEY, SERVICE_REQUEST_SYNC, REQUEST_SYNC_BASE_URL, CONF_ENTITY_CONFIG, - CONF_EXPOSE, CONF_ALIASES + CONF_EXPOSE, CONF_ALIASES, CONF_ROOM_HINT ) from .auth import GoogleAssistantAuthView from .http import async_register_http @@ -43,7 +43,8 @@ ENTITY_SCHEMA = vol.Schema({ vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_TYPE): vol.In(MAPPING_COMPONENT), vol.Optional(CONF_EXPOSE): cv.boolean, - vol.Optional(CONF_ALIASES): vol.All(cv.ensure_list, [cv.string]) + vol.Optional(CONF_ALIASES): vol.All(cv.ensure_list, [cv.string]), + vol.Optional(CONF_ROOM_HINT): cv.string }) CONFIG_SCHEMA = vol.Schema( diff --git a/homeassistant/components/google_assistant/const.py b/homeassistant/components/google_assistant/const.py index 0483f424ca3..1f1ae4682b4 100644 --- a/homeassistant/components/google_assistant/const.py +++ b/homeassistant/components/google_assistant/const.py @@ -13,6 +13,7 @@ CONF_CLIENT_ID = 'client_id' CONF_ALIASES = 'aliases' CONF_AGENT_USER_ID = 'agent_user_id' CONF_API_KEY = 'api_key' +CONF_ROOM_HINT = 'room' DEFAULT_EXPOSE_BY_DEFAULT = True DEFAULT_EXPOSED_DOMAINS = [ diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index a2444e46ec1..f638b847bcb 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -33,7 +33,8 @@ from .const import ( TRAIT_ONOFF, TRAIT_BRIGHTNESS, TRAIT_COLOR_TEMP, TRAIT_RGB_COLOR, TRAIT_SCENE, TRAIT_TEMPERATURE_SETTING, TYPE_LIGHT, TYPE_SCENE, TYPE_SWITCH, TYPE_THERMOSTAT, - CONF_ALIASES, CLIMATE_SUPPORTED_MODES, CLIMATE_MODE_HEATCOOL + CONF_ALIASES, CONF_ROOM_HINT, CLIMATE_SUPPORTED_MODES, + CLIMATE_MODE_HEATCOOL ) HANDLERS = Registry() @@ -124,6 +125,11 @@ def entity_to_device(entity: Entity, config: Config, units: UnitSystem): if aliases: device['name']['nicknames'] = aliases + # add room hint if annotated + room = entity_config.get(CONF_ROOM_HINT) + if room: + device['roomHint'] = room + # add trait if entity supports feature if class_data[2]: supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)