-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add Edit Sheet service to Google Sheets #79149
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a516474
Add options flow to Google Sheets
tkdrob 5ed30c5
Merge branch 'dev' of https://github.com/home-assistant/core into goo…
tkdrob 176e9fb
use backported str enum
tkdrob ebce9f5
lint
tkdrob baa4960
update options on setup
tkdrob c21ccdd
uno mas
tkdrob 7bae9fa
Merge branch 'dev' into google_sheets_options
tkdrob 23d3438
Merge branch 'dev' of https://github.com/home-assistant/core into goo…
tkdrob 6e58565
Merge branch 'google_sheets_options' of https://github.com/tkdrob/cor…
tkdrob 3701025
fix websocket_resolve_media
mib1185 69f665d
Merge branch 'mib1185/media_source/fix-websocket_resolve_media' of ht…
tkdrob fe9e1d6
uno mas
tkdrob 3720f53
Merge branch 'dev' into google_sheets_options
tkdrob 187c8be
ruff
tkdrob 7c5e1ec
Merge branch 'dev' into google_sheets_options
tkdrob dfb207c
Merge branch 'dev' of https://github.com/home-assistant/core into goo…
tkdrob e7c83f4
clarify access settings
tkdrob 8b5e2db
Merge branch 'dev' of https://github.com/home-assistant/core into goo…
tkdrob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,22 @@ | ||
| """Constants for Google Sheets integration.""" | ||
| from __future__ import annotations | ||
|
|
||
| from enum import Enum | ||
| from typing import Final | ||
|
|
||
| DOMAIN = "google_sheets" | ||
|
|
||
| CONF_SHEETS_ACCESS = "sheets_access" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please make this a |
||
| DATA_CONFIG_ENTRY: Final = "config_entry" | ||
| DEFAULT_NAME = "Google Sheets" | ||
| DEFAULT_ACCESS = "https://www.googleapis.com/auth/drive.file" | ||
|
|
||
|
|
||
| class FeatureAccess(Enum): | ||
|
tkdrob marked this conversation as resolved.
Outdated
|
||
| """Class to represent different access scopes.""" | ||
|
|
||
| read_write = "https://www.googleapis.com/auth/spreadsheets" | ||
| read_only = "https://www.googleapis.com/auth/spreadsheets.readonly" | ||
| file = "https://www.googleapis.com/auth/drive.file" | ||
|
|
||
|
|
||
| DEFAULT_ACCESS = [FeatureAccess.file.value, FeatureAccess.read_only.value] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Test configuration and mocks for the google sheets integration.""" | ||
|
|
||
| from collections.abc import Awaitable, Callable, Generator | ||
| import time | ||
|
|
||
| import pytest | ||
|
|
||
| from homeassistant.components.application_credentials import ( | ||
| ClientCredential, | ||
| async_import_client_credential, | ||
| ) | ||
| from homeassistant.components.google_sheets.const import DOMAIN | ||
| from homeassistant.config_entries import ConfigEntryState | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.setup import async_setup_component | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
| TEST_SHEET_ID = "google-sheet-id" | ||
|
|
||
| ComponentSetup = Callable[[], Awaitable[None]] | ||
|
|
||
|
|
||
| @pytest.fixture(name="scopes") | ||
| def mock_scopes() -> list[str]: | ||
| """Fixture to set the scopes present in the OAuth token.""" | ||
| return [ | ||
| "https://www.googleapis.com/auth/drive.file", | ||
| "https://www.googleapis.com/auth/spreadsheets.readonly", | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture(name="expires_at") | ||
| def mock_expires_at() -> int: | ||
| """Fixture to set the oauth token expiration time.""" | ||
| return time.time() + 3600 | ||
|
|
||
|
|
||
| @pytest.fixture(name="config_entry") | ||
| def mock_config_entry(expires_at: int, scopes: list[str]) -> MockConfigEntry: | ||
| """Fixture for MockConfigEntry.""" | ||
| return MockConfigEntry( | ||
| domain=DOMAIN, | ||
| unique_id=TEST_SHEET_ID, | ||
| data={ | ||
| "auth_implementation": DOMAIN, | ||
| "token": { | ||
| "access_token": "mock-access-token", | ||
| "refresh_token": "mock-refresh-token", | ||
| "expires_at": expires_at, | ||
| "scope": " ".join(scopes), | ||
| }, | ||
| }, | ||
| options={"sheets_access": "read_only"}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(name="setup_integration") | ||
| async def mock_setup_integration( | ||
| hass: HomeAssistant, config_entry: MockConfigEntry | ||
| ) -> Generator[ComponentSetup, None, None]: | ||
| """Fixture for setting up the component.""" | ||
| config_entry.add_to_hass(hass) | ||
|
|
||
| assert await async_setup_component(hass, "application_credentials", {}) | ||
| await async_import_client_credential( | ||
| hass, | ||
| DOMAIN, | ||
| ClientCredential("client-id", "client-secret"), | ||
| DOMAIN, | ||
| ) | ||
|
|
||
| async def func() -> None: | ||
| assert await async_setup_component(hass, DOMAIN, {}) | ||
| await hass.async_block_till_done() | ||
|
|
||
| yield func | ||
|
|
||
| # Verify clean unload | ||
| entries = hass.config_entries.async_entries(DOMAIN) | ||
| assert len(entries) == 1 | ||
| await hass.config_entries.async_unload(entries[0].entry_id) | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert not hass.data.get(DOMAIN) | ||
| assert entries[0].state is ConfigEntryState.NOT_LOADED |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you help me understand in more detail how the read and write scopes will be used? I get the general idea of read vs write scopes, but I don't quite get how these will be used compare to the file scope.
The way it appears right now is that I see is the user will create a single sheet (using the file scope) -- but it's also given a read-only scope for everything in the account. I don't see a way to access the other sheets or why giving broad read/write access can even be used.
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.
The read scope gives read access to all spreadsheets. The file scope ensures users still have write access to the document that the integration created. I plan on extending the append service to allow the user to add a document id so they can specify a different document other than the integration made one.
The plan is to add an edit service which makes more sense for any other documents that people have access to that they want to modify. It should be the same schema for both services.
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.
Yeah I understand the scope differences, just wanting to see how they connect to the feature to ensure they all make sense together.
Ok, I'd say let's do the scope changes with the features it will enable? I don't mind viewing the larger PR. I just want to make sure it all connects.