mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Deprecate cloud tts gender (#112256)
* Deprecate cloud tts gender option * Update http api and prefs * Test migration of prefs to minor version 4 * Adjust breaking date * Add test for bad voice in http api * Flatten tts info * Fix comments * Fix comment date Co-authored-by: Erik Montnemery <erik@montnemery.com> * Clarify voice validator --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
|
||||
from copy import deepcopy
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import aiohttp
|
||||
from hass_nabucasa import thingtalk, voice
|
||||
from hass_nabucasa import thingtalk
|
||||
from hass_nabucasa.auth import Unauthenticated, UnknownError
|
||||
from hass_nabucasa.const import STATE_CONNECTED
|
||||
from hass_nabucasa.voice import TTS_VOICES
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.alexa import errors as alexa_errors
|
||||
@@ -17,6 +19,7 @@ from homeassistant.components.assist_pipeline.pipeline import STORAGE_KEY
|
||||
from homeassistant.components.cloud.const import DEFAULT_EXPOSED_DOMAINS, DOMAIN
|
||||
from homeassistant.components.google_assistant.helpers import GoogleEntity
|
||||
from homeassistant.components.homeassistant import exposed_entities
|
||||
from homeassistant.components.websocket_api import ERR_INVALID_FORMAT
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -774,7 +777,7 @@ async def test_websocket_status(
|
||||
"google_report_state": True,
|
||||
"remote_allow_remote_enable": True,
|
||||
"remote_enabled": False,
|
||||
"tts_default_voice": ["en-US", "female"],
|
||||
"tts_default_voice": ["en-US", "JennyNeural"],
|
||||
},
|
||||
"alexa_entities": {
|
||||
"include_domains": [],
|
||||
@@ -896,14 +899,13 @@ async def test_websocket_update_preferences(
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json(
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "cloud/update_prefs",
|
||||
"alexa_enabled": False,
|
||||
"google_enabled": False,
|
||||
"google_secure_devices_pin": "1234",
|
||||
"tts_default_voice": ["en-GB", "male"],
|
||||
"tts_default_voice": ["en-GB", "RyanNeural"],
|
||||
"remote_allow_remote_enable": False,
|
||||
}
|
||||
)
|
||||
@@ -914,7 +916,34 @@ async def test_websocket_update_preferences(
|
||||
assert not cloud.client.prefs.alexa_enabled
|
||||
assert cloud.client.prefs.google_secure_devices_pin == "1234"
|
||||
assert cloud.client.prefs.remote_allow_remote_enable is False
|
||||
assert cloud.client.prefs.tts_default_voice == ("en-GB", "male")
|
||||
assert cloud.client.prefs.tts_default_voice == ("en-GB", "RyanNeural")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("language", "voice"), [("en-GB", "bad_voice"), ("bad_language", "RyanNeural")]
|
||||
)
|
||||
async def test_websocket_update_preferences_bad_voice(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
cloud: MagicMock,
|
||||
setup_cloud: None,
|
||||
language: str,
|
||||
voice: str,
|
||||
) -> None:
|
||||
"""Test updating preference."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
"type": "cloud/update_prefs",
|
||||
"tts_default_voice": [language, voice],
|
||||
}
|
||||
)
|
||||
response = await client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == ERR_INVALID_FORMAT
|
||||
assert cloud.client.prefs.tts_default_voice == ("en-US", "JennyNeural")
|
||||
|
||||
|
||||
async def test_websocket_update_preferences_alexa_report_state(
|
||||
@@ -1596,24 +1625,23 @@ async def test_tts_info(
|
||||
setup_cloud: None,
|
||||
) -> None:
|
||||
"""Test that we can get TTS info."""
|
||||
# Verify the format is as expected
|
||||
assert voice.MAP_VOICE[("en-US", voice.Gender.FEMALE)] == "JennyNeural"
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch.dict(
|
||||
"homeassistant.components.cloud.http_api.MAP_VOICE",
|
||||
{
|
||||
("en-US", voice.Gender.MALE): "GuyNeural",
|
||||
("en-US", voice.Gender.FEMALE): "JennyNeural",
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
await client.send_json({"id": 5, "type": "cloud/tts/info"})
|
||||
response = await client.receive_json()
|
||||
await client.send_json_auto_id({"type": "cloud/tts/info"})
|
||||
response = await client.receive_json()
|
||||
|
||||
assert response["success"]
|
||||
assert response["result"] == {"languages": [["en-US", "male"], ["en-US", "female"]]}
|
||||
assert response["result"] == {
|
||||
"languages": json.loads(
|
||||
json.dumps(
|
||||
[
|
||||
(language, voice)
|
||||
for language, voices in TTS_VOICES.items()
|
||||
for voice in voices
|
||||
]
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user