Allow to specify TTS language in the service call. (#5047)

* Allow to specify TTS language in the service call.

* Allow to specify TTS language in the service call.

* Respect 79 char limit

* Fix "Too many blank lines"

* Fix "Too many blank lines"

* Fix "Too many blank lines"

* Change language to be optional parameter of *get_tts_audio

* Change language to be optional parameter of *get_tts_audio

* Respect 79 char limit

* Don't pass "None

* Use default of "None" for TTS language

* Use default of "None" for TTS language

* Don't pass "None"

* Change TTS cache key to be hash_lang_engine

* Change language from demo to en

* Fix wrong replace
This commit is contained in:
andrey-git authored and Pascal Vizeli committed 2016-12-27 17:01:22 +01:00
1 parent 68865ec27b
commit 4728fa8da6
8 files changed
+206 -38

No files matched your search

+96 -12
View File
@@ -82,11 +82,69 @@ class TestTTS(object):
assert calls[0].data[ATTR_MEDIA_CONTENT_TYPE] == MEDIA_TYPE_MUSIC
assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(
"/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd"
"_demo.mp3") \
"_en_demo.mp3") \
!= -1
assert os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3"))
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3"))
def test_setup_component_and_test_service_with_config_language(self):
"""Setup the demo platform and call service."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
config = {
tts.DOMAIN: {
'platform': 'demo',
'language': 'lang'
}
}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
self.hass.services.call(tts.DOMAIN, 'demo_say', {
tts.ATTR_MESSAGE: "I person is on front of your door.",
})
self.hass.block_till_done()
assert len(calls) == 1
assert calls[0].data[ATTR_MEDIA_CONTENT_TYPE] == MEDIA_TYPE_MUSIC
assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(
"/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd"
"_lang_demo.mp3") \
!= -1
assert os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_lang_demo.mp3"))
def test_setup_component_and_test_service_with_service_language(self):
"""Setup the demo platform and call service."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
config = {
tts.DOMAIN: {
'platform': 'demo',
}
}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
self.hass.services.call(tts.DOMAIN, 'demo_say', {
tts.ATTR_MESSAGE: "I person is on front of your door.",
tts.ATTR_LANGUAGE: "lang",
})
self.hass.block_till_done()
assert len(calls) == 1
assert calls[0].data[ATTR_MEDIA_CONTENT_TYPE] == MEDIA_TYPE_MUSIC
assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(
"/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd"
"_lang_demo.mp3") \
!= -1
assert os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_lang_demo.mp3"))
def test_setup_component_and_test_service_clear_cache(self):
"""Setup the demo platform and call service clear cache."""
@@ -109,14 +167,14 @@ class TestTTS(object):
assert len(calls) == 1
assert os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3"))
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3"))
self.hass.services.call(tts.DOMAIN, tts.SERVICE_CLEAR_CACHE, {})
self.hass.block_till_done()
assert not os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3"))
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3"))
def test_setup_component_and_test_service_with_receive_voice(self):
"""Setup the demo platform and call service and receive voice."""
@@ -144,6 +202,32 @@ class TestTTS(object):
assert req.status_code == 200
assert req.content == demo_data
def test_setup_component_and_test_service_with_receive_voice_german(self):
"""Setup the demo platform and call service and receive voice."""
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
config = {
tts.DOMAIN: {
'platform': 'demo',
}
}
with assert_setup_component(1, tts.DOMAIN):
setup_component(self.hass, tts.DOMAIN, config)
self.hass.start()
self.hass.services.call(tts.DOMAIN, 'demo_say', {
tts.ATTR_MESSAGE: "I person is on front of your door.",
})
self.hass.block_till_done()
assert len(calls) == 1
req = requests.get(calls[0].data[ATTR_MEDIA_CONTENT_ID])
_, demo_data = self.demo_provider.get_tts_audio("bla", "de")
assert req.status_code == 200
assert req.content == demo_data
def test_setup_component_and_web_view_wrong_file(self):
"""Setup the demo platform and receive wrong file from web."""
config = {
@@ -158,7 +242,7 @@ class TestTTS(object):
self.hass.start()
url = ("{}/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd"
"_demo.mp3").format(self.hass.config.api.base_url)
"_en_demo.mp3").format(self.hass.config.api.base_url)
req = requests.get(url)
assert req.status_code == 404
@@ -177,7 +261,7 @@ class TestTTS(object):
self.hass.start()
url = ("{}/api/tts_proxy/265944dsk32c1b2a621be5930510bb2cd"
"_demo.mp3").format(self.hass.config.api.base_url)
"_en_demo.mp3").format(self.hass.config.api.base_url)
req = requests.get(url)
assert req.status_code == 404
@@ -204,7 +288,7 @@ class TestTTS(object):
assert len(calls) == 1
assert not os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3"))
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3"))
def test_setup_component_test_with_cache_call_service_without_cache(self):
"""Setup demo platform with cache and call service without cache."""
@@ -229,7 +313,7 @@ class TestTTS(object):
assert len(calls) == 1
assert not os.path.isfile(os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3"))
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3"))
def test_setup_component_test_with_cache_dir(self):
"""Setup demo platform with cache and call service without cache."""
@@ -238,7 +322,7 @@ class TestTTS(object):
_, demo_data = self.demo_provider.get_tts_audio("bla")
cache_file = os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3")
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3")
os.mkdir(self.default_tts_cache)
with open(cache_file, "wb") as voice_file:
@@ -264,7 +348,7 @@ class TestTTS(object):
assert len(calls) == 1
assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(
"/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd"
"_demo.mp3") \
"_en_demo.mp3") \
!= -1
@patch('homeassistant.components.tts.demo.DemoProvider.get_tts_audio',
@@ -294,7 +378,7 @@ class TestTTS(object):
_, demo_data = self.demo_provider.get_tts_audio("bla")
cache_file = os.path.join(
self.default_tts_cache,
"265944c108cbb00b2a621be5930513e03a0bb2cd_demo.mp3")
"265944c108cbb00b2a621be5930513e03a0bb2cd_en_demo.mp3")
os.mkdir(self.default_tts_cache)
with open(cache_file, "wb") as voice_file:
@@ -313,7 +397,7 @@ class TestTTS(object):
self.hass.start()
url = ("{}/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd"
"_demo.mp3").format(self.hass.config.api.base_url)
"_en_demo.mp3").format(self.hass.config.api.base_url)
req = requests.get(url)
assert req.status_code == 200