Keep responding state on wake word start (#138244)

* Keep responding state on wake word start

* Add comment
This commit is contained in:
Michael Hansen 2025-02-11 10:21:41 -06:00 committed by GitHub
parent 7f376ff004
commit 6226542e4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 1 deletions

View File

@ -405,7 +405,10 @@ class AssistSatelliteEntity(entity.Entity):
def _internal_on_pipeline_event(self, event: PipelineEvent) -> None:
"""Set state based on pipeline stage."""
if event.type is PipelineEventType.WAKE_WORD_START:
self._set_state(AssistSatelliteState.IDLE)
# Only return to idle if we're not currently responding.
# The state will return to idle in tts_response_finished.
if self.state != AssistSatelliteState.RESPONDING:
self._set_state(AssistSatelliteState.IDLE)
elif event.type is PipelineEventType.STT_START:
self._set_state(AssistSatelliteState.LISTENING)
elif event.type is PipelineEventType.INTENT_START:

View File

@ -590,3 +590,54 @@ async def test_start_conversation_reject_builtin_agent(
target={"entity_id": "assist_satellite.test_entity"},
blocking=True,
)
async def test_wake_word_start_keeps_responding(
hass: HomeAssistant, init_components: ConfigEntry, entity: MockAssistSatellite
) -> None:
"""Test entity state stays responding on wake word start event."""
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.state == AssistSatelliteState.IDLE
# Get into responding state
audio_stream = object()
with patch(
"homeassistant.components.assist_satellite.entity.async_pipeline_from_audio_stream"
) as mock_start_pipeline:
await entity.async_accept_pipeline_from_satellite(
audio_stream, start_stage=PipelineStage.TTS
)
assert mock_start_pipeline.called
kwargs = mock_start_pipeline.call_args[1]
event_callback = kwargs["event_callback"]
event_callback(PipelineEvent(PipelineEventType.TTS_START, {}))
state = hass.states.get(ENTITY_ID)
assert state.state == AssistSatelliteState.RESPONDING
# Verify that starting a new wake word stream keeps the state
audio_stream = object()
with patch(
"homeassistant.components.assist_satellite.entity.async_pipeline_from_audio_stream"
) as mock_start_pipeline:
await entity.async_accept_pipeline_from_satellite(
audio_stream, start_stage=PipelineStage.WAKE_WORD
)
assert mock_start_pipeline.called
kwargs = mock_start_pipeline.call_args[1]
event_callback = kwargs["event_callback"]
event_callback(PipelineEvent(PipelineEventType.WAKE_WORD_START, {}))
state = hass.states.get(ENTITY_ID)
assert state.state == AssistSatelliteState.RESPONDING
# Only return to idle once TTS is finished
entity.tts_response_finished()
state = hass.states.get(ENTITY_ID)
assert state.state == AssistSatelliteState.IDLE