Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions homeassistant/components/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ def should_expose(entity):

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.
Expand Down Expand Up @@ -149,19 +152,10 @@ async def async_google_message(
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."""
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_assistant/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down