mirror of
https://github.com/home-assistant/core.git
synced 2026-05-03 19:41:15 +02:00
Raise on ImplementationUnavailableError in Xbox integration (#156168)
This commit is contained in:
@@ -22,7 +22,12 @@ from pythonxbox.common.signed_session import SignedSession
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_entry_oauth2_flow, device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||
ImplementationUnavailableError,
|
||||
OAuth2Session,
|
||||
async_get_config_entry_implementation,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util.ssl import get_default_context
|
||||
|
||||
@@ -77,20 +82,16 @@ class XboxUpdateCoordinator(DataUpdateCoordinator[XboxData]):
|
||||
async def _async_setup(self) -> None:
|
||||
"""Set up coordinator."""
|
||||
try:
|
||||
implementation = (
|
||||
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
||||
self.hass, self.config_entry
|
||||
)
|
||||
implementation = await async_get_config_entry_implementation(
|
||||
self.hass, self.config_entry
|
||||
)
|
||||
except ValueError as e:
|
||||
except ImplementationUnavailableError as e:
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="request_exception",
|
||||
translation_key="oauth2_implementation_unavailable",
|
||||
) from e
|
||||
|
||||
session = config_entry_oauth2_flow.OAuth2Session(
|
||||
self.hass, self.config_entry, implementation
|
||||
)
|
||||
session = OAuth2Session(self.hass, self.config_entry, implementation)
|
||||
signed_session = SignedSession(ssl_context=get_default_context())
|
||||
auth = api.AsyncConfigEntryAuth(signed_session, session)
|
||||
self.client = XboxLiveClient(auth)
|
||||
|
||||
@@ -98,6 +98,9 @@
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"oauth2_implementation_unavailable": {
|
||||
"message": "OAuth2 implementation temporarily unavailable, will retry"
|
||||
},
|
||||
"request_exception": {
|
||||
"message": "Failed to connect to Xbox Network"
|
||||
},
|
||||
|
||||
@@ -40,7 +40,7 @@ async def setup_credentials(hass: HomeAssistant) -> None:
|
||||
def mock_oauth2_implementation() -> Generator[AsyncMock]:
|
||||
"""Mock config entry oauth2 implementation."""
|
||||
with patch(
|
||||
"homeassistant.components.xbox.coordinator.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||
"homeassistant.components.xbox.coordinator.async_get_config_entry_implementation",
|
||||
return_value=AsyncMock(),
|
||||
) as mock_client:
|
||||
client = mock_client.return_value
|
||||
|
||||
@@ -7,6 +7,9 @@ import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||
ImplementationUnavailableError,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -56,8 +59,8 @@ async def test_config_implementation_not_available(
|
||||
"""Test implementation not available."""
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.xbox.coordinator.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||
side_effect=ValueError("Implementation not available"),
|
||||
"homeassistant.components.xbox.coordinator.async_get_config_entry_implementation",
|
||||
side_effect=ImplementationUnavailableError,
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user