Skip to content

Commit d651aae

Browse files
committed
Migrate library xbox-webapi to python-xbox
1 parent f2f769b commit d651aae

20 files changed

+199
-80
lines changed

homeassistant/components/xbox/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""API for xbox bound to Home Assistant OAuth."""
22

3-
from xbox.webapi.authentication.manager import AuthenticationManager
4-
from xbox.webapi.authentication.models import OAuth2TokenResponse
5-
from xbox.webapi.common.signed_session import SignedSession
3+
from pythonxbox.authentication.manager import AuthenticationManager
4+
from pythonxbox.authentication.models import OAuth2TokenResponse
5+
from pythonxbox.common.signed_session import SignedSession
66

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

homeassistant/components/xbox/binary_sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from enum import StrEnum
88
from typing import Any
99

10-
from xbox.webapi.api.provider.people.models import Person
11-
from xbox.webapi.api.provider.titlehub.models import Title
10+
from pythonxbox.api.provider.people.models import Person
11+
from pythonxbox.api.provider.titlehub.models import Title
1212

1313
from homeassistant.components.binary_sensor import (
1414
DOMAIN as BINARY_SENSOR_DOMAIN,

homeassistant/components/xbox/browse_media.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
from typing import NamedTuple
66

7-
from xbox.webapi.api.client import XboxLiveClient
8-
from xbox.webapi.api.provider.catalog.const import HOME_APP_IDS, SYSTEM_PFN_ID_MAP
9-
from xbox.webapi.api.provider.catalog.models import (
7+
from pythonxbox.api.client import XboxLiveClient
8+
from pythonxbox.api.provider.catalog.const import HOME_APP_IDS, SYSTEM_PFN_ID_MAP
9+
from pythonxbox.api.provider.catalog.models import (
1010
AlternateIdType,
1111
CatalogResponse,
1212
FieldsTemplate,
1313
Image,
1414
)
15-
from xbox.webapi.api.provider.smartglass.models import (
15+
from pythonxbox.api.provider.smartglass.models import (
1616
InstalledPackage,
1717
InstalledPackagesList,
1818
)

homeassistant/components/xbox/config_flow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import logging
44
from typing import Any
55

6-
from xbox.webapi.api.client import XboxLiveClient
7-
from xbox.webapi.authentication.manager import AuthenticationManager
8-
from xbox.webapi.authentication.models import OAuth2TokenResponse
9-
from xbox.webapi.common.signed_session import SignedSession
6+
from pythonxbox.api.client import XboxLiveClient
7+
from pythonxbox.authentication.manager import AuthenticationManager
8+
from pythonxbox.authentication.models import OAuth2TokenResponse
9+
from pythonxbox.common.signed_session import SignedSession
1010

1111
from homeassistant.config_entries import ConfigFlowResult
1212
from homeassistant.helpers import config_entry_oauth2_flow
@@ -54,7 +54,7 @@ async def async_oauth_create_entry(self, data: dict) -> ConfigFlowResult:
5454

5555
client = XboxLiveClient(auth)
5656

57-
me = await client.people.get_friends_own_batch([client.xuid])
57+
me = await client.people.get_friends_by_xuid(client.xuid)
5858

5959
await self.async_set_unique_id(client.xuid)
6060
return self.async_create_entry(title=me.people[0].gamertag, data=data)

homeassistant/components/xbox/coordinator.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
import logging
99

1010
from httpx import HTTPStatusError, RequestError, TimeoutException
11-
from xbox.webapi.api.client import XboxLiveClient
12-
from xbox.webapi.api.provider.catalog.const import SYSTEM_PFN_ID_MAP
13-
from xbox.webapi.api.provider.catalog.models import AlternateIdType, Product
14-
from xbox.webapi.api.provider.people.models import Person
15-
from xbox.webapi.api.provider.smartglass.models import (
11+
from pythonxbox.api.client import XboxLiveClient
12+
from pythonxbox.api.provider.catalog.const import SYSTEM_PFN_ID_MAP
13+
from pythonxbox.api.provider.catalog.models import AlternateIdType, Product
14+
from pythonxbox.api.provider.people.models import Person
15+
from pythonxbox.api.provider.smartglass.models import (
1616
SmartglassConsoleList,
1717
SmartglassConsoleStatus,
1818
)
19-
from xbox.webapi.api.provider.titlehub.models import Title
20-
from xbox.webapi.common.signed_session import SignedSession
19+
from pythonxbox.api.provider.titlehub.models import Title
20+
from pythonxbox.common.signed_session import SignedSession
2121

2222
from homeassistant.config_entries import ConfigEntry
2323
from homeassistant.core import HomeAssistant
2424
from homeassistant.exceptions import ConfigEntryNotReady
2525
from homeassistant.helpers import config_entry_oauth2_flow, device_registry as dr
2626
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
27+
from homeassistant.util.ssl import get_default_context
2728

2829
from . import api
2930
from .const import DOMAIN
@@ -90,7 +91,7 @@ async def _async_setup(self) -> None:
9091
session = config_entry_oauth2_flow.OAuth2Session(
9192
self.hass, self.config_entry, implementation
9293
)
93-
signed_session = await self.hass.async_add_executor_job(SignedSession)
94+
signed_session = SignedSession(ssl_context=get_default_context())
9495
auth = api.AsyncConfigEntryAuth(signed_session, session)
9596
self.client = XboxLiveClient(auth)
9697

@@ -183,7 +184,7 @@ async def _async_update_data(self) -> XboxData:
183184

184185
# Update user presence
185186
try:
186-
batch = await self.client.people.get_friends_own_batch([self.client.xuid])
187+
batch = await self.client.people.get_friends_by_xuid(self.client.xuid)
187188
friends = await self.client.people.get_friends_own()
188189
except TimeoutException as e:
189190
raise UpdateFailed(

homeassistant/components/xbox/entity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from dataclasses import dataclass
77
from typing import Any
88

9-
from xbox.webapi.api.provider.people.models import Person
10-
from xbox.webapi.api.provider.smartglass.models import ConsoleType, SmartglassConsole
11-
from xbox.webapi.api.provider.titlehub.models import Title
9+
from pythonxbox.api.provider.people.models import Person
10+
from pythonxbox.api.provider.smartglass.models import ConsoleType, SmartglassConsole
11+
from pythonxbox.api.provider.titlehub.models import Title
1212
from yarl import URL
1313

1414
from homeassistant.components.automation import automations_with_entity

homeassistant/components/xbox/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from dataclasses import dataclass
77
from enum import StrEnum
88

9-
from xbox.webapi.api.provider.people.models import Person
10-
from xbox.webapi.api.provider.titlehub.models import Title
9+
from pythonxbox.api.provider.people.models import Person
10+
from pythonxbox.api.provider.titlehub.models import Title
1111

1212
from homeassistant.components.image import ImageEntity, ImageEntityDescription
1313
from homeassistant.core import HomeAssistant, callback

homeassistant/components/xbox/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"documentation": "https://www.home-assistant.io/integrations/xbox",
1313
"iot_class": "cloud_polling",
14-
"requirements": ["xbox-webapi==2.1.0"],
14+
"requirements": ["python-xbox==0.1.0"],
1515
"ssdp": [
1616
{
1717
"manufacturer": "Microsoft Corporation",

homeassistant/components/xbox/media_player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from typing import Any
66

7-
from xbox.webapi.api.provider.catalog.models import Image
8-
from xbox.webapi.api.provider.smartglass.models import (
7+
from pythonxbox.api.provider.catalog.models import Image
8+
from pythonxbox.api.provider.smartglass.models import (
99
PlaybackState,
1010
PowerState,
1111
VolumeDirection,

homeassistant/components/xbox/media_source.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from dataclasses import dataclass
77

88
from pydantic import ValidationError
9-
from xbox.webapi.api.client import XboxLiveClient
10-
from xbox.webapi.api.provider.catalog.models import FieldsTemplate, Image
11-
from xbox.webapi.api.provider.gameclips.models import GameclipsResponse
12-
from xbox.webapi.api.provider.screenshots.models import ScreenshotResponse
13-
from xbox.webapi.api.provider.smartglass.models import InstalledPackage
9+
from pythonxbox.api.client import XboxLiveClient
10+
from pythonxbox.api.provider.catalog.models import FieldsTemplate, Image
11+
from pythonxbox.api.provider.gameclips.models import GameclipsResponse
12+
from pythonxbox.api.provider.screenshots.models import ScreenshotResponse
13+
from pythonxbox.api.provider.smartglass.models import InstalledPackage
1414

1515
from homeassistant.components.media_player import MediaClass
1616
from homeassistant.components.media_source import (
@@ -149,9 +149,9 @@ async def _build_media_items(self, title, category):
149149
items = [
150150
XboxMediaItem(
151151
item.user_caption
152-
or dt_util.as_local(
153-
dt_util.parse_datetime(item.date_recorded)
154-
).strftime("%b. %d, %Y %I:%M %p"),
152+
or dt_util.as_local(item.date_recorded).strftime(
153+
"%b. %d, %Y %I:%M %p"
154+
),
155155
item.thumbnails[0].uri,
156156
item.game_clip_uris[0].uri,
157157
MediaClass.VIDEO,

0 commit comments

Comments
 (0)