From 0e1663f2596f529d35523dc7f8dedecdc6e6a5a9 Mon Sep 17 00:00:00 2001 From: Will Moss Date: Sat, 28 Mar 2026 08:51:09 -0700 Subject: [PATCH] Handle Oauth2 ImplementationUnavailableError in gentex_homelink (#166646) Co-authored-by: Claude Sonnet 4.6 --- .../components/gentex_homelink/__init__.py | 16 +++++++++----- .../components/gentex_homelink/strings.json | 5 +++++ tests/components/gentex_homelink/test_init.py | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/gentex_homelink/__init__.py b/homeassistant/components/gentex_homelink/__init__.py index cdd37a7920f..68cf0dfac52 100644 --- a/homeassistant/components/gentex_homelink/__init__.py +++ b/homeassistant/components/gentex_homelink/__init__.py @@ -7,7 +7,7 @@ from homelink.mqtt_provider import MQTTProvider from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryAuthFailed +from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow from . import oauth2 @@ -29,11 +29,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: HomeLinkConfigEntry) -> hass, DOMAIN, auth_implementation ) - 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 session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation) authenticated_session = oauth2.AsyncConfigEntryAuth( diff --git a/homeassistant/components/gentex_homelink/strings.json b/homeassistant/components/gentex_homelink/strings.json index 0a5fec312da..111fca492da 100644 --- a/homeassistant/components/gentex_homelink/strings.json +++ b/homeassistant/components/gentex_homelink/strings.json @@ -49,5 +49,10 @@ } } } + }, + "exceptions": { + "oauth2_implementation_unavailable": { + "message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]" + } } } diff --git a/tests/components/gentex_homelink/test_init.py b/tests/components/gentex_homelink/test_init.py index 607430cdab0..d4003c3d0a1 100644 --- a/tests/components/gentex_homelink/test_init.py +++ b/tests/components/gentex_homelink/test_init.py @@ -8,6 +8,9 @@ from syrupy.assertion import SnapshotAssertion from homeassistant.components.gentex_homelink.const import DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant +from homeassistant.helpers.config_entry_oauth2_flow import ( + ImplementationUnavailableError, +) import homeassistant.helpers.device_registry as dr from . import setup_integration, update_callback @@ -72,3 +75,21 @@ async def test_load_unload_entry( await hass.async_block_till_done() assert mock_config_entry.state is ConfigEntryState.NOT_LOADED + + +@pytest.mark.usefixtures("aioclient_mock_fixture") +async def test_oauth_implementation_not_available( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, +) -> None: + """Test that unavailable OAuth implementation raises ConfigEntryNotReady.""" + mock_config_entry.add_to_hass(hass) + + with patch( + "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", + side_effect=ImplementationUnavailableError, + ): + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY