mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Remove deprecated platform config from cloud TTS (#190138)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
f2922c95ec
commit
37c2f30aa0
@@ -28,10 +28,6 @@
|
||||
"description": "You do not have a connection to Home Assistant Cloud. Check your network.",
|
||||
"title": "No connection"
|
||||
},
|
||||
"deprecated_tts_platform_config": {
|
||||
"description": "The whole `platform: cloud` entry under the `tts:` section in configuration.yaml is deprecated and should be removed. You can use the UI to change settings for the Cloud text-to-speech platform. Please adjust your configuration.yaml and restart Home Assistant to fix this issue.",
|
||||
"title": "The Cloud text-to-speech platform configuration is deprecated"
|
||||
},
|
||||
"legacy_subscription": {
|
||||
"fix_flow": {
|
||||
"abort": {
|
||||
|
||||
@@ -4,15 +4,12 @@ import logging
|
||||
from typing import Any, override
|
||||
|
||||
from hass_nabucasa import Cloud
|
||||
from hass_nabucasa.voice import MAP_VOICE, AudioOutput, VoiceError
|
||||
from hass_nabucasa.voice import AudioOutput, VoiceError
|
||||
from hass_nabucasa.voice_data import TTS_VOICES
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.tts import (
|
||||
ATTR_AUDIO_OUTPUT,
|
||||
ATTR_VOICE,
|
||||
CONF_LANG,
|
||||
PLATFORM_SCHEMA as TTS_PLATFORM_SCHEMA,
|
||||
Provider,
|
||||
TextToSpeechEntity,
|
||||
TTSAudioRequest,
|
||||
@@ -21,11 +18,9 @@ from homeassistant.components.tts import (
|
||||
Voice,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PLATFORM, Platform
|
||||
from homeassistant.core import HomeAssistant, async_get_hass, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.setup import async_when_setup
|
||||
|
||||
@@ -34,14 +29,11 @@ from .client import CloudClient
|
||||
from .const import (
|
||||
DATA_CLOUD,
|
||||
DATA_PLATFORMS_SETUP,
|
||||
DOMAIN,
|
||||
TTS_ENTITY_UNIQUE_ID,
|
||||
VOICE_STYLE_SEPERATOR,
|
||||
)
|
||||
from .prefs import CloudPreferences
|
||||
|
||||
ATTR_GENDER = "gender"
|
||||
|
||||
SUPPORT_LANGUAGES = list(TTS_VOICES)
|
||||
|
||||
DEFAULT_VOICES = {
|
||||
@@ -229,67 +221,21 @@ def _prepare_voice_args(
|
||||
}
|
||||
|
||||
|
||||
def _deprecated_platform(value: str) -> str:
|
||||
"""Validate if platform is deprecated."""
|
||||
if value == DOMAIN:
|
||||
_LOGGER.warning(
|
||||
"The cloud tts platform configuration is deprecated, "
|
||||
"please remove it from your configuration "
|
||||
"and use the UI to change settings instead"
|
||||
)
|
||||
hass = async_get_hass()
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"deprecated_tts_platform_config",
|
||||
breaks_in_ha_version="2024.9.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_tts_platform_config",
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
def validate_lang(value: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Validate chosen gender or language."""
|
||||
if (lang := value.get(CONF_LANG)) is None:
|
||||
return value
|
||||
|
||||
if (gender := value.get(ATTR_GENDER)) is None:
|
||||
gender = value[ATTR_GENDER] = next(
|
||||
(chk_gender for chk_lang, chk_gender in MAP_VOICE if chk_lang == lang), None
|
||||
)
|
||||
|
||||
if (lang, gender) not in MAP_VOICE:
|
||||
raise probatio.Invalid("Unsupported language and gender specified.")
|
||||
|
||||
return value
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = probatio.All(
|
||||
TTS_PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
probatio.Required(CONF_PLATFORM): probatio.All(
|
||||
cv.string, _deprecated_platform
|
||||
),
|
||||
probatio.Optional(CONF_LANG): str,
|
||||
probatio.Optional(ATTR_GENDER): str,
|
||||
}
|
||||
),
|
||||
validate_lang,
|
||||
)
|
||||
|
||||
|
||||
async def async_get_engine(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> CloudProvider:
|
||||
) -> CloudProvider | None:
|
||||
"""Set up Cloud speech component."""
|
||||
if discovery_info is None:
|
||||
_LOGGER.error(
|
||||
"Configuring the cloud text-to-speech platform in YAML is no longer"
|
||||
" supported, remove `platform: cloud` from the `tts:` section"
|
||||
)
|
||||
return None
|
||||
cloud = hass.data[DATA_CLOUD]
|
||||
cloud_provider = CloudProvider(cloud)
|
||||
if discovery_info is not None:
|
||||
discovery_info["platform_loaded"].set()
|
||||
discovery_info["platform_loaded"].set()
|
||||
return cloud_provider
|
||||
|
||||
|
||||
|
||||
@@ -10,19 +10,13 @@ import wave
|
||||
|
||||
from hass_nabucasa.voice import VoiceError, VoiceTokenError
|
||||
from hass_nabucasa.voice_data import TTS_VOICES
|
||||
import probatio
|
||||
import pytest
|
||||
from pytest_homeassistant.common import async_mock_service
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
|
||||
from homeassistant.components.assist_pipeline.pipeline import STORAGE_KEY # pylint: disable=home-assistant-component-root-import
|
||||
from homeassistant.components.cloud.const import DEFAULT_TTS_DEFAULT_VOICE, DOMAIN
|
||||
from homeassistant.components.cloud.tts import (
|
||||
DEFAULT_VOICES,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_LANGUAGES,
|
||||
Voice,
|
||||
)
|
||||
from homeassistant.components.cloud.tts import DEFAULT_VOICES, SUPPORT_LANGUAGES, Voice
|
||||
from homeassistant.components.media_player import (
|
||||
ATTR_MEDIA_CONTENT_ID,
|
||||
DOMAIN as MP_DOMAIN,
|
||||
@@ -38,7 +32,6 @@ from homeassistant.components.tts import (
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core_config import async_process_ha_core_config
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@@ -82,48 +75,11 @@ def test_default_voice_is_valid(language: str, voice: str) -> None:
|
||||
assert voice in TTS_VOICES[language]
|
||||
|
||||
|
||||
def test_schema() -> None:
|
||||
"""Test schema."""
|
||||
assert "nl-NL" in SUPPORT_LANGUAGES
|
||||
|
||||
processed = PLATFORM_SCHEMA({"platform": "cloud", "language": "nl-NL"})
|
||||
assert processed["gender"] == "female"
|
||||
|
||||
with pytest.raises(probatio.Invalid):
|
||||
PLATFORM_SCHEMA(
|
||||
{"platform": "cloud", "language": "non-existing", "gender": "female"}
|
||||
)
|
||||
|
||||
with pytest.raises(probatio.Invalid):
|
||||
PLATFORM_SCHEMA(
|
||||
{"platform": "cloud", "language": "nl-NL", "gender": "not-supported"}
|
||||
)
|
||||
|
||||
# Should not raise
|
||||
PLATFORM_SCHEMA({"platform": "cloud", "language": "nl-NL", "gender": "female"})
|
||||
PLATFORM_SCHEMA({"platform": "cloud"})
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("engine_id", "platform_config"),
|
||||
"engine_id",
|
||||
[
|
||||
(
|
||||
DOMAIN,
|
||||
None,
|
||||
),
|
||||
(
|
||||
DOMAIN,
|
||||
{
|
||||
"platform": DOMAIN,
|
||||
"service_name": "yaml",
|
||||
"language": "fr-FR",
|
||||
"gender": "female",
|
||||
},
|
||||
),
|
||||
(
|
||||
"tts.home_assistant_cloud",
|
||||
None,
|
||||
),
|
||||
DOMAIN,
|
||||
"tts.home_assistant_cloud",
|
||||
],
|
||||
)
|
||||
async def test_prefs_default_voice(
|
||||
@@ -131,11 +87,10 @@ async def test_prefs_default_voice(
|
||||
cloud: MagicMock,
|
||||
set_cloud_prefs: Callable[[dict[str, Any]], Coroutine[Any, Any, None]],
|
||||
engine_id: str,
|
||||
platform_config: dict[str, Any] | None,
|
||||
) -> None:
|
||||
"""Test cloud provider uses the preferences."""
|
||||
assert await async_setup_component(hass, "homeassistant", {})
|
||||
assert await async_setup_component(hass, TTS_DOMAIN, {TTS_DOMAIN: platform_config})
|
||||
assert await async_setup_component(hass, TTS_DOMAIN, {TTS_DOMAIN: None})
|
||||
await hass.async_block_till_done()
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
@@ -149,7 +104,6 @@ async def test_prefs_default_voice(
|
||||
engine = get_engine_instance(hass, engine_id)
|
||||
|
||||
assert engine is not None
|
||||
# The platform config provider will be overridden by the discovery info provider.
|
||||
assert engine.default_language == "en-US"
|
||||
assert engine.default_options == {"audio_output": "mp3"}
|
||||
|
||||
@@ -160,24 +114,22 @@ async def test_prefs_default_voice(
|
||||
assert engine.default_options == {"audio_output": "mp3"}
|
||||
|
||||
|
||||
async def test_deprecated_platform_config(
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
cloud: MagicMock,
|
||||
@pytest.mark.usefixtures("cloud")
|
||||
async def test_yaml_platform_config_not_supported(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test cloud provider uses the preferences."""
|
||||
"""Test the cloud text-to-speech platform can't be configured in YAML."""
|
||||
assert await async_setup_component(hass, "homeassistant", {})
|
||||
assert await async_setup_component(
|
||||
hass, TTS_DOMAIN, {TTS_DOMAIN: {"platform": DOMAIN}}
|
||||
hass, TTS_DOMAIN, {TTS_DOMAIN: {"platform": DOMAIN, "service_name": "yaml"}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
issue = issue_registry.async_get_issue(DOMAIN, "deprecated_tts_platform_config")
|
||||
assert issue is not None
|
||||
assert issue.breaks_in_ha_version == "2024.9.0"
|
||||
assert issue.is_fixable is False
|
||||
assert issue.is_persistent is False
|
||||
assert issue.severity == ir.IssueSeverity.WARNING
|
||||
assert issue.translation_key == "deprecated_tts_platform_config"
|
||||
assert not hass.services.has_service(TTS_DOMAIN, "yaml")
|
||||
assert (
|
||||
"Configuring the cloud text-to-speech platform in YAML is no longer supported"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user