Deprecate cloud tts platform config (#110461)

* Deprecate cloud tts platform config

* Add test
This commit is contained in:
Martin Hjelmare 2024-02-13 13:00:42 +01:00 committed by GitHub
parent 8fb04d759b
commit f140c1a46d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 2 deletions

View file

@ -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": {

View file

@ -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,
}

View file

@ -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",
[