Type BrowseMedia children as a covariant (#76869)

pull/67058/head^2
Franck Nijhof 2022-08-16 16:31:09 +02:00 committed by GitHub
parent 2e191d6a60
commit 63d71457aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 18 deletions

View File

@ -422,7 +422,7 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
return cur_item
# Add app item if we have one
if self._app_list and cur_item.children:
if self._app_list and cur_item.children and isinstance(cur_item.children, list):
cur_item.children.insert(0, build_app_list(self._app_list))
return cur_item

View File

@ -173,10 +173,10 @@ class JellyfinSource(MediaSource):
if include_children:
result.children_media_class = MEDIA_CLASS_ARTIST
result.children = await self._build_artists(library_id) # type: ignore[assignment]
result.children = await self._build_artists(library_id)
if not result.children:
result.children_media_class = MEDIA_CLASS_ALBUM
result.children = await self._build_albums(library_id) # type: ignore[assignment]
result.children = await self._build_albums(library_id)
return result
@ -207,7 +207,7 @@ class JellyfinSource(MediaSource):
if include_children:
result.children_media_class = MEDIA_CLASS_ALBUM
result.children = await self._build_albums(artist_id) # type: ignore[assignment]
result.children = await self._build_albums(artist_id)
return result
@ -238,7 +238,7 @@ class JellyfinSource(MediaSource):
if include_children:
result.children_media_class = MEDIA_CLASS_TRACK
result.children = await self._build_tracks(album_id) # type: ignore[assignment]
result.children = await self._build_tracks(album_id)
return result
@ -293,7 +293,7 @@ class JellyfinSource(MediaSource):
if include_children:
result.children_media_class = MEDIA_CLASS_MOVIE
result.children = await self._build_movies(library_id) # type: ignore[assignment]
result.children = await self._build_movies(library_id)
return result

View File

@ -1,6 +1,7 @@
"""Browse media features for media player."""
from __future__ import annotations
from collections.abc import Sequence
from datetime import timedelta
import logging
from typing import Any
@ -97,7 +98,7 @@ class BrowseMedia:
title: str,
can_play: bool,
can_expand: bool,
children: list[BrowseMedia] | None = None,
children: Sequence[BrowseMedia] | None = None,
children_media_class: str | None = None,
thumbnail: str | None = None,
not_shown: int = 0,

View File

@ -27,8 +27,6 @@ class PlayMedia:
class BrowseMediaSource(BrowseMedia):
"""Represent a browsable media file."""
children: list[BrowseMediaSource | BrowseMedia] | None
def __init__(
self, *, domain: str | None, identifier: str | None, **kwargs: Any
) -> None:

View File

@ -528,7 +528,7 @@ class ProtectMediaSource(MediaSource):
args["camera_id"] = camera_id
events = await self._build_events(**args) # type: ignore[arg-type]
source.children = events # type: ignore[assignment]
source.children = events
source.title = self._breadcrumb(
data,
title,
@ -653,7 +653,7 @@ class ProtectMediaSource(MediaSource):
title = f"{start.strftime('%B %Y')} > {title}"
events = await self._build_events(**args) # type: ignore[arg-type]
source.children = events # type: ignore[assignment]
source.children = events
source.title = self._breadcrumb(
data,
title,

View File

@ -1,7 +1,7 @@
"""Support for media browsing."""
from __future__ import annotations
from typing import TYPE_CHECKING, NamedTuple
from typing import NamedTuple
from xbox.webapi.api.client import XboxLiveClient
from xbox.webapi.api.provider.catalog.const import HOME_APP_IDS, SYSTEM_PFN_ID_MAP
@ -56,6 +56,7 @@ async def build_item_response(
apps: InstalledPackagesList = await client.smartglass.get_installed_apps(device_id)
if media_content_type in (None, "library"):
children: list[BrowseMedia] = []
library_info = BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id="library",
@ -63,10 +64,8 @@ async def build_item_response(
title="Installed Applications",
can_play=False,
can_expand=True,
children=[],
children=children,
)
if TYPE_CHECKING:
assert library_info.children is not None
# Add Home
id_type = AlternateIdType.LEGACY_XBOX_PRODUCT_ID
@ -78,7 +77,7 @@ async def build_item_response(
home_thumb = _find_media_image(
home_catalog.products[0].localized_properties[0].images
)
library_info.children.append(
children.append(
BrowseMedia(
media_class=MEDIA_CLASS_APP,
media_content_id="Home",
@ -101,7 +100,7 @@ async def build_item_response(
tv_thumb = _find_media_image(
tv_catalog.products[0].localized_properties[0].images
)
library_info.children.append(
children.append(
BrowseMedia(
media_class=MEDIA_CLASS_APP,
media_content_id="TV",
@ -117,7 +116,7 @@ async def build_item_response(
{app.content_type for app in apps.result if app.content_type in TYPE_MAP}
)
for c_type in content_types:
library_info.children.append(
children.append(
BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id=c_type,