From ddfef18183e92db08fdd6c72a896324cb87b9d50 Mon Sep 17 00:00:00 2001 From: Will Moss Date: Thu, 26 Mar 2026 20:45:04 -0700 Subject: [PATCH] Use error introduced in #154579 in google_photos integration (#166656) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- .../components/google_photos/__init__.py | 15 +++++++++++---- .../components/google_photos/strings.json | 3 +++ tests/components/google_photos/test_init.py | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/google_photos/__init__.py b/homeassistant/components/google_photos/__init__.py index 08bdce9b359..115bd57f67c 100644 --- a/homeassistant/components/google_photos/__init__.py +++ b/homeassistant/components/google_photos/__init__.py @@ -33,11 +33,18 @@ async def async_setup_entry( hass: HomeAssistant, entry: GooglePhotosConfigEntry ) -> bool: """Set up Google Photos from a config entry.""" - implementation = ( - await config_entry_oauth2_flow.async_get_config_entry_implementation( - hass, entry + try: + implementation = ( + await config_entry_oauth2_flow.async_get_config_entry_implementation( + hass, entry + ) ) - ) + except config_entry_oauth2_flow.ImplementationUnavailableError as err: + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="oauth2_implementation_unavailable", + ) from err + web_session = async_get_clientsession(hass) oauth_session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation) auth = api.AsyncConfigEntryAuth(web_session, oauth_session) diff --git a/homeassistant/components/google_photos/strings.json b/homeassistant/components/google_photos/strings.json index 63984ecc7c1..bb041da4a63 100644 --- a/homeassistant/components/google_photos/strings.json +++ b/homeassistant/components/google_photos/strings.json @@ -68,6 +68,9 @@ "no_access_to_path": { "message": "Cannot read {filename}, no access to path; `allowlist_external_dirs` may need to be adjusted in `configuration.yaml`" }, + "oauth2_implementation_unavailable": { + "message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]" + }, "upload_error": { "message": "Failed to upload content: {message}" } diff --git a/tests/components/google_photos/test_init.py b/tests/components/google_photos/test_init.py index 80b051d092d..b6fcc7d5c10 100644 --- a/tests/components/google_photos/test_init.py +++ b/tests/components/google_photos/test_init.py @@ -2,6 +2,7 @@ import http import time +from unittest.mock import patch from aiohttp import ClientError from google_photos_library_api.exceptions import GooglePhotosApiError @@ -10,6 +11,7 @@ import pytest from homeassistant.components.google_photos.const import OAUTH2_TOKEN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant +from homeassistant.helpers import config_entry_oauth2_flow from tests.common import MockConfigEntry from tests.test_util.aiohttp import AiohttpClientMocker @@ -118,3 +120,19 @@ async def test_coordinator_init_failure( ) -> None: """Test init failure to load albums.""" assert config_entry.state is ConfigEntryState.SETUP_RETRY + + +async def test_setup_entry_implementation_unavailable( + hass: HomeAssistant, + config_entry: MockConfigEntry, +) -> None: + """Test setup entry when implementation is unavailable.""" + with patch( + "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", + side_effect=config_entry_oauth2_flow.ImplementationUnavailableError, + ): + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert config_entry.state is ConfigEntryState.SETUP_RETRY