Sort media sources (#66237)
* Sort media sources * Flatten media sources and sort Cast children * Only expand if possible
This commit is contained in:
parent
3733aa9494
commit
e90143e5c9
2 changed files with 19 additions and 16 deletions
|
@ -473,13 +473,13 @@ class CastDevice(MediaPlayerEntity):
|
|||
result = await media_source.async_browse_media(
|
||||
self.hass, None, content_filter=content_filter
|
||||
)
|
||||
children.append(result)
|
||||
children.extend(result.children)
|
||||
except BrowseError:
|
||||
if not children:
|
||||
raise
|
||||
|
||||
# If there's only one media source, resolve it
|
||||
if len(children) == 1:
|
||||
if len(children) == 1 and children[0].can_expand:
|
||||
return await self.async_browse_media(
|
||||
children[0].media_content_type,
|
||||
children[0].media_content_id,
|
||||
|
@ -492,7 +492,7 @@ class CastDevice(MediaPlayerEntity):
|
|||
media_content_type="",
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
children=children,
|
||||
children=sorted(children, key=lambda c: c.title),
|
||||
)
|
||||
|
||||
async def async_browse_media(self, media_content_type=None, media_content_id=None):
|
||||
|
|
|
@ -64,19 +64,22 @@ class MediaSourceItem:
|
|||
can_expand=True,
|
||||
children_media_class=MEDIA_CLASS_APP,
|
||||
)
|
||||
base.children = [
|
||||
BrowseMediaSource(
|
||||
domain=source.domain,
|
||||
identifier=None,
|
||||
media_class=MEDIA_CLASS_APP,
|
||||
media_content_type=MEDIA_TYPE_APP,
|
||||
thumbnail=f"https://brands.home-assistant.io/_/{source.domain}/logo.png",
|
||||
title=source.name,
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
)
|
||||
for source in self.hass.data[DOMAIN].values()
|
||||
]
|
||||
base.children = sorted(
|
||||
(
|
||||
BrowseMediaSource(
|
||||
domain=source.domain,
|
||||
identifier=None,
|
||||
media_class=MEDIA_CLASS_APP,
|
||||
media_content_type=MEDIA_TYPE_APP,
|
||||
thumbnail=f"https://brands.home-assistant.io/_/{source.domain}/logo.png",
|
||||
title=source.name,
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
)
|
||||
for source in self.hass.data[DOMAIN].values()
|
||||
),
|
||||
key=lambda item: item.title,
|
||||
)
|
||||
return base
|
||||
|
||||
return await self.async_media_source().async_browse_media(self)
|
||||
|
|
Loading…
Add table
Reference in a new issue