1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 16:36:08 +01:00

Handle Oauth2 ImplementationUnavailableError in google_sheets (#166651)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Will Moss
2026-03-28 08:53:47 -07:00
committed by GitHub
parent 3757289c73
commit a2e60f84da
3 changed files with 33 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ from homeassistant.exceptions import (
)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.config_entry_oauth2_flow import (
ImplementationUnavailableError,
OAuth2Session,
async_get_config_entry_implementation,
)
@@ -40,7 +41,13 @@ async def async_setup_entry(
hass: HomeAssistant, entry: GoogleSheetsConfigEntry
) -> bool:
"""Set up Google Sheets from a config entry."""
implementation = await async_get_config_entry_implementation(hass, entry)
try:
implementation = await async_get_config_entry_implementation(hass, entry)
except ImplementationUnavailableError as err:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="oauth2_implementation_unavailable",
) from err
session = OAuth2Session(hass, entry, implementation)
try:
await session.async_ensure_token_valid()

View File

@@ -42,6 +42,11 @@
}
}
},
"exceptions": {
"oauth2_implementation_unavailable": {
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
}
},
"services": {
"append_sheet": {
"description": "Appends data to a worksheet in Google Sheets.",

View File

@@ -35,6 +35,9 @@ from homeassistant.exceptions import (
OAuth2TokenRequestTransientError,
ServiceValidationError,
)
from homeassistant.helpers.config_entry_oauth2_flow import (
ImplementationUnavailableError,
)
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
@@ -558,3 +561,20 @@ async def test_get_sheet_invalid_worksheet(
blocking=True,
return_response=True,
)
async def test_oauth_implementation_not_available(
hass: HomeAssistant,
config_entry: MockConfigEntry,
) -> None:
"""Test that unavailable OAuth implementation raises ConfigEntryNotReady."""
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.google_sheets.async_get_config_entry_implementation",
side_effect=ImplementationUnavailableError,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.SETUP_RETRY