diff --git a/homeassistant/components/assist_pipeline/pipeline.py b/homeassistant/components/assist_pipeline/pipeline.py index 87fd9be0c42..d347e433f46 100644 --- a/homeassistant/components/assist_pipeline/pipeline.py +++ b/homeassistant/components/assist_pipeline/pipeline.py @@ -370,7 +370,7 @@ class PipelineRun: def start(self) -> None: """Emit run start event.""" data = { - "pipeline": self.pipeline.name, + "pipeline": self.pipeline.id, "language": self.language, } if self.runner_data is not None: diff --git a/tests/components/assist_pipeline/__init__.py b/tests/components/assist_pipeline/__init__.py index 7400fe32d70..40aa48fbc54 100644 --- a/tests/components/assist_pipeline/__init__.py +++ b/tests/components/assist_pipeline/__init__.py @@ -1,5 +1,4 @@ """Tests for the Voice Assistant integration.""" - MANY_LANGUAGES = [ "ar", "bg", diff --git a/tests/components/assist_pipeline/snapshots/test_init.ambr b/tests/components/assist_pipeline/snapshots/test_init.ambr index 5191e948c38..619c59606ed 100644 --- a/tests/components/assist_pipeline/snapshots/test_init.ambr +++ b/tests/components/assist_pipeline/snapshots/test_init.ambr @@ -4,7 +4,7 @@ dict({ 'data': dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , }), 'type': , }), @@ -91,7 +91,7 @@ dict({ 'data': dict({ 'language': 'en', - 'pipeline': 'test_name', + 'pipeline': , }), 'type': , }), @@ -178,7 +178,7 @@ dict({ 'data': dict({ 'language': 'en', - 'pipeline': 'test_name', + 'pipeline': , }), 'type': , }), diff --git a/tests/components/assist_pipeline/snapshots/test_websocket.ambr b/tests/components/assist_pipeline/snapshots/test_websocket.ambr index f5a0a6dad92..a2e5ac72b07 100644 --- a/tests/components/assist_pipeline/snapshots/test_websocket.ambr +++ b/tests/components/assist_pipeline/snapshots/test_websocket.ambr @@ -2,7 +2,7 @@ # name: test_audio_pipeline dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': 1, 'timeout': 30, @@ -78,7 +78,7 @@ # name: test_audio_pipeline_debug dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': 1, 'timeout': 30, @@ -154,7 +154,7 @@ # name: test_intent_failed dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': None, 'timeout': 30, @@ -171,7 +171,7 @@ # name: test_intent_timeout dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': None, 'timeout': 0.1, @@ -217,7 +217,7 @@ # name: test_stt_stream_failed dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': 1, 'timeout': 30, @@ -240,7 +240,7 @@ # name: test_text_only_pipeline dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': None, 'timeout': 30, @@ -285,7 +285,7 @@ # name: test_tts_failed dict({ 'language': 'en', - 'pipeline': 'Home Assistant', + 'pipeline': , 'runner_data': dict({ 'stt_binary_handler_id': None, 'timeout': 30, diff --git a/tests/components/assist_pipeline/test_init.py b/tests/components/assist_pipeline/test_init.py index 6dd04c37e39..6fb6bf61d96 100644 --- a/tests/components/assist_pipeline/test_init.py +++ b/tests/components/assist_pipeline/test_init.py @@ -1,5 +1,6 @@ """Test Voice Assistant init.""" from dataclasses import asdict +from unittest.mock import ANY import pytest from syrupy.assertion import SnapshotAssertion @@ -12,6 +13,19 @@ from .conftest import MockSttProvider, MockSttProviderEntity from tests.typing import WebSocketGenerator +def process_events(events: list[assist_pipeline.PipelineEvent]) -> list[dict]: + """Process events to remove dynamic values.""" + processed = [] + for event in events: + as_dict = asdict(event) + as_dict.pop("timestamp") + if as_dict["type"] == assist_pipeline.PipelineEventType.RUN_START: + as_dict["data"]["pipeline"] = ANY + processed.append(as_dict) + + return processed + + async def test_pipeline_from_audio_stream_auto( hass: HomeAssistant, mock_stt_provider: MockSttProvider, @@ -45,13 +59,7 @@ async def test_pipeline_from_audio_stream_auto( audio_data(), ) - processed = [] - for event in events: - as_dict = asdict(event) - as_dict.pop("timestamp") - processed.append(as_dict) - - assert processed == snapshot + assert process_events(events) == snapshot assert mock_stt_provider.received == [b"part1", b"part2"] @@ -111,13 +119,7 @@ async def test_pipeline_from_audio_stream_legacy( pipeline_id=pipeline_id, ) - processed = [] - for event in events: - as_dict = asdict(event) - as_dict.pop("timestamp") - processed.append(as_dict) - - assert processed == snapshot + assert process_events(events) == snapshot assert mock_stt_provider.received == [b"part1", b"part2"] @@ -177,13 +179,7 @@ async def test_pipeline_from_audio_stream_entity( pipeline_id=pipeline_id, ) - processed = [] - for event in events: - as_dict = asdict(event) - as_dict.pop("timestamp") - processed.append(as_dict) - - assert processed == snapshot + assert process_events(events) == snapshot assert mock_stt_provider_entity.received == [b"part1", b"part2"] diff --git a/tests/components/assist_pipeline/test_websocket.py b/tests/components/assist_pipeline/test_websocket.py index 827d7b85113..c71d0526fe6 100644 --- a/tests/components/assist_pipeline/test_websocket.py +++ b/tests/components/assist_pipeline/test_websocket.py @@ -1,6 +1,6 @@ """Websocket tests for Voice Assistant integration.""" import asyncio -from unittest.mock import ANY, MagicMock, patch +from unittest.mock import ANY, patch from syrupy.assertion import SnapshotAssertion @@ -37,6 +37,7 @@ async def test_text_only_pipeline( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"]) @@ -101,6 +102,7 @@ async def test_audio_pipeline( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"]) @@ -196,6 +198,7 @@ async def test_intent_timeout( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"]) @@ -292,7 +295,7 @@ async def test_intent_failed( with patch( "homeassistant.components.conversation.async_converse", - new=MagicMock(return_value=RuntimeError), + side_effect=RuntimeError, ): await client.send_json_auto_id( { @@ -310,6 +313,7 @@ async def test_intent_failed( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"]) @@ -405,7 +409,7 @@ async def test_stt_provider_missing( """Test events from a pipeline run with a non-existent STT provider.""" with patch( "homeassistant.components.stt.async_get_provider", - new=MagicMock(return_value=None), + return_value=None, ): client = await hass_ws_client(hass) @@ -438,7 +442,7 @@ async def test_stt_stream_failed( with patch( "tests.components.assist_pipeline.conftest.MockSttProvider.async_process_audio_stream", - new=MagicMock(side_effect=RuntimeError), + side_effect=RuntimeError, ): await client.send_json_auto_id( { @@ -458,6 +462,7 @@ async def test_stt_stream_failed( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"]) @@ -504,7 +509,7 @@ async def test_tts_failed( with patch( "homeassistant.components.media_source.async_resolve_media", - new=MagicMock(return_value=RuntimeError), + side_effect=RuntimeError, ): await client.send_json_auto_id( { @@ -522,6 +527,7 @@ async def test_tts_failed( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"]) @@ -1105,6 +1111,7 @@ async def test_audio_pipeline_debug( # run start msg = await client.receive_json() assert msg["event"]["type"] == "run-start" + msg["event"]["data"]["pipeline"] = ANY assert msg["event"]["data"] == snapshot events.append(msg["event"])