Fix Yale integration to handle unavailable OAuth implementation at startup (#154245)

This commit is contained in:
J. Nick Koston
2025-10-17 20:31:05 +00:00
committed by Franck Nijhof
parent 03b0842a01
commit f82ec81062
2 changed files with 26 additions and 6 deletions
+8 -5
View File
@@ -27,13 +27,16 @@ type YaleConfigEntry = ConfigEntry[YaleData]
async def async_setup_entry(hass: HomeAssistant, entry: YaleConfigEntry) -> bool:
"""Set up yale from a config entry."""
"""Set up Yale from a config entry."""
session = async_create_yale_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)
yale_gateway = YaleGateway(Path(hass.config.config_dir), session, oauth_session)
try:
+18 -1
View File
@@ -1,6 +1,6 @@
"""The tests for the yale platform."""
from unittest.mock import Mock
from unittest.mock import Mock, patch
from aiohttp import ClientResponseError
import pytest
@@ -28,6 +28,8 @@ from .mocks import (
_mock_inoperative_yale_lock_detail,
_mock_lock_with_offline_key,
_mock_operative_yale_lock_detail,
mock_client_credentials,
mock_yale_config_entry,
)
from tests.typing import WebSocketGenerator
@@ -234,3 +236,18 @@ async def test_device_remove_devices(
)
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
assert response["success"]
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_yale_config_entry(hass)
with patch(
"homeassistant.components.yale.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