1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Use error introduced in #154579 in yolink integration (#156092)

This commit is contained in:
Will Moss
2025-11-09 08:44:44 -08:00
committed by GitHub
parent 5b2d43dffb
commit 7aced2522a
4 changed files with 41 additions and 9 deletions
+13 -7
View File
@@ -19,10 +19,14 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import (
aiohttp_client,
config_entry_oauth2_flow,
config_validation as cv,
device_registry as dr,
)
from homeassistant.helpers.config_entry_oauth2_flow import (
ImplementationUnavailableError,
OAuth2Session,
async_get_config_entry_implementation,
)
from homeassistant.helpers.typing import ConfigType
from . import api
@@ -120,13 +124,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up yolink from a config entry."""
hass.data.setdefault(DOMAIN, {})
implementation = (
await config_entry_oauth2_flow.async_get_config_entry_implementation(
hass, entry
)
)
try:
implementation = await async_get_config_entry_implementation(hass, entry)
except ImplementationUnavailableError as err:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="oauth2_implementation_unavailable",
) from err
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
session = OAuth2Session(hass, entry, implementation)
auth_mgr = api.ConfigEntryAuth(
hass, aiohttp_client.async_get_clientsession(hass), session
@@ -133,6 +133,9 @@
"invalid_config_entry": {
"message": "Config entry not found or not loaded!"
},
"oauth2_implementation_unavailable": {
"message": "OAuth2 implementation temporarily unavailable, will retry"
},
"valve_inoperable_currently": {
"message": "The Valve cannot be operated currently."
}
+1 -2
View File
@@ -130,8 +130,7 @@ async def test_abort_if_authorization_timeout(hass: HomeAssistant) -> None:
application_credentials.ClientCredential(CLIENT_ID, CLIENT_SECRET),
)
with patch(
"homeassistant.components.yolink.config_entry_oauth2_flow."
"LocalOAuth2Implementation.async_generate_authorize_url",
"homeassistant.helpers.config_entry_oauth2_flow.LocalOAuth2Implementation.async_generate_authorize_url",
side_effect=TimeoutError,
):
result = await hass.config_entries.flow.async_init(
+24
View File
@@ -1,10 +1,17 @@
"""Tests for the yolink integration."""
from unittest.mock import patch
import pytest
from homeassistant.components.yolink import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.config_entry_oauth2_flow import (
ImplementationUnavailableError,
)
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
@@ -36,3 +43,20 @@ async def test_device_remove_devices(
device_registry, mock_config_entry.entry_id
)
assert len(device_entries) == 0
@pytest.mark.usefixtures("setup_credentials", "mock_auth_manager", "mock_yolink_home")
async def test_oauth_implementation_not_available(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None:
"""Test that an unavailable OAuth implementation raises ConfigEntryNotReady."""
assert await async_setup_component(hass, "cloud", {})
with patch(
"homeassistant.components.yolink.async_get_config_entry_implementation",
side_effect=ImplementationUnavailableError,
):
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY