Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SignedSession in Xbox #133938

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions homeassistant/components/xbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import (
aiohttp_client,
config_entry_oauth2_flow,
config_validation as cv,
)
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv

from . import api
from .const import DOMAIN
Expand All @@ -40,9 +36,7 @@
)
)
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
auth = api.AsyncConfigEntryAuth(
aiohttp_client.async_get_clientsession(hass), session
)
auth = api.AsyncConfigEntryAuth(session)

Check warning on line 39 in homeassistant/components/xbox/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/xbox/__init__.py#L39

Added line #L39 was not covered by tests

client = XboxLiveClient(auth)
consoles: SmartglassConsoleList = await client.smartglass.get_console_list()
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/xbox/api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
"""API for xbox bound to Home Assistant OAuth."""

from aiohttp import ClientSession
from xbox.webapi.authentication.manager import AuthenticationManager
from xbox.webapi.authentication.models import OAuth2TokenResponse
from xbox.webapi.common.signed_session import SignedSession

from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session
from homeassistant.util.dt import utc_from_timestamp


class AsyncConfigEntryAuth(AuthenticationManager):
"""Provide xbox authentication tied to an OAuth2 based config entry."""

def __init__(
self,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
def __init__(self, oauth_session: OAuth2Session) -> None:
"""Initialize xbox auth."""
# Leaving out client credentials as they are handled by Home Assistant
super().__init__(websession, "", "", "")
super().__init__(SignedSession(), "", "", "")

Check warning on line 17 in homeassistant/components/xbox/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/xbox/api.py#L17

Added line #L17 was not covered by tests
self._oauth_session = oauth_session
self.oauth = self._get_oauth_token()

Expand Down