Fix google assistant request sync service call (#17415)

* Update __init__.py

* Add optional agent_user_id field to request_sync service

* Update services.yaml
This commit is contained in:
Jason Hu 2018-11-27 05:57:42 -08:00 committed by Paulus Schoutsen
parent 87507c4b6f
commit 4d5338a1b0
2 changed files with 7 additions and 4 deletions

View File

@ -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:

View File

@ -1,2 +1,5 @@
request_sync:
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.