mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Fix camera content type while browsing (#67256)
This commit is contained in:
parent
442e2eecd5
commit
7e4b63690d
@ -73,10 +73,7 @@ class CameraMediaSource(MediaSource):
|
||||
if item.identifier:
|
||||
raise BrowseError("Unknown item")
|
||||
|
||||
supported_stream_types: list[str | None] = [None]
|
||||
|
||||
if "stream" in self.hass.config.components:
|
||||
supported_stream_types.append(STREAM_TYPE_HLS)
|
||||
can_stream_hls = "stream" in self.hass.config.components
|
||||
|
||||
# Root. List cameras.
|
||||
component: EntityComponent = self.hass.data[DOMAIN]
|
||||
@ -86,7 +83,13 @@ class CameraMediaSource(MediaSource):
|
||||
camera = cast(Camera, camera)
|
||||
stream_type = camera.frontend_stream_type
|
||||
|
||||
if stream_type not in supported_stream_types:
|
||||
if stream_type is None:
|
||||
content_type = camera.content_type
|
||||
|
||||
elif can_stream_hls and stream_type == STREAM_TYPE_HLS:
|
||||
content_type = FORMAT_CONTENT_TYPE[HLS_PROVIDER]
|
||||
|
||||
else:
|
||||
not_shown += 1
|
||||
continue
|
||||
|
||||
@ -95,7 +98,7 @@ class CameraMediaSource(MediaSource):
|
||||
domain=DOMAIN,
|
||||
identifier=camera.entity_id,
|
||||
media_class=MEDIA_CLASS_VIDEO,
|
||||
media_content_type=FORMAT_CONTENT_TYPE[HLS_PROVIDER],
|
||||
media_content_type=content_type,
|
||||
title=camera.name,
|
||||
thumbnail=f"/api/camera_proxy/{camera.entity_id}",
|
||||
can_play=True,
|
||||
|
@ -15,21 +15,35 @@ async def setup_media_source(hass):
|
||||
assert await async_setup_component(hass, "media_source", {})
|
||||
|
||||
|
||||
async def test_browsing(hass, mock_camera_hls):
|
||||
async def test_browsing_hls(hass, mock_camera_hls):
|
||||
"""Test browsing camera media source."""
|
||||
item = await media_source.async_browse_media(hass, "media-source://camera")
|
||||
assert item is not None
|
||||
assert item.title == "Camera"
|
||||
assert len(item.children) == 0
|
||||
assert item.not_shown == 2
|
||||
|
||||
# Adding stream enables HLS camera
|
||||
hass.config.components.add("stream")
|
||||
|
||||
item = await media_source.async_browse_media(hass, "media-source://camera")
|
||||
assert item.not_shown == 0
|
||||
assert len(item.children) == 2
|
||||
assert item.children[0].media_content_type == FORMAT_CONTENT_TYPE["hls"]
|
||||
|
||||
|
||||
async def test_browsing_filter_non_hls(hass, mock_camera_web_rtc):
|
||||
async def test_browsing_mjpeg(hass, mock_camera):
|
||||
"""Test browsing camera media source."""
|
||||
item = await media_source.async_browse_media(hass, "media-source://camera")
|
||||
assert item is not None
|
||||
assert item.title == "Camera"
|
||||
assert len(item.children) == 2
|
||||
assert item.not_shown == 0
|
||||
assert item.children[0].media_content_type == "image/jpg"
|
||||
assert item.children[1].media_content_type == "image/png"
|
||||
|
||||
|
||||
async def test_browsing_filter_web_rtc(hass, mock_camera_web_rtc):
|
||||
"""Test browsing camera media source hides non-HLS cameras."""
|
||||
item = await media_source.async_browse_media(hass, "media-source://camera")
|
||||
assert item is not None
|
||||
|
Loading…
x
Reference in New Issue
Block a user