ESPHome: dont send error when wake word is aborted (#101032)

* ESPHome dont send error when wake word is aborted

* Add test
This commit is contained in:
Jesse Hills 2023-09-28 16:39:57 +13:00 committed by Franck Nijhof
parent 5bd306392f
commit ffad30734b
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 34 additions and 3 deletions

View File

@ -24,7 +24,10 @@ from homeassistant.components.assist_pipeline import (
async_pipeline_from_audio_stream,
select as pipeline_select,
)
from homeassistant.components.assist_pipeline.error import WakeWordDetectionError
from homeassistant.components.assist_pipeline.error import (
WakeWordDetectionAborted,
WakeWordDetectionError,
)
from homeassistant.components.media_player import async_process_play_media_url
from homeassistant.core import Context, HomeAssistant, callback
@ -273,6 +276,8 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
},
)
_LOGGER.warning("Pipeline not found")
except WakeWordDetectionAborted:
pass # Wake word detection was aborted and `handle_finished` is enough.
except WakeWordDetectionError as e:
self.handle_event(
VoiceAssistantEventType.VOICE_ASSISTANT_ERROR,
@ -281,7 +286,6 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
"message": e.message,
},
)
_LOGGER.warning("No Wake word provider found")
finally:
self.handle_finished()

View File

@ -12,7 +12,10 @@ from homeassistant.components.assist_pipeline import (
PipelineEventType,
PipelineStage,
)
from homeassistant.components.assist_pipeline.error import WakeWordDetectionError
from homeassistant.components.assist_pipeline.error import (
WakeWordDetectionAborted,
WakeWordDetectionError,
)
from homeassistant.components.esphome import DomainData
from homeassistant.components.esphome.voice_assistant import VoiceAssistantUDPServer
from homeassistant.core import HomeAssistant
@ -411,3 +414,27 @@ async def test_wake_word_exception(
conversation_id=None,
flags=2,
)
async def test_wake_word_abort_exception(
hass: HomeAssistant,
voice_assistant_udp_server_v2: VoiceAssistantUDPServer,
) -> None:
"""Test that the pipeline is set to start with Wake word."""
async def async_pipeline_from_audio_stream(*args, **kwargs):
raise WakeWordDetectionAborted
with patch(
"homeassistant.components.esphome.voice_assistant.async_pipeline_from_audio_stream",
new=async_pipeline_from_audio_stream,
), patch.object(voice_assistant_udp_server_v2, "handle_event") as mock_handle_event:
voice_assistant_udp_server_v2.transport = Mock()
await voice_assistant_udp_server_v2.run_pipeline(
device_id="mock-device-id",
conversation_id=None,
flags=2,
)
mock_handle_event.assert_not_called()