mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Fix August integration to handle unavailable OAuth implementation at startup (#154244)
This commit is contained in:
@@ -36,11 +36,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bo
|
|||||||
raise ConfigEntryAuthFailed("Migration to OAuth required")
|
raise ConfigEntryAuthFailed("Migration to OAuth required")
|
||||||
|
|
||||||
session = async_create_august_clientsession(hass)
|
session = async_create_august_clientsession(hass)
|
||||||
implementation = (
|
try:
|
||||||
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
implementation = (
|
||||||
hass, entry
|
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)
|
oauth_session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
|
||||||
august_gateway = AugustGateway(Path(hass.config.config_dir), session, oauth_session)
|
august_gateway = AugustGateway(Path(hass.config.config_dir), session, oauth_session)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""The tests for the august platform."""
|
"""The tests for the august platform."""
|
||||||
|
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from aiohttp import ClientResponseError
|
from aiohttp import ClientResponseError
|
||||||
import pytest
|
import pytest
|
||||||
@@ -33,6 +33,8 @@ from .mocks import (
|
|||||||
_mock_inoperative_august_lock_detail,
|
_mock_inoperative_august_lock_detail,
|
||||||
_mock_lock_with_offline_key,
|
_mock_lock_with_offline_key,
|
||||||
_mock_operative_august_lock_detail,
|
_mock_operative_august_lock_detail,
|
||||||
|
mock_august_config_entry,
|
||||||
|
mock_client_credentials,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
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 len(flows) == 1
|
||||||
assert flows[0]["step_id"] == "pick_implementation"
|
assert flows[0]["step_id"] == "pick_implementation"
|
||||||
assert flows[0]["context"]["source"] == "reauth"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user