Skip to content

Google Assistant SDK integration#82328

Merged
allenporter merged 4 commits into
home-assistant:devfrom
tronikos:google-assistant-sdk
Dec 9, 2022
Merged

Google Assistant SDK integration#82328
allenporter merged 4 commits into
home-assistant:devfrom
tronikos:google-assistant-sdk

Conversation

@tronikos
Copy link
Copy Markdown
Member

@tronikos tronikos commented Nov 18, 2022

Proposed change

Allow sending commands and broadcast messages to Google Assistant.

  • Sending commands is useful to control devices supported by Google Assistant but not Home Assistant.
  • Broadcasting messages is useful to not interrupt music playback. Broadcast service is setup as a notify service to be able to use it in alerts etc. It optionally supports targets (Google Assistant currently seems to only support rooms as targets).

Requirements for this to work:

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

This is an alternative approach to #82188

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:

  • 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.

To help with the load of incoming pull requests:

@elupus
Copy link
Copy Markdown
Contributor

elupus commented Nov 26, 2022

Not forgotten. I've just not gotten around to testing this.

Comment thread homeassistant/components/google_assistant_sdk/config_flow.py Outdated
Comment thread homeassistant/components/google_assistant_sdk/__init__.py Outdated
Copy link
Copy Markdown
Contributor

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

So this is using notify as the first platform.. From my impression of the docs you added, it seems like this can really represent anything that google assistant do (e.g. theoretically, it could expose a lock since you can tell google assistant to unlock your lock). Am I understanding that right?

@tronikos
Copy link
Copy Markdown
Member Author

tronikos commented Dec 7, 2022

Yes your understanding is right. I've personally been using this mostly for the broadcast announcements, controlling nest guard and playing relaxing sounds in bedroom speakers in a schedule.
In a future version I might modify the underlying library to parse the HTML response from Google Assistant to be able to expose the status of devices you send commands to. That would allow users to create template devices.

This is to improve diff of the next commit with the actual implementation.

Commands used:
cp -r homeassistant/components/google_sheets/ homeassistant/components/google_assistant_sdk/
cp -r tests/components/google_sheets/ tests/components/google_assistant_sdk/

find homeassistant/components/google_assistant_sdk/ tests/components/google_assistant_sdk/ -type f | xargs sed -i \
-e 's@google_sheets@google_assistant_sdk@g' \
-e 's@Google Sheets@Google Assistant SDK@g' \
-e 's@tkdrob@tronikos@g'
Allows sending commands and broadcast messages to Google Assistant.
@tronikos tronikos force-pushed the google-assistant-sdk branch from ea18b91 to 75da4b2 Compare December 8, 2022 04:36
@allenporter
Copy link
Copy Markdown
Contributor

Looks good to merge after CI passes

@allenporter
Copy link
Copy Markdown
Contributor

Looks like there is a protobuf 4 conflict. My impression was that just a few weeks ago were using protobuf 3 as some proejcts were not ready for the proto4 compiler yet (this was blocking a grpc upgrade) but it looks like that has been resolved.

@tronikos
Copy link
Copy Markdown
Member Author

tronikos commented Dec 8, 2022

The problem is the underlying library depends on outdated google-assistant-grpc==0.3.0 which causes the following error when using protobuf 4:

gassist_text\__init__.py:4: in <module>
    from .textinput import TextAssistant
gassist_text\textinput.py:33: in <module>
    from google.assistant.embedded.v1alpha2 import (
.venv\Lib\site-packages\google\assistant\embedded\v1alpha2\embedded_assistant_pb2.py:36: in <module>
    _descriptor.EnumValueDescriptor(
.venv\Lib\site-packages\google\protobuf\descriptor.py:755: in __new__
    _message.Message._CheckCalledFromGeneratedFile()
E   TypeError: Descriptors cannot not be created directly.
E   If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
E   If you cannot immediately regenerate your protos, some other possible workarounds are:
E    1. Downgrade the protobuf package to 3.20.x or lower.
E    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
E   
E   More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

I'll have to check if I can stop depending on google-assistant-grpc and instead include https://github.com/googleapis/googleapis/blob/master/google/assistant/embedded/v1alpha2/embedded_assistant.proto in the library and generate the _pb2.py using the latest protoc.

@allenporter
Copy link
Copy Markdown
Contributor

I'll have to check if I can stop depending on google-assistant-grpc and instead include

Makes sense. That project looks like it has hardly any activity (unclear if its worth upgrading it to protobuf 4)

@tronikos
Copy link
Copy Markdown
Member Author

tronikos commented Dec 9, 2022

PTAL. I believe I fixed the protobuf conflict. gassist-text library now works with either protobuf 3 or 4.

@allenporter allenporter merged commit 5d31673 into home-assistant:dev Dec 9, 2022
@allenporter
Copy link
Copy Markdown
Contributor

@tronikos I was reviewing the delta in the python library tronikos/gassist_text@0.0.2...0.0.4 and saw the build and setup were removed. Do you have an approach to bring that back? Generally, as you improve gassist_text in the future, we'll want to review changelogs to the library as part of the PR, but also using a "standard" build chain is also helpful so we have more confidence pypi and what is committed to github match, but here i realize now I can't tell how this was built.

@tronikos
Copy link
Copy Markdown
Member Author

tronikos commented Dec 9, 2022 via email

@tronikos
Copy link
Copy Markdown
Member Author

tronikos commented Dec 9, 2022 via email

@allenporter
Copy link
Copy Markdown
Contributor

Thank you, I missed the toml addition.

@tronikos tronikos mentioned this pull request Dec 9, 2022
19 tasks
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 10, 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.

3 participants