2018-09-26 09:49:55 +02:00
|
|
|
"""Collection of helper methods.
|
|
|
|
|
|
|
|
|
|
All containing methods are legacy helpers that should not be used by new
|
|
|
|
|
components. Instead call the service directly.
|
|
|
|
|
"""
|
2024-03-08 14:50:25 +01:00
|
|
|
|
2021-08-10 19:33:06 -05:00
|
|
|
from unittest.mock import Mock
|
|
|
|
|
|
2024-11-19 03:41:50 +01:00
|
|
|
from webrtc_models import RTCIceCandidateInit
|
2024-11-05 14:44:37 +01:00
|
|
|
|
|
|
|
|
from homeassistant.components.camera import (
|
|
|
|
|
Camera,
|
|
|
|
|
CameraWebRTCProvider,
|
|
|
|
|
WebRTCAnswer,
|
|
|
|
|
WebRTCSendMessage,
|
|
|
|
|
)
|
|
|
|
|
from homeassistant.core import callback
|
|
|
|
|
|
2021-08-10 19:33:06 -05:00
|
|
|
EMPTY_8_6_JPEG = b"empty_8_6"
|
2022-02-08 14:32:02 -08:00
|
|
|
WEBRTC_ANSWER = "a=sendonly"
|
2024-10-03 09:20:03 +02:00
|
|
|
STREAM_SOURCE = "rtsp://127.0.0.1/stream"
|
2021-08-10 19:33:06 -05:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
|
2021-08-10 19:33:06 -05:00
|
|
|
def mock_turbo_jpeg(
|
|
|
|
|
first_width=None, second_width=None, first_height=None, second_height=None
|
|
|
|
|
):
|
|
|
|
|
"""Mock a TurboJPEG instance."""
|
|
|
|
|
mocked_turbo_jpeg = Mock()
|
|
|
|
|
mocked_turbo_jpeg.decode_header.side_effect = [
|
|
|
|
|
(first_width, first_height, 0, 0),
|
|
|
|
|
(second_width, second_height, 0, 0),
|
|
|
|
|
]
|
|
|
|
|
mocked_turbo_jpeg.scale_with_quality.return_value = EMPTY_8_6_JPEG
|
2021-12-23 00:24:53 +08:00
|
|
|
mocked_turbo_jpeg.encode.return_value = EMPTY_8_6_JPEG
|
2021-08-10 19:33:06 -05:00
|
|
|
return mocked_turbo_jpeg
|
2024-11-05 14:44:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class SomeTestProvider(CameraWebRTCProvider):
|
|
|
|
|
"""Test provider."""
|
|
|
|
|
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
|
"""Initialize the provider."""
|
|
|
|
|
self._is_supported = True
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def domain(self) -> str:
|
|
|
|
|
"""Return the integration domain of the provider."""
|
|
|
|
|
return "some_test"
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
|
def async_is_supported(self, stream_source: str) -> bool:
|
|
|
|
|
"""Determine if the provider supports the stream source."""
|
|
|
|
|
return self._is_supported
|
|
|
|
|
|
|
|
|
|
async def async_handle_async_webrtc_offer(
|
|
|
|
|
self,
|
|
|
|
|
camera: Camera,
|
|
|
|
|
offer_sdp: str,
|
|
|
|
|
session_id: str,
|
|
|
|
|
send_message: WebRTCSendMessage,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Handle the WebRTC offer and return the answer via the provided callback.
|
|
|
|
|
|
|
|
|
|
Return value determines if the offer was handled successfully.
|
|
|
|
|
"""
|
|
|
|
|
send_message(WebRTCAnswer(answer="answer"))
|
|
|
|
|
|
|
|
|
|
async def async_on_webrtc_candidate(
|
2024-11-19 03:41:50 +01:00
|
|
|
self, session_id: str, candidate: RTCIceCandidateInit
|
2024-11-05 14:44:37 +01:00
|
|
|
) -> None:
|
|
|
|
|
"""Handle the WebRTC candidate."""
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
|
def async_close_session(self, session_id: str) -> None:
|
|
|
|
|
"""Close the session."""
|