From f82ec81062bd093533fb61954cce4174326ae709 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 12 Oct 2025 09:16:02 -1000 Subject: [PATCH] Fix Yale integration to handle unavailable OAuth implementation at startup (#154245) --- homeassistant/components/yale/__init__.py | 13 ++++++++----- tests/components/yale/test_init.py | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/yale/__init__.py b/homeassistant/components/yale/__init__.py index 1cbd9c87b572..f3db044a7852 100644 --- a/homeassistant/components/yale/__init__.py +++ b/homeassistant/components/yale/__init__.py @@ -27,13 +27,16 @@ type YaleConfigEntry = ConfigEntry[YaleData] async def async_setup_entry(hass: HomeAssistant, entry: YaleConfigEntry) -> bool: - """Set up yale from a config entry.""" + """Set up Yale from a config entry.""" session = async_create_yale_clientsession(hass) - 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 ValueError as err: + raise ConfigEntryNotReady("OAuth implementation not available") from err oauth_session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation) yale_gateway = YaleGateway(Path(hass.config.config_dir), session, oauth_session) try: diff --git a/tests/components/yale/test_init.py b/tests/components/yale/test_init.py index ec43c07f1eef..1276907133a5 100644 --- a/tests/components/yale/test_init.py +++ b/tests/components/yale/test_init.py @@ -1,6 +1,6 @@ """The tests for the yale platform.""" -from unittest.mock import Mock +from unittest.mock import Mock, patch from aiohttp import ClientResponseError import pytest @@ -28,6 +28,8 @@ from .mocks import ( _mock_inoperative_yale_lock_detail, _mock_lock_with_offline_key, _mock_operative_yale_lock_detail, + mock_client_credentials, + mock_yale_config_entry, ) from tests.typing import WebSocketGenerator @@ -234,3 +236,18 @@ async def test_device_remove_devices( ) response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) assert response["success"] + + +async def test_oauth_implementation_not_available(hass: HomeAssistant) -> None: + """Test that unavailable OAuth implementation raises ConfigEntryNotReady.""" + await mock_client_credentials(hass) + entry = await mock_yale_config_entry(hass) + + with patch( + "homeassistant.components.yale.config_entry_oauth2_flow.async_get_config_entry_implementation", + side_effect=ValueError("Implementation not available"), + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert entry.state is ConfigEntryState.SETUP_RETRY