diff --git a/homeassistant/components/august/__init__.py b/homeassistant/components/august/__init__.py index 38a3ade2d90..3267fbfb0bc 100644 --- a/homeassistant/components/august/__init__.py +++ b/homeassistant/components/august/__init__.py @@ -36,11 +36,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bo raise ConfigEntryAuthFailed("Migration to OAuth required") session = async_create_august_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) august_gateway = AugustGateway(Path(hass.config.config_dir), session, oauth_session) try: diff --git a/tests/components/august/test_init.py b/tests/components/august/test_init.py index 33517e9e130..ae30c8ad977 100644 --- a/tests/components/august/test_init.py +++ b/tests/components/august/test_init.py @@ -1,6 +1,6 @@ """The tests for the august platform.""" -from unittest.mock import Mock +from unittest.mock import Mock, patch from aiohttp import ClientResponseError import pytest @@ -33,6 +33,8 @@ from .mocks import ( _mock_inoperative_august_lock_detail, _mock_lock_with_offline_key, _mock_operative_august_lock_detail, + mock_august_config_entry, + mock_client_credentials, ) from tests.common import MockConfigEntry @@ -284,3 +286,18 @@ async def test_oauth_migration_on_legacy_entry(hass: HomeAssistant) -> None: assert len(flows) == 1 assert flows[0]["step_id"] == "pick_implementation" assert flows[0]["context"]["source"] == "reauth" + + +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_august_config_entry(hass) + + with patch( + "homeassistant.components.august.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