1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Make Stream.stop() async (#73107)

* Make Stream.start() async
* Stop streams concurrently on shutdown
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
uvjustin
2022-06-08 02:10:53 +10:00
committed by GitHub
parent c6b835dd91
commit 73f2bca377
11 changed files with 92 additions and 67 deletions

View File

@@ -158,6 +158,7 @@ async def mock_create_stream(hass) -> Mock:
)
mock_stream.return_value.async_get_image = AsyncMock()
mock_stream.return_value.async_get_image.return_value = IMAGE_BYTES_FROM_STREAM
mock_stream.return_value.start = AsyncMock()
yield mock_stream
@@ -370,6 +371,7 @@ async def test_refresh_expired_stream_token(
# Request a stream for the camera entity to exercise nest cam + camera interaction
# and shutdown on url expiration
with patch("homeassistant.components.camera.create_stream") as create_stream:
create_stream.return_value.start = AsyncMock()
hls_url = await camera.async_request_stream(hass, "camera.my_camera", fmt="hls")
assert hls_url.startswith("/api/hls/") # Includes access token
assert create_stream.called
@@ -536,7 +538,8 @@ async def test_refresh_expired_stream_failure(
# Request an HLS stream
with patch("homeassistant.components.camera.create_stream") as create_stream:
create_stream.return_value.start = AsyncMock()
create_stream.return_value.stop = AsyncMock()
hls_url = await camera.async_request_stream(hass, "camera.my_camera", fmt="hls")
assert hls_url.startswith("/api/hls/") # Includes access token
assert create_stream.called
@@ -555,6 +558,7 @@ async def test_refresh_expired_stream_failure(
# Requesting an HLS stream will create an entirely new stream
with patch("homeassistant.components.camera.create_stream") as create_stream:
create_stream.return_value.start = AsyncMock()
# The HLS stream endpoint was invalidated, with a new auth token
hls_url2 = await camera.async_request_stream(
hass, "camera.my_camera", fmt="hls"