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

Add Google Drive integration for backup #134576

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

tronikos
Copy link
Member

@tronikos tronikos commented Jan 3, 2025

Proposed change

Add Google Drive integration. Currently it only provides a backup agent that works with the Home Assistant backup solution introduced in Home Assistant 2025.1.
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:

@tronikos tronikos marked this pull request as ready for review January 4, 2025 11:25
Copy link
Contributor

@rokam rokam left a comment

Choose a reason for hiding this comment

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

Works as expected and LGTM. Missing test coverage should be a priority on follow-up PR.


def _convert_agent_backup_to_properties(backup: AgentBackup) -> dict[str, str]:
return {
k: v if k in _AGENT_BACKUP_SIMPLE_FIELDS else json.dumps(v)
Copy link
Member

Choose a reason for hiding this comment

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

This feels a little fragile, should we include a "version": "1" as a key/value so in the future when fields change in some way, we can handle that (ie json.loads below would fail if it's not valid JSON)

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to convert every field to JSON except backup_id to make it less fragile. backup_id needs to be unmodified so that we can efficiently query it without listing all backups.

@pantherale0
Copy link

LGTM - as this uses the folder ID, I'm assuming there could be a chance that someone might "accidentally" delete the folder? Does this impact integration startup / backup service? Could a backup upload "silently" fail for example? Very minor in the grand scheme of things, but I know Google's storage manager likes to recommend things to delete.

@tronikos
Copy link
Member Author

tronikos commented Jan 5, 2025

LGTM - as this uses the folder ID, I'm assuming there could be a chance that someone might "accidentally" delete the folder? Does this impact integration startup / backup service? Could a backup upload "silently" fail for example? Very minor in the grand scheme of things, but I know Google's storage manager likes to recommend things to delete.

Done. If the folder is deleted the setup fails with:
"Google Drive folder not found. Remove the Google Drive integration and re-add it for a new 'Home Assistant' folder to be created in Google Drive."

@rokam
Copy link
Contributor

rokam commented Jan 5, 2025

LGTM - as this uses the folder ID, I'm assuming there could be a chance that someone might "accidentally" delete the folder? Does this impact integration startup / backup service? Could a backup upload "silently" fail for example? Very minor in the grand scheme of things, but I know Google's storage manager likes to recommend things to delete.

Done. If the folder is deleted the setup fails with: "Google Drive folder not found. Remove the Google Drive integration and re-add it for a new 'Home Assistant' folder to be created in Google Drive."

Later this could be changed to use repair instead of reconfigure flow.

@tronikos
Copy link
Member Author

tronikos commented Jan 6, 2025

LGTM - as this uses the folder ID, I'm assuming there could be a chance that someone might "accidentally" delete the folder? Does this impact integration startup / backup service? Could a backup upload "silently" fail for example? Very minor in the grand scheme of things, but I know Google's storage manager likes to recommend things to delete.

Done. If the folder is deleted the setup fails with: "Google Drive folder not found. Remove the Google Drive integration and re-add it for a new 'Home Assistant' folder to be created in Google Drive."

Later this could be changed to use repair instead of reconfigure flow.

That's a good idea. Thanks! For now I changed the quality scale to repair-issues: todo

@hmmbob
Copy link
Contributor

hmmbob commented Jan 6, 2025

Lovely!

Would it make sense to name the folder Home Assistant Backups instead of just Home Assistant? I feel this better describes the purpose of the folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants