Raise on ImplementationUnavailableError in Xbox integration (#156168)

This commit is contained in:
Manu
2025-11-09 08:56:16 +01:00
committed by GitHub
parent 9002116572
commit 4a85837f2e
4 changed files with 20 additions and 13 deletions
+11 -10
View File
@@ -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"
},
+1 -1
View File
@@ -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
+5 -2
View File
@@ -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)