mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 00:27:19 +00:00
Clean up more
This commit is contained in:
parent
3b1b33d7f2
commit
f8a496dff2
@ -20,9 +20,6 @@ import hass_nabucasa
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import conversation, stt, tts, wake_word, websocket_api
|
||||
from homeassistant.components.tts import (
|
||||
generate_media_source_id as tts_generate_media_source_id,
|
||||
)
|
||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES, MATCH_ALL
|
||||
from homeassistant.core import Context, HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@ -1276,26 +1273,9 @@ class PipelineRun:
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
# Synthesize audio and get URL
|
||||
tts_media_id = tts_generate_media_source_id(
|
||||
self.hass,
|
||||
tts_input,
|
||||
engine=self.tts_stream.engine,
|
||||
language=self.tts_stream.language,
|
||||
options=self.tts_stream.options,
|
||||
)
|
||||
except Exception as src_error:
|
||||
_LOGGER.exception("Unexpected error during text-to-speech")
|
||||
raise TextToSpeechError(
|
||||
code="tts-failed",
|
||||
message="Unexpected error during text-to-speech",
|
||||
) from src_error
|
||||
|
||||
self.tts_stream.async_set_message(tts_input)
|
||||
|
||||
tts_output = {
|
||||
"media_id": tts_media_id,
|
||||
"token": self.tts_stream.token,
|
||||
"url": self.tts_stream.url,
|
||||
"mime_type": self.tts_stream.content_type,
|
||||
|
@ -92,9 +92,6 @@ class AssistSatelliteAnnouncement:
|
||||
media_id: str
|
||||
"""Media ID to be played."""
|
||||
|
||||
original_media_id: str
|
||||
"""The raw media ID before processing."""
|
||||
|
||||
tts_token: str | None
|
||||
"""The TTS token of the media."""
|
||||
|
||||
@ -501,9 +498,7 @@ class AssistSatelliteEntity(entity.Entity):
|
||||
media_id_source: Literal["url", "media_id", "tts"] | None = None
|
||||
tts_token: str | None = None
|
||||
|
||||
if media_id:
|
||||
original_media_id = media_id
|
||||
else:
|
||||
if not media_id:
|
||||
media_id_source = "tts"
|
||||
# Synthesize audio and get URL
|
||||
pipeline_id = self._resolve_pipeline()
|
||||
@ -530,13 +525,6 @@ class AssistSatelliteEntity(entity.Entity):
|
||||
|
||||
tts_token = stream.token
|
||||
media_id = stream.url
|
||||
original_media_id = tts.generate_media_source_id(
|
||||
self.hass,
|
||||
message,
|
||||
engine=engine,
|
||||
language=pipeline.tts_language,
|
||||
options=tts_options,
|
||||
)
|
||||
|
||||
if media_source.is_media_source_id(media_id):
|
||||
if not media_id_source:
|
||||
@ -572,7 +560,6 @@ class AssistSatelliteEntity(entity.Entity):
|
||||
return AssistSatelliteAnnouncement(
|
||||
message=message,
|
||||
media_id=media_id,
|
||||
original_media_id=original_media_id,
|
||||
tts_token=tts_token,
|
||||
media_id_source=media_id_source,
|
||||
preannounce_media_id=preannounce_media_id,
|
||||
|
@ -63,7 +63,6 @@ from .const import (
|
||||
from .entity import TextToSpeechEntity, TTSAudioRequest
|
||||
from .helper import get_engine_instance
|
||||
from .legacy import PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, Provider, async_setup_legacy
|
||||
from .media_source import generate_media_source_id
|
||||
from .models import Voice
|
||||
|
||||
__all__ = [
|
||||
@ -83,7 +82,6 @@ __all__ = [
|
||||
"TtsAudioType",
|
||||
"Voice",
|
||||
"async_default_engine",
|
||||
"generate_media_source_id",
|
||||
]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -190,7 +190,6 @@ async def test_new_pipeline_cancels_pipeline(
|
||||
AssistSatelliteAnnouncement(
|
||||
message="Hello",
|
||||
media_id="http://10.10.10.10:8123/api/tts_proxy/test-token",
|
||||
original_media_id="media-source://bla",
|
||||
tts_token="test-token",
|
||||
media_id_source="tts",
|
||||
),
|
||||
@ -204,7 +203,6 @@ async def test_new_pipeline_cancels_pipeline(
|
||||
AssistSatelliteAnnouncement(
|
||||
message="Hello",
|
||||
media_id="https://www.home-assistant.io/resolved.mp3",
|
||||
original_media_id="media-source://given",
|
||||
tts_token=None,
|
||||
media_id_source="media_id",
|
||||
),
|
||||
@ -214,7 +212,6 @@ async def test_new_pipeline_cancels_pipeline(
|
||||
AssistSatelliteAnnouncement(
|
||||
message="",
|
||||
media_id="http://example.com/bla.mp3",
|
||||
original_media_id="http://example.com/bla.mp3",
|
||||
tts_token=None,
|
||||
media_id_source="url",
|
||||
),
|
||||
@ -227,7 +224,6 @@ async def test_new_pipeline_cancels_pipeline(
|
||||
AssistSatelliteAnnouncement(
|
||||
message="",
|
||||
media_id="http://example.com/bla.mp3",
|
||||
original_media_id="http://example.com/bla.mp3",
|
||||
tts_token=None,
|
||||
media_id_source="url",
|
||||
preannounce_media_id="http://example.com/preannounce.mp3",
|
||||
@ -250,23 +246,7 @@ async def test_announce(
|
||||
assert entity.state == AssistSatelliteState.RESPONDING
|
||||
await original_announce(announcement)
|
||||
|
||||
def tts_generate_media_source_id(
|
||||
hass: HomeAssistant,
|
||||
message: str,
|
||||
engine: str | None = None,
|
||||
language: str | None = None,
|
||||
options: dict | None = None,
|
||||
cache: bool | None = None,
|
||||
):
|
||||
# Check that TTS options are passed here
|
||||
assert options == {"test-option": "test-value", "voice": "test-voice"}
|
||||
return "media-source://bla"
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
new=tts_generate_media_source_id,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="tts.cloud",
|
||||
@ -550,7 +530,6 @@ async def test_vad_sensitivity_entity_not_found(
|
||||
message="Hello",
|
||||
media_id="http://10.10.10.10:8123/api/tts_proxy/test-token",
|
||||
tts_token="test-token",
|
||||
original_media_id="media-source://generated",
|
||||
media_id_source="tts",
|
||||
),
|
||||
),
|
||||
@ -568,7 +547,6 @@ async def test_vad_sensitivity_entity_not_found(
|
||||
message="Hello",
|
||||
media_id="https://www.home-assistant.io/resolved.mp3",
|
||||
tts_token=None,
|
||||
original_media_id="media-source://given",
|
||||
media_id_source="media_id",
|
||||
),
|
||||
),
|
||||
@ -585,7 +563,6 @@ async def test_vad_sensitivity_entity_not_found(
|
||||
message="",
|
||||
media_id="http://example.com/given.mp3",
|
||||
tts_token=None,
|
||||
original_media_id="http://example.com/given.mp3",
|
||||
media_id_source="url",
|
||||
),
|
||||
),
|
||||
@ -602,7 +579,6 @@ async def test_vad_sensitivity_entity_not_found(
|
||||
message="",
|
||||
media_id="http://example.com/given.mp3",
|
||||
tts_token=None,
|
||||
original_media_id="http://example.com/given.mp3",
|
||||
media_id_source="url",
|
||||
preannounce_media_id="http://example.com/preannounce.mp3",
|
||||
),
|
||||
@ -633,10 +609,6 @@ async def test_start_conversation(
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://generated",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="tts.cloud",
|
||||
|
@ -19,10 +19,6 @@ async def mock_tts(hass: HomeAssistant):
|
||||
"""Mock TTS service."""
|
||||
assert await async_setup_component(hass, "tts", {})
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://bla",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_create_stream",
|
||||
return_value=MockResultStream(hass, "wav", b""),
|
||||
|
@ -1196,10 +1196,6 @@ async def test_announce_message(
|
||||
done.set()
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://bla",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="tts.cloud_tts",
|
||||
@ -1373,10 +1369,6 @@ async def test_announce_message_with_preannounce(
|
||||
done.set()
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://bla",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="tts.cloud_tts",
|
||||
@ -1493,10 +1485,6 @@ async def test_start_conversation_message(
|
||||
done.set()
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://bla",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="tts.cloud_tts",
|
||||
@ -1708,10 +1696,6 @@ async def test_start_conversation_message_with_preannounce(
|
||||
done.set()
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://bla",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="tts.cloud_tts",
|
||||
|
@ -18,6 +18,7 @@ from homeassistant.components.media_player import (
|
||||
SERVICE_PLAY_MEDIA,
|
||||
MediaType,
|
||||
)
|
||||
from homeassistant.components.tts.media_source import generate_media_source_id
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -1315,7 +1316,7 @@ async def test_generate_media_source_id(
|
||||
result_query: str,
|
||||
) -> None:
|
||||
"""Test generating a media source ID."""
|
||||
media_source_id = tts.generate_media_source_id(
|
||||
media_source_id = generate_media_source_id(
|
||||
hass, "msg", engine, language, options, cache
|
||||
)
|
||||
|
||||
@ -1353,7 +1354,7 @@ async def test_generate_media_source_id_invalid_options(
|
||||
) -> None:
|
||||
"""Test generating a media source ID."""
|
||||
with pytest.raises(HomeAssistantError):
|
||||
tts.generate_media_source_id(hass, "msg", engine, language, options, None)
|
||||
generate_media_source_id(hass, "msg", engine, language, options, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -1405,7 +1406,7 @@ async def test_legacy_fetching_in_async(
|
||||
await mock_setup(hass, ProviderWithAsyncFetching(DEFAULT_LANG))
|
||||
|
||||
# Test async_get_media_source_audio
|
||||
media_source_id = tts.generate_media_source_id(
|
||||
media_source_id = generate_media_source_id(
|
||||
hass,
|
||||
"test message",
|
||||
"test",
|
||||
@ -1435,7 +1436,7 @@ async def test_legacy_fetching_in_async(
|
||||
assert await req.read() == b"test"
|
||||
|
||||
# Test error is not cached
|
||||
media_source_id = tts.generate_media_source_id(
|
||||
media_source_id = generate_media_source_id(
|
||||
hass, "test message 2", "test", "en_US", None, None
|
||||
)
|
||||
tts_audio = asyncio.Future()
|
||||
@ -1468,7 +1469,7 @@ async def test_fetching_in_async(
|
||||
await mock_config_entry_setup(hass, EntityWithAsyncFetching(DEFAULT_LANG))
|
||||
|
||||
# Test async_get_media_source_audio
|
||||
media_source_id = tts.generate_media_source_id(
|
||||
media_source_id = generate_media_source_id(
|
||||
hass,
|
||||
"test message",
|
||||
"tts.test",
|
||||
@ -1498,7 +1499,7 @@ async def test_fetching_in_async(
|
||||
assert await req.read() == b"test"
|
||||
|
||||
# Test error is not cached
|
||||
media_source_id = tts.generate_media_source_id(
|
||||
media_source_id = generate_media_source_id(
|
||||
hass, "test message 2", "tts.test", "en_US", None, None
|
||||
)
|
||||
tts_audio = asyncio.Future()
|
||||
|
@ -832,7 +832,6 @@ async def test_announce(
|
||||
message="test announcement",
|
||||
media_id=_MEDIA_ID,
|
||||
tts_token=mock_tts_result_stream.token,
|
||||
original_media_id=_MEDIA_ID,
|
||||
media_id_source="tts",
|
||||
)
|
||||
|
||||
@ -883,7 +882,6 @@ async def test_voip_id_is_ip_address(
|
||||
message="test announcement",
|
||||
media_id=_MEDIA_ID,
|
||||
tts_token=mock_tts_result_stream.token,
|
||||
original_media_id=_MEDIA_ID,
|
||||
media_id_source="tts",
|
||||
)
|
||||
|
||||
@ -939,7 +937,6 @@ async def test_announce_timeout(
|
||||
message="test announcement",
|
||||
media_id=_MEDIA_ID,
|
||||
tts_token=mock_tts_result_stream.token,
|
||||
original_media_id=_MEDIA_ID,
|
||||
media_id_source="tts",
|
||||
)
|
||||
|
||||
@ -981,7 +978,6 @@ async def test_start_conversation(
|
||||
message="test announcement",
|
||||
media_id=_MEDIA_ID,
|
||||
tts_token=mock_tts_result_stream.token,
|
||||
original_media_id=_MEDIA_ID,
|
||||
media_id_source="tts",
|
||||
)
|
||||
|
||||
@ -1125,10 +1121,6 @@ async def test_start_conversation_user_doesnt_pick_up(
|
||||
"homeassistant.components.assist_satellite.entity.async_pipeline_from_audio_stream",
|
||||
new=async_pipeline_from_audio_stream,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.generate_media_source_id",
|
||||
return_value="media-source://bla",
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.tts.async_resolve_engine",
|
||||
return_value="test tts",
|
||||
|
@ -11,6 +11,9 @@ from syrupy import SnapshotAssertion
|
||||
from wyoming.audio import AudioChunk, AudioStop
|
||||
|
||||
from homeassistant.components import tts, wyoming
|
||||
|
||||
# pylint: disable=hass-component-root-import
|
||||
from homeassistant.components.tts.media_source import generate_media_source_id
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_component import DATA_INSTANCES
|
||||
@ -63,7 +66,7 @@ async def test_get_tts_audio(
|
||||
) as mock_client:
|
||||
extension, data = await async_get_media_source_audio(
|
||||
hass,
|
||||
tts.generate_media_source_id(
|
||||
generate_media_source_id(
|
||||
hass,
|
||||
"Hello world",
|
||||
"tts.test_tts",
|
||||
@ -100,7 +103,7 @@ async def test_get_tts_audio_different_formats(
|
||||
) as mock_client:
|
||||
extension, data = await async_get_media_source_audio(
|
||||
hass,
|
||||
tts.generate_media_source_id(
|
||||
generate_media_source_id(
|
||||
hass,
|
||||
"Hello world",
|
||||
"tts.test_tts",
|
||||
@ -134,7 +137,7 @@ async def test_get_tts_audio_different_formats(
|
||||
) as mock_client:
|
||||
extension, data = await async_get_media_source_audio(
|
||||
hass,
|
||||
tts.generate_media_source_id(
|
||||
generate_media_source_id(
|
||||
hass,
|
||||
"Hello world",
|
||||
"tts.test_tts",
|
||||
@ -186,7 +189,7 @@ async def test_get_tts_audio_audio_oserror(
|
||||
):
|
||||
await async_get_media_source_audio(
|
||||
hass,
|
||||
tts.generate_media_source_id(
|
||||
generate_media_source_id(
|
||||
hass, "Hello world", "tts.test_tts", hass.config.language
|
||||
),
|
||||
)
|
||||
@ -208,7 +211,7 @@ async def test_voice_speaker(
|
||||
) as mock_client:
|
||||
await async_get_media_source_audio(
|
||||
hass,
|
||||
tts.generate_media_source_id(
|
||||
generate_media_source_id(
|
||||
hass,
|
||||
"Hello world",
|
||||
"tts.test_tts",
|
||||
|
Loading…
x
Reference in New Issue
Block a user