mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Add rtsp transport options to generic camera (#46623)
* Add rtsp transport options to generic camera
This commit is contained in:
parent
adf480025d
commit
39da0dc409
@ -34,6 +34,9 @@ CONF_LIMIT_REFETCH_TO_URL_CHANGE = "limit_refetch_to_url_change"
|
||||
CONF_STILL_IMAGE_URL = "still_image_url"
|
||||
CONF_STREAM_SOURCE = "stream_source"
|
||||
CONF_FRAMERATE = "framerate"
|
||||
CONF_RTSP_TRANSPORT = "rtsp_transport"
|
||||
FFMPEG_OPTION_MAP = {CONF_RTSP_TRANSPORT: "rtsp_transport"}
|
||||
ALLOWED_RTSP_TRANSPORT_PROTOCOLS = {"tcp", "udp", "udp_multicast", "http"}
|
||||
|
||||
DEFAULT_NAME = "Generic Camera"
|
||||
GET_IMAGE_TIMEOUT = 10
|
||||
@ -54,6 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
cv.small_float, cv.positive_int
|
||||
),
|
||||
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
|
||||
vol.Optional(CONF_RTSP_TRANSPORT): vol.In(ALLOWED_RTSP_TRANSPORT_PROTOCOLS),
|
||||
}
|
||||
)
|
||||
|
||||
@ -85,15 +89,19 @@ class GenericCamera(Camera):
|
||||
self._supported_features = SUPPORT_STREAM if self._stream_source else 0
|
||||
self.content_type = device_info[CONF_CONTENT_TYPE]
|
||||
self.verify_ssl = device_info[CONF_VERIFY_SSL]
|
||||
if device_info.get(CONF_RTSP_TRANSPORT):
|
||||
self.stream_options[FFMPEG_OPTION_MAP[CONF_RTSP_TRANSPORT]] = device_info[
|
||||
CONF_RTSP_TRANSPORT
|
||||
]
|
||||
|
||||
username = device_info.get(CONF_USERNAME)
|
||||
password = device_info.get(CONF_PASSWORD)
|
||||
|
||||
if username and password:
|
||||
if self._authentication == HTTP_DIGEST_AUTHENTICATION:
|
||||
self._auth = httpx.DigestAuth(username, password)
|
||||
self._auth = httpx.DigestAuth(username=username, password=password)
|
||||
else:
|
||||
self._auth = httpx.BasicAuth(username, password=password)
|
||||
self._auth = httpx.BasicAuth(username=username, password=password)
|
||||
else:
|
||||
self._auth = None
|
||||
|
||||
|
@ -250,6 +250,28 @@ async def test_stream_source_error(aioclient_mock, hass, hass_client, hass_ws_cl
|
||||
}
|
||||
|
||||
|
||||
async def test_setup_alternative_options(hass, hass_ws_client):
|
||||
"""Test that the stream source is setup with different config options."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"camera",
|
||||
{
|
||||
"camera": {
|
||||
"name": "config_test",
|
||||
"platform": "generic",
|
||||
"still_image_url": "https://example.com",
|
||||
"authentication": "digest",
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
"stream_source": "rtsp://example.com:554/rtsp/",
|
||||
"rtsp_transport": "udp",
|
||||
},
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data["camera"].get_entity("camera.config_test")
|
||||
|
||||
|
||||
async def test_no_stream_source(aioclient_mock, hass, hass_client, hass_ws_client):
|
||||
"""Test a stream request without stream source option set."""
|
||||
assert await async_setup_component(
|
||||
|
Loading…
x
Reference in New Issue
Block a user