Skip to content

Commit 19b773d

Browse files
synesthesiambdraco
andauthored
Only send ESPHome intent progress when necessary (home-assistant#147458)
* Only send intent progress when necessary * cover * Fix logic --------- Co-authored-by: J. Nick Koston <[email protected]>
1 parent 9e7c7ec commit 19b773d

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

homeassistant/components/esphome/assist_satellite.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,15 @@ def on_pipeline_event(self, event: PipelineEvent) -> None:
284284
assert event.data is not None
285285
data_to_send = {"text": event.data["stt_output"]["text"]}
286286
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_INTENT_PROGRESS:
287-
data_to_send = {
288-
"tts_start_streaming": "1"
289-
if (event.data and event.data.get("tts_start_streaming"))
290-
else "0",
291-
}
287+
if (
288+
not event.data
289+
or ("tts_start_streaming" not in event.data)
290+
or (not event.data["tts_start_streaming"])
291+
):
292+
# ESPHome only needs to know if early TTS streaming is available
293+
return
294+
295+
data_to_send = {"tts_start_streaming": "1"}
292296
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_INTENT_END:
293297
assert event.data is not None
294298
data_to_send = {

tests/components/esphome/test_assist_satellite.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,78 @@ async def test_get_set_configuration(
17761776
assert satellite.async_get_configuration() == updated_config
17771777

17781778

1779+
async def test_intent_progress_optimization(
1780+
hass: HomeAssistant,
1781+
mock_client: APIClient,
1782+
mock_esphome_device: MockESPHomeDeviceType,
1783+
) -> None:
1784+
"""Test that intent progress events are only sent when early TTS streaming is available."""
1785+
mock_device = await mock_esphome_device(
1786+
mock_client=mock_client,
1787+
device_info={
1788+
"voice_assistant_feature_flags": VoiceAssistantFeature.VOICE_ASSISTANT
1789+
},
1790+
)
1791+
await hass.async_block_till_done()
1792+
1793+
satellite = get_satellite_entity(hass, mock_device.device_info.mac_address)
1794+
assert satellite is not None
1795+
1796+
# Test that intent progress without tts_start_streaming is not sent
1797+
mock_client.send_voice_assistant_event.reset_mock()
1798+
satellite.on_pipeline_event(
1799+
PipelineEvent(
1800+
type=PipelineEventType.INTENT_PROGRESS,
1801+
data={"some_other_key": "value"},
1802+
)
1803+
)
1804+
mock_client.send_voice_assistant_event.assert_not_called()
1805+
1806+
# Test that intent progress with tts_start_streaming=False is not sent
1807+
satellite.on_pipeline_event(
1808+
PipelineEvent(
1809+
type=PipelineEventType.INTENT_PROGRESS,
1810+
data={"tts_start_streaming": False},
1811+
)
1812+
)
1813+
mock_client.send_voice_assistant_event.assert_not_called()
1814+
1815+
# Test that intent progress with tts_start_streaming=True is sent
1816+
satellite.on_pipeline_event(
1817+
PipelineEvent(
1818+
type=PipelineEventType.INTENT_PROGRESS,
1819+
data={"tts_start_streaming": True},
1820+
)
1821+
)
1822+
assert mock_client.send_voice_assistant_event.call_args_list[-1].args == (
1823+
VoiceAssistantEventType.VOICE_ASSISTANT_INTENT_PROGRESS,
1824+
{"tts_start_streaming": "1"},
1825+
)
1826+
1827+
# Test that intent progress with tts_start_streaming as string "1" is sent
1828+
mock_client.send_voice_assistant_event.reset_mock()
1829+
satellite.on_pipeline_event(
1830+
PipelineEvent(
1831+
type=PipelineEventType.INTENT_PROGRESS,
1832+
data={"tts_start_streaming": "1"},
1833+
)
1834+
)
1835+
assert mock_client.send_voice_assistant_event.call_args_list[-1].args == (
1836+
VoiceAssistantEventType.VOICE_ASSISTANT_INTENT_PROGRESS,
1837+
{"tts_start_streaming": "1"},
1838+
)
1839+
1840+
# Test that intent progress with no data is *not* sent
1841+
mock_client.send_voice_assistant_event.reset_mock()
1842+
satellite.on_pipeline_event(
1843+
PipelineEvent(
1844+
type=PipelineEventType.INTENT_PROGRESS,
1845+
data=None,
1846+
)
1847+
)
1848+
mock_client.send_voice_assistant_event.assert_not_called()
1849+
1850+
17791851
async def test_wake_word_select(
17801852
hass: HomeAssistant,
17811853
mock_client: APIClient,

0 commit comments

Comments
 (0)