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
2 changed files with 23 additions and 16 deletions
|
@ -10,8 +10,9 @@ from motioneye_client.const import KEY_MEDIA_LIST, KEY_MIME_TYPE, KEY_PATH
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
MEDIA_CLASS_DIRECTORY,
|
MEDIA_CLASS_DIRECTORY,
|
||||||
MEDIA_CLASS_IMAGE,
|
MEDIA_CLASS_IMAGE,
|
||||||
MEDIA_CLASS_MOVIE,
|
|
||||||
MEDIA_CLASS_VIDEO,
|
MEDIA_CLASS_VIDEO,
|
||||||
|
MEDIA_TYPE_IMAGE,
|
||||||
|
MEDIA_TYPE_VIDEO,
|
||||||
)
|
)
|
||||||
from homeassistant.components.media_source.error import MediaSourceError, Unresolvable
|
from homeassistant.components.media_source.error import MediaSourceError, Unresolvable
|
||||||
from homeassistant.components.media_source.models import (
|
from homeassistant.components.media_source.models import (
|
||||||
|
@ -239,7 +240,9 @@ class MotionEyeMediaSource(MediaSource):
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
identifier=f"{config.entry_id}#{device.id}#{kind}",
|
identifier=f"{config.entry_id}#{device.id}#{kind}",
|
||||||
media_class=MEDIA_CLASS_DIRECTORY,
|
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=(
|
title=(
|
||||||
f"{config.title} {device.name} {kind.title()}"
|
f"{config.title} {device.name} {kind.title()}"
|
||||||
if full_title
|
if full_title
|
||||||
|
@ -248,7 +251,7 @@ class MotionEyeMediaSource(MediaSource):
|
||||||
can_play=False,
|
can_play=False,
|
||||||
can_expand=True,
|
can_expand=True,
|
||||||
children_media_class=(
|
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)
|
parsed_path = PurePath(path)
|
||||||
if path != "/":
|
if path != "/":
|
||||||
base.title += " " + str(PurePath(*parsed_path.parts[1:]))
|
base.title += f" {PurePath(*parsed_path.parts[1:])}"
|
||||||
|
|
||||||
base.children = []
|
base.children = []
|
||||||
|
|
||||||
|
@ -339,7 +342,11 @@ class MotionEyeMediaSource(MediaSource):
|
||||||
f"#{kind}#{full_child_path}"
|
f"#{kind}#{full_child_path}"
|
||||||
),
|
),
|
||||||
media_class=MEDIA_CLASS_DIRECTORY,
|
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,
|
title=display_child_path,
|
||||||
can_play=False,
|
can_play=False,
|
||||||
can_expand=True,
|
can_expand=True,
|
||||||
|
|
|
@ -159,20 +159,20 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
|
||||||
{
|
{
|
||||||
"title": "Movies",
|
"title": "Movies",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "video",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
"media-source://motioneye"
|
"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||||
),
|
),
|
||||||
"can_play": False,
|
"can_play": False,
|
||||||
"can_expand": True,
|
"can_expand": True,
|
||||||
"children_media_class": "movie",
|
"children_media_class": "video",
|
||||||
"thumbnail": None,
|
"thumbnail": None,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Images",
|
"title": "Images",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "image",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
"media-source://motioneye"
|
"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#images"
|
f"/74565ad414754616000674c87bdc876c#{device.id}#images"
|
||||||
|
@ -193,20 +193,20 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
|
||||||
assert media.as_dict() == {
|
assert media.as_dict() == {
|
||||||
"title": "http://test:8766 Test Camera Movies",
|
"title": "http://test:8766 Test Camera Movies",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "video",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
"media-source://motioneye"
|
"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||||
),
|
),
|
||||||
"can_play": False,
|
"can_play": False,
|
||||||
"can_expand": True,
|
"can_expand": True,
|
||||||
"children_media_class": "movie",
|
"children_media_class": "video",
|
||||||
"thumbnail": None,
|
"thumbnail": None,
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"title": "2021-04-25",
|
"title": "2021-04-25",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "video",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
"media-source://motioneye"
|
"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies#/2021-04-25"
|
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() == {
|
assert media.as_dict() == {
|
||||||
"title": "http://test:8766 Test Camera Movies 2021-04-25",
|
"title": "http://test:8766 Test Camera Movies 2021-04-25",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "video",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
"media-source://motioneye"
|
"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||||
),
|
),
|
||||||
"can_play": False,
|
"can_play": False,
|
||||||
"can_expand": True,
|
"can_expand": True,
|
||||||
"children_media_class": "movie",
|
"children_media_class": "video",
|
||||||
"thumbnail": None,
|
"thumbnail": None,
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
|
@ -305,7 +305,7 @@ async def test_async_browse_media_images_success(hass: HomeAssistant) -> None:
|
||||||
assert media.as_dict() == {
|
assert media.as_dict() == {
|
||||||
"title": "http://test:8766 Test Camera Images 2021-04-12",
|
"title": "http://test:8766 Test Camera Images 2021-04-12",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "image",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
"media-source://motioneye"
|
"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#images"
|
f"/74565ad414754616000674c87bdc876c#{device.id}#images"
|
||||||
|
@ -469,14 +469,14 @@ async def test_async_resolve_media_failure(hass: HomeAssistant) -> None:
|
||||||
assert media.as_dict() == {
|
assert media.as_dict() == {
|
||||||
"title": "http://test:8766 Test Camera Movies 2021-04-25",
|
"title": "http://test:8766 Test Camera Movies 2021-04-25",
|
||||||
"media_class": "directory",
|
"media_class": "directory",
|
||||||
"media_content_type": "directory",
|
"media_content_type": "video",
|
||||||
"media_content_id": (
|
"media_content_id": (
|
||||||
f"media-source://motioneye"
|
f"media-source://motioneye"
|
||||||
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
f"/74565ad414754616000674c87bdc876c#{device.id}#movies"
|
||||||
),
|
),
|
||||||
"can_play": False,
|
"can_play": False,
|
||||||
"can_expand": True,
|
"can_expand": True,
|
||||||
"children_media_class": "movie",
|
"children_media_class": "video",
|
||||||
"thumbnail": None,
|
"thumbnail": None,
|
||||||
"children": [],
|
"children": [],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue