Skip to content
Snippets Groups Projects
Unverified Commit 715f4bd2 authored by Erik Montnemery's avatar Erik Montnemery Committed by GitHub
Browse files

Set deprecated flag on TTS engines replaced by entities in WS list (#124676)

parent 74a12bb8
No related branches found
No related tags found
No related merge requests found
......@@ -1086,6 +1086,7 @@ def websocket_list_engines(
language = msg.get("language")
providers = []
provider_info: dict[str, Any]
entity_domains: set[str] = set()
for entity in component.entities:
provider_info = {
......@@ -1097,6 +1098,8 @@ def websocket_list_engines(
language, entity.supported_languages, country
)
providers.append(provider_info)
if entity.platform:
entity_domains.add(entity.platform.platform_name)
for engine_id, provider in manager.providers.items():
provider_info = {
"engine_id": engine_id,
......@@ -1106,6 +1109,8 @@ def websocket_list_engines(
provider_info["supported_languages"] = language_util.matches(
language, provider.supported_languages, country
)
if engine_id in entity_domains:
provider_info["deprecated"] = True
providers.append(provider_info)
connection.send_message(
......
......@@ -31,6 +31,7 @@ from .common import (
SUPPORT_LANGUAGES,
TEST_DOMAIN,
MockProvider,
MockTTS,
MockTTSEntity,
get_media_source_url,
mock_config_entry_setup,
......@@ -38,7 +39,13 @@ from .common import (
retrieve_media,
)
from tests.common import async_mock_service, mock_restore_cache
from tests.common import (
MockModule,
async_mock_service,
mock_integration,
mock_platform,
mock_restore_cache,
)
from tests.typing import ClientSessionGenerator, WebSocketGenerator
ORIG_WRITE_TAGS = tts.SpeechManager.write_tags
......@@ -1635,6 +1642,53 @@ async def test_ws_list_engines(
}
async def test_ws_list_engines_deprecated(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
mock_tts_entity: MockTTSEntity,
) -> None:
"""Test listing tts engines.
This test asserts the deprecated flag is set on a legacy engine whose integration
also provides tts entities.
"""
mock_provider = MockProvider(DEFAULT_LANG)
mock_provider_2 = MockProvider(DEFAULT_LANG)
mock_integration(hass, MockModule(domain="test"))
mock_platform(hass, "test.tts", MockTTS(mock_provider))
mock_integration(hass, MockModule(domain="test_2"))
mock_platform(hass, "test_2.tts", MockTTS(mock_provider_2))
await async_setup_component(
hass, "tts", {"tts": [{"platform": "test"}, {"platform": "test_2"}]}
)
await mock_config_entry_setup(hass, mock_tts_entity)
client = await hass_ws_client()
await client.send_json_auto_id({"type": "tts/engine/list"})
msg = await client.receive_json()
assert msg["success"]
assert msg["result"] == {
"providers": [
{
"engine_id": "tts.test",
"supported_languages": ["de_CH", "de_DE", "en_GB", "en_US"],
},
{
"deprecated": True,
"engine_id": "test",
"supported_languages": ["de_CH", "de_DE", "en_GB", "en_US"],
},
{
"engine_id": "test_2",
"supported_languages": ["de_CH", "de_DE", "en_GB", "en_US"],
},
]
}
@pytest.mark.parametrize(
("setup", "engine_id"),
[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment