Fix August integration to handle unavailable OAuth implementation at startup (#154244)

This commit is contained in:
J. Nick Koston
2025-10-12 09:16:22 -10:00
committed by GitHub
parent 7948b35265
commit c9d67d596b
2 changed files with 25 additions and 5 deletions

View File

@@ -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:

View File

@@ -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