mirror of
https://github.com/home-assistant/core
synced 2024-10-01 05:30:36 +02:00
Use NamedTuple for xbox media type details (#56753)
This commit is contained in:
parent
15aafc8db6
commit
718f8d8bf7
@ -1,6 +1,8 @@
|
|||||||
"""Support for media browsing."""
|
"""Support for media browsing."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import NamedTuple
|
||||||
|
|
||||||
from xbox.webapi.api.client import XboxLiveClient
|
from xbox.webapi.api.client import XboxLiveClient
|
||||||
from xbox.webapi.api.provider.catalog.const import HOME_APP_IDS, SYSTEM_PFN_ID_MAP
|
from xbox.webapi.api.provider.catalog.const import HOME_APP_IDS, SYSTEM_PFN_ID_MAP
|
||||||
from xbox.webapi.api.provider.catalog.models import (
|
from xbox.webapi.api.provider.catalog.models import (
|
||||||
@ -23,15 +25,23 @@ from homeassistant.components.media_player.const import (
|
|||||||
MEDIA_TYPE_GAME,
|
MEDIA_TYPE_GAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MediaTypeDetails(NamedTuple):
|
||||||
|
"""Details for media type."""
|
||||||
|
|
||||||
|
type: str
|
||||||
|
cls: str
|
||||||
|
|
||||||
|
|
||||||
TYPE_MAP = {
|
TYPE_MAP = {
|
||||||
"App": {
|
"App": MediaTypeDetails(
|
||||||
"type": MEDIA_TYPE_APP,
|
type=MEDIA_TYPE_APP,
|
||||||
"class": MEDIA_CLASS_APP,
|
cls=MEDIA_CLASS_APP,
|
||||||
},
|
),
|
||||||
"Game": {
|
"Game": MediaTypeDetails(
|
||||||
"type": MEDIA_TYPE_GAME,
|
type=MEDIA_TYPE_GAME,
|
||||||
"class": MEDIA_CLASS_GAME,
|
cls=MEDIA_CLASS_GAME,
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -109,11 +119,11 @@ async def build_item_response(
|
|||||||
BrowseMedia(
|
BrowseMedia(
|
||||||
media_class=MEDIA_CLASS_DIRECTORY,
|
media_class=MEDIA_CLASS_DIRECTORY,
|
||||||
media_content_id=c_type,
|
media_content_id=c_type,
|
||||||
media_content_type=TYPE_MAP[c_type]["type"],
|
media_content_type=TYPE_MAP[c_type].type,
|
||||||
title=f"{c_type}s",
|
title=f"{c_type}s",
|
||||||
can_play=False,
|
can_play=False,
|
||||||
can_expand=True,
|
can_expand=True,
|
||||||
children_media_class=TYPE_MAP[c_type]["class"],
|
children_media_class=TYPE_MAP[c_type].cls,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -145,7 +155,7 @@ async def build_item_response(
|
|||||||
for app in apps.result
|
for app in apps.result
|
||||||
if app.content_type == media_content_id and app.one_store_product_id
|
if app.content_type == media_content_id and app.one_store_product_id
|
||||||
],
|
],
|
||||||
children_media_class=TYPE_MAP[media_content_id]["class"],
|
children_media_class=TYPE_MAP[media_content_id].cls,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -159,9 +169,9 @@ def item_payload(item: InstalledPackage, images: dict[str, list[Image]]):
|
|||||||
thumbnail = f"https:{thumbnail}"
|
thumbnail = f"https:{thumbnail}"
|
||||||
|
|
||||||
return BrowseMedia(
|
return BrowseMedia(
|
||||||
media_class=TYPE_MAP[item.content_type]["class"],
|
media_class=TYPE_MAP[item.content_type].cls,
|
||||||
media_content_id=item.one_store_product_id,
|
media_content_id=item.one_store_product_id,
|
||||||
media_content_type=TYPE_MAP[item.content_type]["type"],
|
media_content_type=TYPE_MAP[item.content_type].type,
|
||||||
title=item.name,
|
title=item.name,
|
||||||
can_play=True,
|
can_play=True,
|
||||||
can_expand=False,
|
can_expand=False,
|
||||||
|
Loading…
Reference in New Issue
Block a user