From d76c5ed351941038898e2c692d59108eda70b282 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 25 Sep 2023 18:58:10 +0200 Subject: [PATCH] Use wake word settings in assist pipeline runs (#100864) --- homeassistant/components/assist_pipeline/pipeline.py | 7 +++++-- homeassistant/components/wake_word/__init__.py | 2 +- tests/components/wake_word/test_init.py | 2 +- tests/components/wyoming/test_wake_word.py | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/assist_pipeline/pipeline.py b/homeassistant/components/assist_pipeline/pipeline.py index 8e297b38797..e3b0eafda20 100644 --- a/homeassistant/components/assist_pipeline/pipeline.py +++ b/homeassistant/components/assist_pipeline/pipeline.py @@ -476,7 +476,9 @@ class PipelineRun: async def prepare_wake_word_detection(self) -> None: """Prepare wake-word-detection.""" - entity_id = wake_word.async_default_entity(self.hass) + entity_id = self.pipeline.wake_word_entity or wake_word.async_default_entity( + self.hass + ) if entity_id is None: raise WakeWordDetectionError( code="wake-engine-missing", @@ -553,7 +555,8 @@ class PipelineRun: audio_stream=stream, stt_audio_buffer=stt_audio_buffer, wake_word_vad=wake_word_vad, - ) + ), + self.pipeline.wake_word_id, ) if stt_audio_buffer is not None: diff --git a/homeassistant/components/wake_word/__init__.py b/homeassistant/components/wake_word/__init__.py index 01344a00952..eeed7b8029b 100644 --- a/homeassistant/components/wake_word/__init__.py +++ b/homeassistant/components/wake_word/__init__.py @@ -96,7 +96,7 @@ class WakeWordDetectionEntity(RestoreEntity): """ async def async_process_audio_stream( - self, stream: AsyncIterable[tuple[bytes, int]], wake_word_id: str | None = None + self, stream: AsyncIterable[tuple[bytes, int]], wake_word_id: str | None ) -> DetectionResult | None: """Try to detect wake word(s) in an audio stream with timestamps. diff --git a/tests/components/wake_word/test_init.py b/tests/components/wake_word/test_init.py index 4123e4a7e47..7f3e8f011ee 100644 --- a/tests/components/wake_word/test_init.py +++ b/tests/components/wake_word/test_init.py @@ -199,7 +199,7 @@ async def test_not_detected_entity( # Need 2 seconds to trigger state = setup.state - result = await setup.async_process_audio_stream(one_second_stream()) + result = await setup.async_process_audio_stream(one_second_stream(), None) assert result is None # State should only change when there's a detection diff --git a/tests/components/wyoming/test_wake_word.py b/tests/components/wyoming/test_wake_word.py index cd156c660a8..4ec471be7fd 100644 --- a/tests/components/wyoming/test_wake_word.py +++ b/tests/components/wyoming/test_wake_word.py @@ -54,7 +54,7 @@ async def test_streaming_audio( "homeassistant.components.wyoming.wake_word.AsyncTcpClient", MockAsyncTcpClient(client_events), ): - result = await entity.async_process_audio_stream(audio_stream()) + result = await entity.async_process_audio_stream(audio_stream(), None) assert result is not None assert result == snapshot @@ -78,7 +78,7 @@ async def test_streaming_audio_connection_lost( "homeassistant.components.wyoming.wake_word.AsyncTcpClient", MockAsyncTcpClient([None]), ): - result = await entity.async_process_audio_stream(audio_stream()) + result = await entity.async_process_audio_stream(audio_stream(), None) assert result is None @@ -103,6 +103,6 @@ async def test_streaming_audio_oserror( "homeassistant.components.wyoming.wake_word.AsyncTcpClient", mock_client, ), patch.object(mock_client, "read_event", side_effect=OSError("Boom!")): - result = await entity.async_process_audio_stream(audio_stream()) + result = await entity.async_process_audio_stream(audio_stream(), None) assert result is None