Skip to content

Commit f82ec81

Browse files
bdracofrenck
authored andcommitted
Fix Yale integration to handle unavailable OAuth implementation at startup (home-assistant#154245)
1 parent 03b0842 commit f82ec81

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

homeassistant/components/yale/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@
2727

2828

2929
async def async_setup_entry(hass: HomeAssistant, entry: YaleConfigEntry) -> bool:
30-
"""Set up yale from a config entry."""
30+
"""Set up Yale from a config entry."""
3131
session = async_create_yale_clientsession(hass)
32-
implementation = (
33-
await config_entry_oauth2_flow.async_get_config_entry_implementation(
34-
hass, entry
32+
try:
33+
implementation = (
34+
await config_entry_oauth2_flow.async_get_config_entry_implementation(
35+
hass, entry
36+
)
3537
)
36-
)
38+
except ValueError as err:
39+
raise ConfigEntryNotReady("OAuth implementation not available") from err
3740
oauth_session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
3841
yale_gateway = YaleGateway(Path(hass.config.config_dir), session, oauth_session)
3942
try:

tests/components/yale/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 yale platform."""
22

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

55
from aiohttp import ClientResponseError
66
import pytest
@@ -28,6 +28,8 @@
2828
_mock_inoperative_yale_lock_detail,
2929
_mock_lock_with_offline_key,
3030
_mock_operative_yale_lock_detail,
31+
mock_client_credentials,
32+
mock_yale_config_entry,
3133
)
3234

3335
from tests.typing import WebSocketGenerator
@@ -234,3 +236,18 @@ async def test_device_remove_devices(
234236
)
235237
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
236238
assert response["success"]
239+
240+
241+
async def test_oauth_implementation_not_available(hass: HomeAssistant) -> None:
242+
"""Test that unavailable OAuth implementation raises ConfigEntryNotReady."""
243+
await mock_client_credentials(hass)
244+
entry = await mock_yale_config_entry(hass)
245+
246+
with patch(
247+
"homeassistant.components.yale.config_entry_oauth2_flow.async_get_config_entry_implementation",
248+
side_effect=ValueError("Implementation not available"),
249+
):
250+
await hass.config_entries.async_setup(entry.entry_id)
251+
await hass.async_block_till_done()
252+
253+
assert entry.state is ConfigEntryState.SETUP_RETRY

0 commit comments

Comments
 (0)