44from datetime import timedelta
55from http import HTTPStatus
66from typing import Any
7- from unittest .mock import patch
7+ from unittest .mock import AsyncMock , Mock , patch
88
99import aiohttp
1010from freezegun .api import FrozenDateTimeFactory
3737from homeassistant .core import HomeAssistant
3838from homeassistant .setup import async_setup_component
3939
40- from tests .common import Mock , MockConfigEntry
40+ from tests .common import MockConfigEntry
4141from tests .typing import ClientSessionGenerator , WebSocketGenerator
4242
4343
@@ -353,10 +353,16 @@ async def test_stream_source(
353353 stream_source = await async_get_stream_source (hass , "camera.config_test" )
354354 assert stream_source == "http://barney:[email protected] /5a" 355355
356+ # Create a mock stream that doesn't actually try to connect
357+ mock_stream = Mock ()
358+ mock_stream .add_provider = Mock ()
359+ mock_stream .start = AsyncMock ()
360+ mock_stream .endpoint_url = Mock (return_value = "http://home.assistant/playlist.m3u8" )
361+
356362 with patch (
357- "homeassistant.components.camera.Stream.endpoint_url " ,
358- return_value = "http://home.assistant/playlist.m3u8" ,
359- ) as mock_stream_url :
363+ "homeassistant.components.camera.create_stream " ,
364+ return_value = mock_stream ,
365+ ):
360366 # Request playlist through WebSocket
361367 client = await hass_ws_client (hass )
362368
@@ -366,7 +372,7 @@ async def test_stream_source(
366372 msg = await client .receive_json ()
367373
368374 # Assert WebSocket response
369- assert mock_stream_url .call_count == 1
375+ assert mock_stream . endpoint_url .call_count == 1
370376 assert msg ["id" ] == 1
371377 assert msg ["type" ] == TYPE_RESULT
372378 assert msg ["success" ]
0 commit comments