Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ async def async_get_image(hass, entity_id, timeout=10):
raise HomeAssistantError("Unable to get image")


@bind_hass
async def async_get_stream_source(hass, entity_id):
"""Fetch the stream source for a camera entity."""
camera = _get_camera_from_entity_id(hass, entity_id)

return await camera.stream_source()


@bind_hass
async def async_get_mjpeg_stream(hass, request, entity_id):
"""Fetch an mjpeg stream from a camera entity."""
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/homekit/type_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ async def _async_get_stream_source(self):
if stream_source:
return stream_source
try:
stream_source = await camera.stream_source()
Comment thread
bdraco marked this conversation as resolved.
stream_source = await self.hass.components.camera.async_get_stream_source(
self.entity_id
)
except Exception: # pylint: disable=broad-except
_LOGGER.exception(
"Failed to get stream source - this could be a transient error or your camera might not be compatible with HomeKit yet"
Expand Down
13 changes: 13 additions & 0 deletions tests/components/camera/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ async def test_get_image_from_camera(hass, image_mock_url):
assert image.content == b"Test"


async def test_get_stream_source_from_camera(hass, mock_camera):
"""Fetch stream source from camera entity."""

with patch(
"homeassistant.components.camera.Camera.stream_source",
return_value="rtsp://127.0.0.1/stream",
) as mock_camera_stream_source:
stream_source = await camera.async_get_stream_source(hass, "camera.demo_camera")

assert mock_camera_stream_source.called
assert stream_source == "rtsp://127.0.0.1/stream"


async def test_get_image_without_exists_camera(hass, image_mock_url):
"""Try to get image without exists camera."""
with patch(
Expand Down