-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix google assistant request sync service call #17415
Conversation
I am new on this project. I have trouble configuring SSL on a dev env.
On
If you have some advise on how I could test this feature easily fell free to help me. |
@CedrickFlocon can you direct apply my change to your production instance? Since the changes only 2 lines, you can directly edit your local |
@awarecan I try but I wasn't able to locate the source code directory. If I well understand the project, the source code should be in a docker container ? |
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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always send the same agent_user_id as was set in https://github.com/home-assistant/home-assistant/blob/bd450ee9ffdb7e7aa765070a1c86118cde6f9e1b/homeassistant/components/google_assistant/smart_home.py#L244-L247
If it's not the same, it won't trigger a resync.
So we should just hardcode this to home-assistant
since this is a single tenant skill anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also noted in the original documentation as well. Failing to set a consistent Agent User ID causes the user to relink assistant so they can issue a sync command.
https://www.home-assistant.io/components/google_assistant/#troubleshooting-the-request_sync-service
I think hard-coding it is a much better approach so the user doesn't need to worry about it at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine to supply a const user id for now, since we don't have permission system in place yet. All users will get same access anyway. However, after we introduce permission, thing will become interesting.
Just a reminder, we need a way to supply context.user
to system triggered event, not only for this particular issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rethink it again. I should not revert user id to a fixed value only because it breaks automation script. Instead, I am going to add an optional field to the service call, so if user need it, can be provided in the automation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case of supporting multiple agent_user_id ? It's linked to a test skill and this is the only instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have multiple Google users, they can link to different HA user. If those HA users have different permission, they will get different devices linked in Google Assistant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.
In that case we should have this service fail if not called from the context of a user?
Is this ready to be tested? |
Yes, ready for test. |
Ok, Will run this through in a bit and report back. |
fields: | ||
agent_user_id: | ||
description: [Optional] specific Home Assistant user id to sync with Google Assistant. Do no need when you call this services through Home Assistant front end or API. Used in automation script or other place where context.user_id is missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brackets will fail yaml and produce a traceback. In testing I removed the brackets and this will load.
I think the way this is worded is slightly confusing. Perhaps try the below?
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
Sorry for the delay. Had some things come up. I tested two different ways.
This above produces the same 400 error as noted in the related issue.
This above produces a 404 not found. Also, not sure exactly why but this change caused severe slowdown during HA startup even without any automations using the sync service. Both my Google Calendar and Nest components get stuck and never load. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks fine
@balloob This change causes a 404 on the request. How does this change look fine? |
You get a 404 if the ID is not the same as the one that you used to sync with. So you might have gotten the ID wrong. |
I validated the ID was correct. I even created a 2nd account and tried this on my dev environment. Still gets a 404. I think this needs more testing. |
@balloob @awarecan I was able to find some time to test this further. I was confused by the documentation where previously we could specify a user_agent_id. I cannot recall the reasons why but most had used the user_id of their respective google accounts. There was no particular reason. Since the submission of this PR, the init.py has been updated to allow GA to "unlock". This PR was never merged to master (At least that I can see). I can provide a new PR and can confirm these changes do in fact resolve the issue. Sorry for the long delay and thank you @awarecan for the help. |
I opened #19113 but I guess the changes in this PR for init.py are already merged to dev so they just need to be merged to master. I did update the services.yaml and the description. |
Description:
context.user_id
will be None ifrequest_sync
service call was triggered by platform event in Automation.The fix add an optional
agent_user_id
field torequest_sync
service, so that automation script can provide the user idRelated issue (if applicable): fixes #17380
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests pass