Only include agent user ID in SYNC responses (#23497)

pull/23507/head
Paulus Schoutsen 2019-04-28 00:42:06 -07:00 committed by Pascal Vizeli
parent 300d1f44a6
commit b09f5b6743
3 changed files with 10 additions and 12 deletions

View File

@ -100,10 +100,13 @@ class CloudClient(Interface):
return google_conf['filter'](entity.entity_id)
username = self._hass.data[DOMAIN].claims["cognito:username"]
self._google_config = ga_h.Config(
should_expose=should_expose,
secure_devices_pin=self._prefs.google_secure_devices_pin,
entity_config=google_conf.get(CONF_ENTITY_CONFIG),
agent_user_id=username,
)
# Set it to the latest.
@ -149,19 +152,10 @@ class CloudClient(Interface):
if not self._prefs.google_enabled:
return ga.turned_off_response(payload)
answer = await ga.async_handle_message(
return await ga.async_handle_message(
self._hass, self.google_config, self.prefs.cloud_user, payload
)
# Fix AgentUserId
try:
cloud = self._hass.data[DOMAIN]
answer['payload']['agentUserId'] = cloud.claims['cognito:username']
except (TypeError, KeyError):
return ga.turned_off_response(payload)
return answer
async def async_webhook_message(
self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
"""Process cloud webhook message to client."""

View File

@ -20,12 +20,16 @@ class Config:
"""Hold the configuration for Google Assistant."""
def __init__(self, should_expose,
entity_config=None, secure_devices_pin=None):
entity_config=None, secure_devices_pin=None,
agent_user_id=None):
"""Initialize the configuration."""
self.should_expose = should_expose
self.entity_config = entity_config or {}
self.secure_devices_pin = secure_devices_pin
# Agent User Id to use for query responses
self.agent_user_id = agent_user_id
class RequestData:
"""Hold data associated with a particular request."""

View File

@ -99,7 +99,7 @@ async def async_devices_sync(hass, data, payload):
devices.append(serialized)
response = {
'agentUserId': data.context.user_id,
'agentUserId': data.config.agent_user_id or data.context.user_id,
'devices': devices,
}