Skip to content
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

Enable local fulfillment google assistant #63218

Merged
merged 15 commits into from
Jan 5, 2022
Merged

Enable local fulfillment google assistant #63218

merged 15 commits into from
Jan 5, 2022

Conversation

LoekSangers
Copy link
Contributor

@LoekSangers LoekSangers commented Jan 2, 2022

Proposed change

Adding support for configuring Google Assistant Local Fulfillment, the actual request handling already exists, just adding the ability to enable it.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

Not applicable.

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Not sure as I am extending an existing component

To help with the load of incoming pull requests:

@homeassistant
Copy link
Contributor

Hi @LoekSangers,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@probot-home-assistant
Copy link

Hey there @home-assistant/cloud, mind taking a look at this pull request as it has been labeled with an integration (google_assistant) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@LoekSangers
Copy link
Contributor Author

Currently looking into writing the tests for the added functionality, but unsure of how to approach this correctly. So any advice is appreciated.

Also still need to write the documentation.

@LoekSangers
Copy link
Contributor Author

Note for people wanting to test this you need to restart the home assistant core after the app.js files have been loaded to your Google device for the registration to work and requests to be fulfilled locally.

@LoekSangers
Copy link
Contributor Author

Is there a way to run tests faster locally?

Currently I run: tox -e py39 -- tests/components/google_assistant/*
but this way I don't get lint, and just running tox takes too much time.

@emontnemery
Copy link
Contributor

emontnemery commented Jan 3, 2022

Is there a way to run tests faster locally?

Yes, it's in the docs: https://developers.home-assistant.io/docs/development_testing#testing-outside-of-tox 👍

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jan 3, 2022
@frenck frenck requested a review from balloob January 3, 2022 20:09
Comment on lines 113 to 115
def local_sdk_user_id(self):
"""Return the user ID to be used for actions received via the local SDK."""
return list(self._store.agent_user_ids.keys())[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs to be updated to receive the webhook ID that received the actions and map it to the correct user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the best way to approach this is to make the used user id a configuration for the component. This would support the use case as describe by 1. above. As far as I can tell the local sdk does not send this information and has no way of knowing which user agent id should be used otherwise.

Having it be webhook dependent does not really make sense as we only send this webhook information for local fulfillment and we send it in a field that will get overwritten by the next sync with different data, i.e. the way we sync all devices for all user agent ids, to me look like we will only have the last synced value stored by google (as the device id stays the same).

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Jan 3, 2022
@LoekSangers
Copy link
Contributor Author

@balloob @frenck Could you review the approach and let me know whether you agree or not? Currently the tests don't pass as I have not updated them, because if this is not the approach you want to go with that is just wasted effort. (I did test locally that the code works as intended though ;)).

@LoekSangers
Copy link
Contributor Author

Not sure what caused the check to not pass, but I think the pr is done and can be reviewed again.

@frenck
Copy link
Member

frenck commented Jan 4, 2022

image
That can be safely ignored, not your fault. I've opened/merged a PR earlier today to catch that one.

@@ -161,6 +162,10 @@ def local_sdk_user_id(self):
"""Return the user ID to be used for actions received via the local SDK."""
raise NotImplementedError

def get_webhook_id(self, agent_user_id):
"""Return the webhook ID to be used for actions for a given agent user id via the local SDK."""
return self.local_sdk_webhook_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of this property altogether. For cloud/google_config.py you can just rename the property implementation to get_webhook_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this and also created a get_local_agent_user_id to simplify the use of the helper classes (i.e. move the methods back to helper from http).

@balloob
Copy link
Member

balloob commented Jan 5, 2022

Nice! looks good.

@LoekSangers
Copy link
Contributor Author

Awesome!

@balloob balloob merged commit 25fe213 into home-assistant:dev Jan 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants