mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Address late review of motionEye media browser (#58925)
* Media-content type fixes post-codereview. * More f-string. * Use the 'video' media class not 'movie'.
This commit is contained in:
parent
16371e6579
commit
8fda2e0a1d
@ -10,8 +10,9 @@ from motioneye_client.const import KEY_MEDIA_LIST, KEY_MIME_TYPE, KEY_PATH
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_CLASS_DIRECTORY,
|
||||
MEDIA_CLASS_IMAGE,
|
||||
MEDIA_CLASS_MOVIE,
|
||||
MEDIA_CLASS_VIDEO,
|
||||
MEDIA_TYPE_IMAGE,
|
||||
MEDIA_TYPE_VIDEO,
|
||||
)
|
||||
from homeassistant.components.media_source.error import MediaSourceError, Unresolvable
|
||||
from homeassistant.components.media_source.models import (
|
||||
@ -239,7 +240,9 @@ class MotionEyeMediaSource(MediaSource):
|
||||
domain=DOMAIN,
|
||||
identifier=f"{config.entry_id}#{device.id}#{kind}",
|
||||
media_class=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_type=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_type=(
|
||||
MEDIA_TYPE_VIDEO if kind == "movies" else MEDIA_TYPE_IMAGE
|
||||
),
|
||||
title=(
|
||||
f"{config.title} {device.name} {kind.title()}"
|
||||
if full_title
|
||||
@ -248,7 +251,7 @@ class MotionEyeMediaSource(MediaSource):
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
children_media_class=(
|
||||
MEDIA_CLASS_MOVIE if kind == "movies" else MEDIA_CLASS_IMAGE
|
||||
MEDIA_CLASS_VIDEO if kind == "movies" else MEDIA_CLASS_IMAGE
|
||||
),
|
||||
)
|
||||
|
||||
@ -274,7 +277,7 @@ class MotionEyeMediaSource(MediaSource):
|
||||
|
||||
parsed_path = PurePath(path)
|
||||
if path != "/":
|
||||
base.title += " " + str(PurePath(*parsed_path.parts[1:]))
|
||||
base.title += f" {PurePath(*parsed_path.parts[1:])}"
|
||||
|
||||
base.children = []
|
||||
|
||||
@ -339,7 +342,11 @@ class MotionEyeMediaSource(MediaSource):
|
||||
f"#{kind}#{full_child_path}"
|
||||
),
|
||||
media_class=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_type=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_type=(
|
||||
MEDIA_TYPE_VIDEO
|
||||
if kind == "movies"
|
||||
else MEDIA_TYPE_IMAGE
|
||||
),
|
||||
title=display_child_path,
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
|
@ -159,20 +159,20 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
|
||||
{
|
||||
"title": "Movies",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "video",
|
||||
"media_content_id": (
|
||||
"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||
),
|
||||
"can_play": False,
|
||||
"can_expand": True,
|
||||
"children_media_class": "movie",
|
||||
"children_media_class": "video",
|
||||
"thumbnail": None,
|
||||
},
|
||||
{
|
||||
"title": "Images",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "image",
|
||||
"media_content_id": (
|
||||
"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#images"
|
||||
@ -193,20 +193,20 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
|
||||
assert media.as_dict() == {
|
||||
"title": "http://test:8766 Test Camera Movies",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "video",
|
||||
"media_content_id": (
|
||||
"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||
),
|
||||
"can_play": False,
|
||||
"can_expand": True,
|
||||
"children_media_class": "movie",
|
||||
"children_media_class": "video",
|
||||
"thumbnail": None,
|
||||
"children": [
|
||||
{
|
||||
"title": "2021-04-25",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "video",
|
||||
"media_content_id": (
|
||||
"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies#/2021-04-25"
|
||||
@ -227,14 +227,14 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
|
||||
assert media.as_dict() == {
|
||||
"title": "http://test:8766 Test Camera Movies 2021-04-25",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "video",
|
||||
"media_content_id": (
|
||||
"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||
),
|
||||
"can_play": False,
|
||||
"can_expand": True,
|
||||
"children_media_class": "movie",
|
||||
"children_media_class": "video",
|
||||
"thumbnail": None,
|
||||
"children": [
|
||||
{
|
||||
@ -305,7 +305,7 @@ async def test_async_browse_media_images_success(hass: HomeAssistant) -> None:
|
||||
assert media.as_dict() == {
|
||||
"title": "http://test:8766 Test Camera Images 2021-04-12",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "image",
|
||||
"media_content_id": (
|
||||
"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#images"
|
||||
@ -469,14 +469,14 @@ async def test_async_resolve_media_failure(hass: HomeAssistant) -> None:
|
||||
assert media.as_dict() == {
|
||||
"title": "http://test:8766 Test Camera Movies 2021-04-25",
|
||||
"media_class": "directory",
|
||||
"media_content_type": "directory",
|
||||
"media_content_type": "video",
|
||||
"media_content_id": (
|
||||
f"media-source://motioneye"
|
||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||
),
|
||||
"can_play": False,
|
||||
"can_expand": True,
|
||||
"children_media_class": "movie",
|
||||
"children_media_class": "video",
|
||||
"thumbnail": None,
|
||||
"children": [],
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user