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

Setup Google Cloud from the UI #121502

Merged
merged 14 commits into from
Sep 2, 2024

Conversation

tronikos
Copy link
Member

@tronikos tronikos commented Jul 8, 2024

Breaking change

Proposed change

Google Cloud can now be setup from the UI

  • I kept the service account info file but to make it easier this is now directly uploaded from the UI and you don't need to manually copy it to the config directory. See
    image
  • I couldn't use application credentials. TTS (and in the future STT) requires https://www.googleapis.com/auth/cloud-platform scope which is sensitive and requires the app to be verified by Google. See image
  • For the few current users of this integration I added an import flow. I decided to still let them have both in parallel in case they are using the tts.google_cloud_say service and avoid a breaking change.
  • I added options flow, see
    image

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

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Jul 8, 2024

Hey there @lufton, mind taking a look at this pull request as it has been labeled with an integration (google_cloud) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of google_cloud can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign google_cloud Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@tronikos tronikos changed the title Google Cloud can now be setup from the UI Setup Google Cloud from the UI Jul 8, 2024
@tronikos tronikos marked this pull request as ready for review July 8, 2024 11:43
Copy link
Contributor

@arturpragacz arturpragacz left a comment

Choose a reason for hiding this comment

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

The addition to .strict-typing could be done as a separate PR to reduce scope.

homeassistant/generated/integrations.json Show resolved Hide resolved
homeassistant/components/google_cloud/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/google_cloud/config_flow.py Outdated Show resolved Hide resolved
tests/components/google_cloud/test_init.py Outdated Show resolved Hide resolved
homeassistant/components/google_cloud/tts.py Outdated Show resolved Hide resolved
Copy link
Contributor

@arturpragacz arturpragacz left a comment

Choose a reason for hiding this comment

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

LGTM

homeassistant/components/google_cloud/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/google_cloud/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/google_cloud/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/google_cloud/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/google_cloud/tts.py Outdated Show resolved Hide resolved
tests/components/google_cloud/test_config_flow.py Outdated Show resolved Hide resolved
Comment on lines 53 to 102
async def test_user_flow_missing_file(hass: HomeAssistant) -> None:
"""Test user flow when uploaded file is missing."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}

with patch(
"homeassistant.components.google_cloud.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{UPLOADED_KEY_FILE: str(uuid4())},
)
await hass.async_block_till_done()

assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "invalid_file"}
assert len(mock_setup_entry.mock_calls) == 0


async def test_user_flow_invalid_file(
hass: HomeAssistant,
create_invalid_google_credentials_json: str,
mock_process_uploaded_file: MagicMock,
) -> None:
"""Test user flow when uploaded file is invalid."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}

uploaded_file = str(uuid4())
with patch(
"homeassistant.components.google_cloud.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{UPLOADED_KEY_FILE: uploaded_file},
)
await hass.async_block_till_done()

assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "invalid_file"}
mock_process_uploaded_file.assert_called_with(hass, uploaded_file)
assert len(mock_setup_entry.mock_calls) == 0
Copy link
Member

Choose a reason for hiding this comment

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

We should make sure the tests end in either an abort or create entry to test the flow is able to recover

Copy link
Member Author

Choose a reason for hiding this comment

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

On errors I don't abort but rather show the form with the error without moving to the next step:
image
Since this is the very first form and there is no state I don't think it's worth complicating the test setup and continuing the flow which will essentially retest test_user_flow_success

tests/components/google_cloud/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/google_cloud/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/google_cloud/test_init.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft September 2, 2024 09:05
@home-assistant
Copy link

home-assistant bot commented Sep 2, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@tronikos tronikos marked this pull request as ready for review September 2, 2024 10:51
@tronikos
Copy link
Member Author

tronikos commented Sep 2, 2024

Thanks for the review!

@tronikos tronikos merged commit d40e314 into home-assistant:dev Sep 2, 2024
35 checks passed
@tronikos tronikos deleted the google_cloud_config_flow branch September 2, 2024 11:30
@tronikos
Copy link
Member Author

tronikos commented Sep 2, 2024

If it helps, while the context of this review is still fresh in your mind, I also have #120854

@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 2024
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