mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Pass ESPHome device audio settings to the pipeline (#190096)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1ada6e10ae
commit
fae4dc0d35
@@ -4,7 +4,7 @@ from abc import abstractmethod
|
||||
import asyncio
|
||||
from collections.abc import AsyncIterable
|
||||
import contextlib
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses import dataclass, field, replace
|
||||
from enum import StrEnum
|
||||
import logging
|
||||
from typing import Any, Literal, final, override
|
||||
@@ -448,8 +448,13 @@ class AssistSatelliteEntity(entity.Entity):
|
||||
wake_word_phrase: str | None = None,
|
||||
*,
|
||||
context: Context | None = None,
|
||||
audio_settings: AudioSettings | None = None,
|
||||
) -> None:
|
||||
"""Triggers an Assist pipeline in Home Assistant from a satellite."""
|
||||
"""Triggers an Assist pipeline in Home Assistant from a satellite.
|
||||
|
||||
silence_seconds in audio_settings is always taken from the satellite's
|
||||
VAD sensitivity.
|
||||
"""
|
||||
await self._cancel_running_pipeline()
|
||||
|
||||
# Consume system prompt in first pipeline
|
||||
@@ -528,8 +533,9 @@ class AssistSatelliteEntity(entity.Entity):
|
||||
satellite_id=self.entity_id,
|
||||
tts_audio_output=self.tts_options,
|
||||
wake_word_phrase=wake_word_phrase,
|
||||
audio_settings=AudioSettings(
|
||||
silence_seconds=self._resolve_vad_sensitivity()
|
||||
audio_settings=replace(
|
||||
audio_settings or AudioSettings(),
|
||||
silence_seconds=self._resolve_vad_sensitivity(),
|
||||
),
|
||||
start_stage=start_stage,
|
||||
end_stage=end_stage,
|
||||
|
||||
@@ -27,6 +27,7 @@ from probatio.humanize import humanize_error
|
||||
|
||||
from homeassistant.components import assist_satellite, tts
|
||||
from homeassistant.components.assist_pipeline import (
|
||||
AudioSettings,
|
||||
PipelineEvent,
|
||||
PipelineEventType,
|
||||
PipelineStage,
|
||||
@@ -609,6 +610,11 @@ class EsphomeAssistSatellite(
|
||||
start_stage=start_stage,
|
||||
end_stage=end_stage,
|
||||
wake_word_phrase=wake_word_phrase,
|
||||
audio_settings=AudioSettings(
|
||||
noise_suppression_level=audio_settings.noise_suppression_level,
|
||||
auto_gain_dbfs=audio_settings.auto_gain,
|
||||
volume_multiplier=audio_settings.volume_multiplier,
|
||||
),
|
||||
),
|
||||
"esphome_assist_satellite_pipeline",
|
||||
)
|
||||
|
||||
@@ -594,6 +594,34 @@ async def test_vad_sensitivity_entity(
|
||||
await done.wait()
|
||||
|
||||
|
||||
async def test_audio_settings_from_satellite(
|
||||
hass: HomeAssistant, init_components: ConfigEntry, entity: MockAssistSatellite
|
||||
) -> None:
|
||||
"""Test audio settings from the satellite are passed to the pipeline."""
|
||||
with patch(
|
||||
"homeassistant.components.assist_satellite.entity.async_pipeline_from_audio_stream"
|
||||
) as mock_start_pipeline:
|
||||
await entity.async_accept_pipeline_from_satellite(
|
||||
object(),
|
||||
audio_settings=AudioSettings(
|
||||
noise_suppression_level=2,
|
||||
auto_gain_dbfs=15,
|
||||
volume_multiplier=1.5,
|
||||
is_vad_enabled=False,
|
||||
silence_seconds=10.0,
|
||||
),
|
||||
)
|
||||
|
||||
# silence_seconds comes from the satellite's VAD sensitivity instead
|
||||
assert mock_start_pipeline.call_args.kwargs["audio_settings"] == AudioSettings(
|
||||
noise_suppression_level=2,
|
||||
auto_gain_dbfs=15,
|
||||
volume_multiplier=1.5,
|
||||
is_vad_enabled=False,
|
||||
silence_seconds=vad.VadSensitivity.to_seconds(vad.VadSensitivity.DEFAULT),
|
||||
)
|
||||
|
||||
|
||||
async def test_pipeline_entity_not_found(
|
||||
hass: HomeAssistant, init_components: ConfigEntry, entity: MockAssistSatellite
|
||||
) -> None:
|
||||
|
||||
@@ -25,7 +25,12 @@ import pytest
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
|
||||
from homeassistant.components import assist_pipeline, assist_satellite, conversation
|
||||
from homeassistant.components.assist_pipeline import PipelineEvent, PipelineEventType
|
||||
from homeassistant.components.assist_pipeline import (
|
||||
AudioSettings,
|
||||
PipelineEvent,
|
||||
PipelineEventType,
|
||||
VadSensitivity,
|
||||
)
|
||||
from homeassistant.components.assist_pipeline.pipeline import KEY_ASSIST_PIPELINE # pylint: disable=home-assistant-component-root-import
|
||||
from homeassistant.components.assist_satellite import (
|
||||
AssistSatelliteConfiguration,
|
||||
@@ -1110,6 +1115,47 @@ async def test_tts_partial_format_from_media_player(
|
||||
assert kwargs.get("tts_audio_output") == tts_audio_output
|
||||
|
||||
|
||||
async def test_pipeline_audio_settings(
|
||||
hass: HomeAssistant,
|
||||
mock_client: APIClient,
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""Test audio settings from the device are passed to the pipeline."""
|
||||
mock_device = await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
device_info={
|
||||
"voice_assistant_feature_flags": VoiceAssistantFeature.VOICE_ASSISTANT
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
satellite = get_satellite_entity(hass, mock_device.device_info.mac_address)
|
||||
assert satellite is not None
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.assist_satellite.entity.async_pipeline_from_audio_stream",
|
||||
) as mock_pipeline_from_audio_stream:
|
||||
await satellite.handle_pipeline_start(
|
||||
conversation_id="",
|
||||
flags=0,
|
||||
audio_settings=VoiceAssistantAudioSettings(
|
||||
noise_suppression_level=3, auto_gain=20, volume_multiplier=2.0
|
||||
),
|
||||
wake_word_phrase=None,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_pipeline_from_audio_stream.assert_called_once()
|
||||
assert mock_pipeline_from_audio_stream.call_args.kwargs[
|
||||
"audio_settings"
|
||||
] == AudioSettings(
|
||||
noise_suppression_level=3,
|
||||
auto_gain_dbfs=20,
|
||||
volume_multiplier=2.0,
|
||||
silence_seconds=VadSensitivity.to_seconds(VadSensitivity.DEFAULT),
|
||||
)
|
||||
|
||||
|
||||
async def test_announce_message(
|
||||
hass: HomeAssistant,
|
||||
mock_client: APIClient,
|
||||
|
||||
Reference in New Issue
Block a user