From b358103b58860e496a1702437ed440d0649592fa Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Tue, 17 Nov 2020 16:31:59 +0100 Subject: [PATCH] Update cloud integration to 0.38.0 (#43314) Co-authored-by: Paulus Schoutsen --- homeassistant/components/cloud/manifest.json | 2 +- homeassistant/components/cloud/tts.py | 35 +++++++++++++++----- homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/cloud/test_tts.py | 15 +++++++++ 6 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 tests/components/cloud/test_tts.py diff --git a/homeassistant/components/cloud/manifest.json b/homeassistant/components/cloud/manifest.json index f3c79a470ea..3f65ed2ba46 100644 --- a/homeassistant/components/cloud/manifest.json +++ b/homeassistant/components/cloud/manifest.json @@ -2,7 +2,7 @@ "domain": "cloud", "name": "Home Assistant Cloud", "documentation": "https://www.home-assistant.io/integrations/cloud", - "requirements": ["hass-nabucasa==0.37.2"], + "requirements": ["hass-nabucasa==0.38.0"], "dependencies": ["http", "webhook", "alexa"], "after_dependencies": ["google_assistant"], "codeowners": ["@home-assistant/cloud"] diff --git a/homeassistant/components/cloud/tts.py b/homeassistant/components/cloud/tts.py index ea769c6a054..9dd392a12c5 100644 --- a/homeassistant/components/cloud/tts.py +++ b/homeassistant/components/cloud/tts.py @@ -1,7 +1,7 @@ """Support for the cloud for text to speech service.""" from hass_nabucasa import Cloud -from hass_nabucasa.voice import VoiceError +from hass_nabucasa.voice import MAP_VOICE, VoiceError import voluptuous as vol from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider @@ -10,17 +10,36 @@ from .const import DOMAIN CONF_GENDER = "gender" -SUPPORT_LANGUAGES = ["en-US", "de-DE", "es-ES"] -SUPPORT_GENDER = ["male", "female"] +SUPPORT_LANGUAGES = list({key[0] for key in MAP_VOICE}) DEFAULT_LANG = "en-US" DEFAULT_GENDER = "female" -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Optional(CONF_LANG, default=DEFAULT_LANG): vol.In(SUPPORT_LANGUAGES), - vol.Optional(CONF_GENDER, default=DEFAULT_GENDER): vol.In(SUPPORT_GENDER), - } + +def validate_lang(value): + """Validate chosen gender or language.""" + lang = value[CONF_LANG] + gender = value.get(CONF_GENDER) + + if gender is None: + gender = value[CONF_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 vol.Invalid("Unsupported language and gender specified.") + + return value + + +PLATFORM_SCHEMA = vol.All( + PLATFORM_SCHEMA.extend( + { + vol.Optional(CONF_LANG, default=DEFAULT_LANG): str, + vol.Optional(CONF_GENDER): str, + } + ), + validate_lang, ) diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index c39bb3cc9a4..6bd03e8c36d 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -12,7 +12,7 @@ cryptography==3.2 defusedxml==0.6.0 distro==1.5.0 emoji==0.5.4 -hass-nabucasa==0.37.2 +hass-nabucasa==0.38.0 home-assistant-frontend==20201111.1 httpx==0.16.1 importlib-metadata==1.6.0;python_version<'3.8' diff --git a/requirements_all.txt b/requirements_all.txt index a42c3829d0a..81b5d8aff84 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -735,7 +735,7 @@ habitipy==0.2.0 hangups==0.4.11 # homeassistant.components.cloud -hass-nabucasa==0.37.2 +hass-nabucasa==0.38.0 # homeassistant.components.splunk hass_splunk==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ba665b3b709..afc4428e91d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -376,7 +376,7 @@ ha-ffmpeg==2.0 hangups==0.4.11 # homeassistant.components.cloud -hass-nabucasa==0.37.2 +hass-nabucasa==0.38.0 # homeassistant.components.tasmota hatasmota==0.0.30 diff --git a/tests/components/cloud/test_tts.py b/tests/components/cloud/test_tts.py new file mode 100644 index 00000000000..32a4ca7cb50 --- /dev/null +++ b/tests/components/cloud/test_tts.py @@ -0,0 +1,15 @@ +"""Tests for cloud tts.""" +from homeassistant.components.cloud import tts + + +def test_schema(): + """Test schema.""" + assert "nl-NL" in tts.SUPPORT_LANGUAGES + + processed = tts.PLATFORM_SCHEMA({"platform": "cloud", "language": "nl-NL"}) + assert processed["gender"] == "female" + + # Should not raise + processed = tts.PLATFORM_SCHEMA( + {"platform": "cloud", "language": "nl-NL", "gender": "female"} + )