diff --git a/homeassistant/components/cloud/strings.json b/homeassistant/components/cloud/strings.json index 6f1e3c80bf7..4bef2ac9ba3 100644 --- a/homeassistant/components/cloud/strings.json +++ b/homeassistant/components/cloud/strings.json @@ -24,6 +24,10 @@ } }, "issues": { + "deprecated_tts_platform_config": { + "title": "The Cloud text-to-speech platform configuration is deprecated", + "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." + }, "deprecated_voice": { "title": "A deprecated voice was used", "fix_flow": { diff --git a/homeassistant/components/cloud/tts.py b/homeassistant/components/cloud/tts.py index ba34ac7a9b0..59ae5b22214 100644 --- a/homeassistant/components/cloud/tts.py +++ b/homeassistant/components/cloud/tts.py @@ -20,8 +20,9 @@ from homeassistant.components.tts import ( Voice, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import Platform -from homeassistant.core import HomeAssistant, callback +from homeassistant.const import CONF_PLATFORM, Platform +from homeassistant.core import HomeAssistant, async_get_hass, callback +import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -39,6 +40,27 @@ SUPPORT_LANGUAGES = list(TTS_VOICES) _LOGGER = logging.getLogger(__name__) +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: @@ -58,6 +80,7 @@ def validate_lang(value: dict[str, Any]) -> dict[str, Any]: PLATFORM_SCHEMA = vol.All( TTS_PLATFORM_SCHEMA.extend( { + vol.Required(CONF_PLATFORM): vol.All(cv.string, _deprecated_platform), vol.Optional(CONF_LANG): str, vol.Optional(ATTR_GENDER): str, } diff --git a/tests/components/cloud/test_tts.py b/tests/components/cloud/test_tts.py index 92a9cb10992..db43c40b69a 100644 --- a/tests/components/cloud/test_tts.py +++ b/tests/components/cloud/test_tts.py @@ -122,6 +122,26 @@ async def test_prefs_default_voice( assert engine.default_options == {"gender": "male", "audio_output": "mp3"} +async def test_deprecated_platform_config( + hass: HomeAssistant, + issue_registry: IssueRegistry, + cloud: MagicMock, +) -> None: + """Test cloud provider uses the preferences.""" + assert await async_setup_component( + hass, TTS_DOMAIN, {TTS_DOMAIN: {"platform": DOMAIN}} + ) + 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 == IssueSeverity.WARNING + assert issue.translation_key == "deprecated_tts_platform_config" + + @pytest.mark.parametrize( "engine_id", [