Create Xbox signed session in executor (#136927)

This commit is contained in:
Joost Lekkerkerker 2025-01-30 16:16:22 +01:00 committed by GitHub
parent bab616fa61
commit 232e99b62e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import logging
from xbox.webapi.api.client import XboxLiveClient
from xbox.webapi.api.provider.smartglass.models import SmartglassConsoleList
from xbox.webapi.common.signed_session import SignedSession
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
@ -36,7 +37,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
)
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
auth = api.AsyncConfigEntryAuth(session)
signed_session = await hass.async_add_executor_job(SignedSession)
auth = api.AsyncConfigEntryAuth(signed_session, session)
client = XboxLiveClient(auth)
consoles: SmartglassConsoleList = await client.smartglass.get_console_list()

View File

@ -11,10 +11,12 @@ from homeassistant.util.dt import utc_from_timestamp
class AsyncConfigEntryAuth(AuthenticationManager):
"""Provide xbox authentication tied to an OAuth2 based config entry."""
def __init__(self, oauth_session: OAuth2Session) -> None:
def __init__(
self, signed_session: SignedSession, oauth_session: OAuth2Session
) -> None:
"""Initialize xbox auth."""
# Leaving out client credentials as they are handled by Home Assistant
super().__init__(SignedSession(), "", "", "")
super().__init__(signed_session, "", "", "")
self._oauth_session = oauth_session
self.oauth = self._get_oauth_token()