From 4d5338a1b0ef7ec3e3d2204eb7e379d90d891272 Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Tue, 27 Nov 2018 05:57:42 -0800 Subject: [PATCH] Fix google assistant request sync service call (#17415) * Update __init__.py * Add optional agent_user_id field to request_sync service * Update services.yaml --- homeassistant/components/google_assistant/__init__.py | 6 +++--- homeassistant/components/google_assistant/services.yaml | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/google_assistant/__init__.py b/homeassistant/components/google_assistant/__init__.py index f444974bc8d..bf0c72ec1c8 100644 --- a/homeassistant/components/google_assistant/__init__.py +++ b/homeassistant/components/google_assistant/__init__.py @@ -33,8 +33,6 @@ _LOGGER = logging.getLogger(__name__) DEPENDENCIES = ['http'] -DEFAULT_AGENT_USER_ID = 'home-assistant' - ENTITY_SCHEMA = vol.Schema({ vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_EXPOSE): cv.boolean, @@ -70,10 +68,12 @@ async def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]): websession = async_get_clientsession(hass) try: with async_timeout.timeout(5, loop=hass.loop): + agent_user_id = call.data.get('agent_user_id') or \ + call.context.user_id res = await websession.post( REQUEST_SYNC_BASE_URL, params={'key': api_key}, - json={'agent_user_id': call.context.user_id}) + json={'agent_user_id': agent_user_id}) _LOGGER.info("Submitted request_sync request to Google") res.raise_for_status() except aiohttp.ClientResponseError: diff --git a/homeassistant/components/google_assistant/services.yaml b/homeassistant/components/google_assistant/services.yaml index 6019b75bd98..7d3af71ac2b 100644 --- a/homeassistant/components/google_assistant/services.yaml +++ b/homeassistant/components/google_assistant/services.yaml @@ -1,2 +1,5 @@ request_sync: - description: Send a request_sync command to Google. \ No newline at end of file + description: Send a request_sync command to Google. + fields: + agent_user_id: + description: Optional. Only needed for automations. Specific Home Assistant user id to sync with Google Assistant. Do not need when you call this service through Home Assistant front end or API. Used in automation script or other place where context.user_id is missing.