Improve mediabrowser names for DUO lens Reolink cameras (#124766)
* Improve playback of DUO lens cameras like TrackMix * fix styling * Adjust tests accordinglypull/124781/head
parent
8504a16e83
commit
d1681fac72
|
@ -174,10 +174,7 @@ class ReolinkVODMediaSource(MediaSource):
|
|||
if len(ch_id) > 3:
|
||||
ch = host.api.channel_for_uid(ch_id)
|
||||
|
||||
if (
|
||||
host.api.api_version("recReplay", int(ch)) < 1
|
||||
or not host.api.hdd_info
|
||||
):
|
||||
if not host.api.supported(int(ch), "replay") or not host.api.hdd_info:
|
||||
# playback stream not supported by this camera or no storage installed
|
||||
continue
|
||||
|
||||
|
@ -281,12 +278,16 @@ class ReolinkVODMediaSource(MediaSource):
|
|||
config_entry_id, channel, "sub"
|
||||
)
|
||||
|
||||
title = host.api.camera_name(channel)
|
||||
if host.api.model in DUAL_LENS_MODELS:
|
||||
title = f"{host.api.camera_name(channel)} lens {channel}"
|
||||
|
||||
return BrowseMediaSource(
|
||||
domain=DOMAIN,
|
||||
identifier=f"RESs|{config_entry_id}|{channel}",
|
||||
media_class=MediaClass.CHANNEL,
|
||||
media_content_type=MediaType.PLAYLIST,
|
||||
title=host.api.camera_name(channel),
|
||||
title=title,
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
children=children,
|
||||
|
@ -328,12 +329,16 @@ class ReolinkVODMediaSource(MediaSource):
|
|||
for day in status.days
|
||||
]
|
||||
|
||||
title = f"{host.api.camera_name(channel)} {res_name(stream)}"
|
||||
if host.api.model in DUAL_LENS_MODELS:
|
||||
title = f"{host.api.camera_name(channel)} lens {channel} {res_name(stream)}"
|
||||
|
||||
return BrowseMediaSource(
|
||||
domain=DOMAIN,
|
||||
identifier=f"DAYS|{config_entry_id}|{channel}|{stream}",
|
||||
media_class=MediaClass.CHANNEL,
|
||||
media_content_type=MediaType.PLAYLIST,
|
||||
title=f"{host.api.camera_name(channel)} {res_name(stream)}",
|
||||
title=title,
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
children=children,
|
||||
|
@ -388,12 +393,18 @@ class ReolinkVODMediaSource(MediaSource):
|
|||
)
|
||||
)
|
||||
|
||||
title = (
|
||||
f"{host.api.camera_name(channel)} {res_name(stream)} {year}/{month}/{day}"
|
||||
)
|
||||
if host.api.model in DUAL_LENS_MODELS:
|
||||
title = f"{host.api.camera_name(channel)} lens {channel} {res_name(stream)} {year}/{month}/{day}"
|
||||
|
||||
return BrowseMediaSource(
|
||||
domain=DOMAIN,
|
||||
identifier=f"FILES|{config_entry_id}|{channel}|{stream}",
|
||||
media_class=MediaClass.CHANNEL,
|
||||
media_content_type=MediaType.PLAYLIST,
|
||||
title=f"{host.api.camera_name(channel)} {res_name(stream)} {year}/{month}/{day}",
|
||||
title=title,
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
children=children,
|
||||
|
|
|
@ -130,7 +130,7 @@ async def test_browsing(
|
|||
) -> None:
|
||||
"""Test browsing the Reolink three."""
|
||||
entry_id = config_entry.entry_id
|
||||
reolink_connect.api_version.return_value = 1
|
||||
reolink_connect.supported.return_value = 1
|
||||
reolink_connect.model = "Reolink TrackMix PoE"
|
||||
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
|
||||
|
@ -162,7 +162,7 @@ async def test_browsing(
|
|||
browse_res_AT_sub_id = f"RES|{entry_id}|{TEST_CHANNEL}|autotrack_sub"
|
||||
browse_res_AT_main_id = f"RES|{entry_id}|{TEST_CHANNEL}|autotrack_main"
|
||||
assert browse.domain == DOMAIN
|
||||
assert browse.title == TEST_NVR_NAME
|
||||
assert browse.title == f"{TEST_NVR_NAME} lens 0"
|
||||
assert browse.identifier == browse_resolution_id
|
||||
assert browse.children[0].identifier == browse_res_sub_id
|
||||
assert browse.children[1].identifier == browse_res_main_id
|
||||
|
@ -178,19 +178,19 @@ async def test_browsing(
|
|||
|
||||
browse = await async_browse_media(hass, f"{URI_SCHEME}{DOMAIN}/{browse_res_sub_id}")
|
||||
assert browse.domain == DOMAIN
|
||||
assert browse.title == f"{TEST_NVR_NAME} Low res."
|
||||
assert browse.title == f"{TEST_NVR_NAME} lens 0 Low res."
|
||||
|
||||
browse = await async_browse_media(
|
||||
hass, f"{URI_SCHEME}{DOMAIN}/{browse_res_AT_sub_id}"
|
||||
)
|
||||
assert browse.domain == DOMAIN
|
||||
assert browse.title == f"{TEST_NVR_NAME} Autotrack low res."
|
||||
assert browse.title == f"{TEST_NVR_NAME} lens 0 Autotrack low res."
|
||||
|
||||
browse = await async_browse_media(
|
||||
hass, f"{URI_SCHEME}{DOMAIN}/{browse_res_AT_main_id}"
|
||||
)
|
||||
assert browse.domain == DOMAIN
|
||||
assert browse.title == f"{TEST_NVR_NAME} Autotrack high res."
|
||||
assert browse.title == f"{TEST_NVR_NAME} lens 0 Autotrack high res."
|
||||
|
||||
browse = await async_browse_media(
|
||||
hass, f"{URI_SCHEME}{DOMAIN}/{browse_res_main_id}"
|
||||
|
@ -200,7 +200,7 @@ async def test_browsing(
|
|||
browse_day_0_id = f"DAY|{entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_YEAR}|{TEST_MONTH}|{TEST_DAY}"
|
||||
browse_day_1_id = f"DAY|{entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_YEAR}|{TEST_MONTH}|{TEST_DAY2}"
|
||||
assert browse.domain == DOMAIN
|
||||
assert browse.title == f"{TEST_NVR_NAME} High res."
|
||||
assert browse.title == f"{TEST_NVR_NAME} lens 0 High res."
|
||||
assert browse.identifier == browse_days_id
|
||||
assert browse.children[0].identifier == browse_day_0_id
|
||||
assert browse.children[1].identifier == browse_day_1_id
|
||||
|
@ -220,7 +220,8 @@ async def test_browsing(
|
|||
browse_file_id = f"FILE|{entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME}"
|
||||
assert browse.domain == DOMAIN
|
||||
assert (
|
||||
browse.title == f"{TEST_NVR_NAME} High res. {TEST_YEAR}/{TEST_MONTH}/{TEST_DAY}"
|
||||
browse.title
|
||||
== f"{TEST_NVR_NAME} lens 0 High res. {TEST_YEAR}/{TEST_MONTH}/{TEST_DAY}"
|
||||
)
|
||||
assert browse.identifier == browse_files_id
|
||||
assert browse.children[0].identifier == browse_file_id
|
||||
|
@ -272,7 +273,7 @@ async def test_browsing_rec_playback_unsupported(
|
|||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test browsing a Reolink camera which does not support playback of recordings."""
|
||||
reolink_connect.api_version.return_value = 0
|
||||
reolink_connect.supported.return_value = 0
|
||||
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
@ -293,7 +294,7 @@ async def test_browsing_errors(
|
|||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test browsing a Reolink camera errors."""
|
||||
reolink_connect.api_version.return_value = 1
|
||||
reolink_connect.supported.return_value = 1
|
||||
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
@ -312,7 +313,7 @@ async def test_browsing_not_loaded(
|
|||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test browsing a Reolink camera integration which is not loaded."""
|
||||
reolink_connect.api_version.return_value = 1
|
||||
reolink_connect.supported.return_value = 1
|
||||
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
|
Loading…
Reference in New Issue