Speech to Text component (#28434)
* Initial commit for STT * Fix code review
This commit is contained in:
1 parent
33c8cba30d
commit
99c0559a0c
11 files changed
+436
-1
No files matched your search
@@ -0,0 +1,69 @@
|
||||
"""The tests for the demo stt component."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import stt
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_comp(hass):
|
||||
"""Set up demo component."""
|
||||
hass.loop.run_until_complete(
|
||||
async_setup_component(hass, stt.DOMAIN, {"stt": {"platform": "demo"}})
|
||||
)
|
||||
|
||||
|
||||
async def test_demo_settings(hass_client):
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.get("/api/stt/demo")
|
||||
response_data = await response.json()
|
||||
|
||||
assert response.status == 200
|
||||
assert response_data == {
|
||||
"languages": ["en", "de"],
|
||||
"bitrates": [16],
|
||||
"samplerates": [16000, 44100],
|
||||
"formats": ["wav"],
|
||||
"codecs": ["pcm"],
|
||||
}
|
||||
|
||||
|
||||
async def test_demo_speech_no_metadata(hass_client):
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post("/api/stt/demo", data=b"Test")
|
||||
assert response.status == 400
|
||||
|
||||
|
||||
async def test_demo_speech_wrong_metadata(hass_client):
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post(
|
||||
"/api/stt/demo",
|
||||
headers={
|
||||
"X-Speech-Content": "format=wav; codec=pcm; samplerate=8000; bitrate=16; language=de"
|
||||
},
|
||||
data=b"Test",
|
||||
)
|
||||
assert response.status == 415
|
||||
|
||||
|
||||
async def test_demo_speech(hass_client):
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post(
|
||||
"/api/stt/demo",
|
||||
headers={
|
||||
"X-Speech-Content": "format=wav; codec=pcm; samplerate=16000; bitrate=16; language=de"
|
||||
},
|
||||
data=b"Test",
|
||||
)
|
||||
response_data = await response.json()
|
||||
|
||||
assert response.status == 200
|
||||
assert response_data == {"text": "Turn the Kitchen Lights on", "result": "success"}
|
||||
@@ -0,0 +1 @@
|
||||
"""Speech to text tests."""
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Test STT component setup."""
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import stt
|
||||
|
||||
|
||||
async def test_setup_comp(hass):
|
||||
"""Set up demo component."""
|
||||
assert await async_setup_component(hass, stt.DOMAIN, {"stt": {}})
|
||||
|
||||
|
||||
async def test_demo_settings_not_exists(hass, hass_client):
|
||||
"""Test retrieve settings from demo provider."""
|
||||
assert await async_setup_component(hass, stt.DOMAIN, {"stt": {}})
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.get("/api/stt/beer")
|
||||
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
async def test_demo_speech_not_exists(hass, hass_client):
|
||||
"""Test retrieve settings from demo provider."""
|
||||
assert await async_setup_component(hass, stt.DOMAIN, {"stt": {}})
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post("/api/stt/beer", data=b"test")
|
||||
|
||||
assert response.status == 404
|
||||
Reference in new issue
Block a user