2018-09-26 07:49:55 +00:00
|
|
|
"""Collection of helper methods.
|
|
|
|
|
|
|
|
All containing methods are legacy helpers that should not be used by new
|
|
|
|
components. Instead call the service directly.
|
|
|
|
"""
|
2021-08-11 00:33:06 +00:00
|
|
|
from unittest.mock import Mock
|
|
|
|
|
2020-04-11 19:10:15 +00:00
|
|
|
from homeassistant.components.camera.const import DATA_CAMERA_PREFS, PREF_PRELOAD_STREAM
|
2018-09-26 07:49:55 +00:00
|
|
|
|
2021-08-11 00:33:06 +00:00
|
|
|
EMPTY_8_6_JPEG = b"empty_8_6"
|
2022-02-08 22:32:02 +00:00
|
|
|
WEBRTC_ANSWER = "a=sendonly"
|
2021-08-11 00:33:06 +00:00
|
|
|
|
2018-09-26 07:49:55 +00:00
|
|
|
|
2020-04-11 19:10:15 +00:00
|
|
|
def mock_camera_prefs(hass, entity_id, prefs=None):
|
2019-03-26 12:31:29 +00:00
|
|
|
"""Fixture for cloud component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
prefs_to_set = {PREF_PRELOAD_STREAM: True}
|
2020-04-11 19:10:15 +00:00
|
|
|
if prefs is not None:
|
|
|
|
prefs_to_set.update(prefs)
|
2019-03-26 12:31:29 +00:00
|
|
|
hass.data[DATA_CAMERA_PREFS]._prefs[entity_id] = prefs_to_set
|
|
|
|
return prefs_to_set
|
2021-08-11 00:33:06 +00: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-22 16:24:53 +00:00
|
|
|
mocked_turbo_jpeg.encode.return_value = EMPTY_8_6_JPEG
|
2021-08-11 00:33:06 +00:00
|
|
|
return mocked_turbo_jpeg
|