Skip to content

Commit 03b0842

Browse files
bdracofrenck
authored andcommitted
Fix August integration to handle unavailable OAuth implementation at startup (home-assistant#154244)
1 parent 13e5cb5 commit 03b0842

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

homeassistant/components/august/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bo
3636
raise ConfigEntryAuthFailed("Migration to OAuth required")
3737

3838
session = async_create_august_clientsession(hass)
39-
implementation = (
40-
await config_entry_oauth2_flow.async_get_config_entry_implementation(
41-
hass, entry
39+
try:
40+
implementation = (
41+
await config_entry_oauth2_flow.async_get_config_entry_implementation(
42+
hass, entry
43+
)
4244
)
43-
)
45+
except ValueError as err:
46+
raise ConfigEntryNotReady("OAuth implementation not available") from err
4447
oauth_session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
4548
august_gateway = AugustGateway(Path(hass.config.config_dir), session, oauth_session)
4649
try:

tests/components/august/test_init.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""The tests for the august platform."""
22

3-
from unittest.mock import Mock
3+
from unittest.mock import Mock, patch
44

55
from aiohttp import ClientResponseError
66
import pytest
@@ -33,6 +33,8 @@
3333
_mock_inoperative_august_lock_detail,
3434
_mock_lock_with_offline_key,
3535
_mock_operative_august_lock_detail,
36+
mock_august_config_entry,
37+
mock_client_credentials,
3638
)
3739

3840
from tests.common import MockConfigEntry
@@ -284,3 +286,18 @@ async def test_oauth_migration_on_legacy_entry(hass: HomeAssistant) -> None:
284286
assert len(flows) == 1
285287
assert flows[0]["step_id"] == "pick_implementation"
286288
assert flows[0]["context"]["source"] == "reauth"
289+
290+
291+
async def test_oauth_implementation_not_available(hass: HomeAssistant) -> None:
292+
"""Test that unavailable OAuth implementation raises ConfigEntryNotReady."""
293+
await mock_client_credentials(hass)
294+
entry = await mock_august_config_entry(hass)
295+
296+
with patch(
297+
"homeassistant.components.august.config_entry_oauth2_flow.async_get_config_entry_implementation",
298+
side_effect=ValueError("Implementation not available"),
299+
):
300+
await hass.config_entries.async_setup(entry.entry_id)
301+
await hass.async_block_till_done()
302+
303+
assert entry.state is ConfigEntryState.SETUP_RETRY

0 commit comments

Comments
 (0)