Wait for client to be created in wyoming tests (#110751)

* Add missing async_block_till_done in wyoming tests

* better fix

* better fix

* better fix

* better fix
pull/110760/head
J. Nick Koston 2024-02-16 15:48:47 -06:00 committed by GitHub
parent 58a6f26f66
commit 5adb9240c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 5 deletions

View File

@ -603,18 +603,25 @@ async def test_satellite_error_during_pipeline(hass: HomeAssistant) -> None:
).event(),
] # no audio chunks after RunPipeline
client_created_event = asyncio.Event()
mock_client = SatelliteAsyncTcpClient(events)
def _async_make_tcp_client(*args: Any, **kwargs: Any) -> SatelliteAsyncTcpClient:
client_created_event.set()
return mock_client
with patch(
"homeassistant.components.wyoming.data.load_wyoming_info",
return_value=SATELLITE_INFO,
), patch(
"homeassistant.components.wyoming.satellite.AsyncTcpClient",
SatelliteAsyncTcpClient(events),
) as mock_client, patch(
_async_make_tcp_client,
), patch(
"homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream",
) as mock_run_pipeline:
await setup_config_entry(hass)
async with asyncio.timeout(1):
await client_created_event.wait()
await mock_client.connect_event.wait()
await mock_client.run_satellite_event.wait()
@ -652,13 +659,20 @@ async def test_tts_not_wav(hass: HomeAssistant) -> None:
RunPipeline(start_stage=PipelineStage.TTS, end_stage=PipelineStage.TTS).event(),
]
client_created_event = asyncio.Event()
mock_client = SatelliteAsyncTcpClient(events)
def _async_make_tcp_client(*args: Any, **kwargs: Any) -> SatelliteAsyncTcpClient:
client_created_event.set()
return mock_client
with patch(
"homeassistant.components.wyoming.data.load_wyoming_info",
return_value=SATELLITE_INFO,
), patch(
"homeassistant.components.wyoming.satellite.AsyncTcpClient",
SatelliteAsyncTcpClient(events),
) as mock_client, patch(
_async_make_tcp_client,
), patch(
"homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream",
) as mock_run_pipeline, patch(
"homeassistant.components.wyoming.satellite.tts.async_get_media_source_audio",
@ -669,6 +683,7 @@ async def test_tts_not_wav(hass: HomeAssistant) -> None:
):
entry = await setup_config_entry(hass)
async with asyncio.timeout(1):
await client_created_event.wait()
await mock_client.connect_event.wait()
await mock_client.run_satellite_event.wait()