Remove legacy STT provider from the demo integration (#94585)
This commit is contained in:
parent
e5b2801f5b
commit
1b8c72e644
2 changed files with 15 additions and 78 deletions
|
@ -9,7 +9,6 @@ from homeassistant.components.stt import (
|
|||
AudioCodecs,
|
||||
AudioFormats,
|
||||
AudioSampleRates,
|
||||
Provider,
|
||||
SpeechMetadata,
|
||||
SpeechResult,
|
||||
SpeechResultState,
|
||||
|
@ -18,20 +17,10 @@ from homeassistant.components.stt import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
SUPPORT_LANGUAGES = ["en", "de"]
|
||||
|
||||
|
||||
async def async_get_engine(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> Provider:
|
||||
"""Set up Demo speech component."""
|
||||
return DemoProvider()
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
|
@ -86,48 +75,3 @@ class DemoProviderEntity(SpeechToTextEntity):
|
|||
pass
|
||||
|
||||
return SpeechResult("Turn the Kitchen Lights on", SpeechResultState.SUCCESS)
|
||||
|
||||
|
||||
class DemoProvider(Provider):
|
||||
"""Demo speech API provider."""
|
||||
|
||||
@property
|
||||
def supported_languages(self) -> list[str]:
|
||||
"""Return a list of supported languages."""
|
||||
return SUPPORT_LANGUAGES
|
||||
|
||||
@property
|
||||
def supported_formats(self) -> list[AudioFormats]:
|
||||
"""Return a list of supported formats."""
|
||||
return [AudioFormats.WAV]
|
||||
|
||||
@property
|
||||
def supported_codecs(self) -> list[AudioCodecs]:
|
||||
"""Return a list of supported codecs."""
|
||||
return [AudioCodecs.PCM]
|
||||
|
||||
@property
|
||||
def supported_bit_rates(self) -> list[AudioBitRates]:
|
||||
"""Return a list of supported bit rates."""
|
||||
return [AudioBitRates.BITRATE_16]
|
||||
|
||||
@property
|
||||
def supported_sample_rates(self) -> list[AudioSampleRates]:
|
||||
"""Return a list of supported sample rates."""
|
||||
return [AudioSampleRates.SAMPLERATE_16000, AudioSampleRates.SAMPLERATE_44100]
|
||||
|
||||
@property
|
||||
def supported_channels(self) -> list[AudioChannels]:
|
||||
"""Return a list of supported channels."""
|
||||
return [AudioChannels.CHANNEL_STEREO]
|
||||
|
||||
async def async_process_audio_stream(
|
||||
self, metadata: SpeechMetadata, stream: AsyncIterable[bytes]
|
||||
) -> SpeechResult:
|
||||
"""Process an audio stream to STT service."""
|
||||
|
||||
# Read available data
|
||||
async for _ in stream:
|
||||
pass
|
||||
|
||||
return SpeechResult("Turn the Kitchen Lights on", SpeechResultState.SUCCESS)
|
||||
|
|
|
@ -4,42 +4,38 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import stt
|
||||
from homeassistant.components.demo import DOMAIN as DEMO_DOMAIN
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def setup_legacy_platform(hass: HomeAssistant) -> None:
|
||||
"""Set up legacy demo platform."""
|
||||
assert await async_setup_component(hass, stt.DOMAIN, {"stt": {"platform": "demo"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def setup_config_entry(hass: HomeAssistant) -> None:
|
||||
"""Set up demo component from config entry."""
|
||||
config_entry = MockConfigEntry(domain=DEMO_DOMAIN)
|
||||
config_entry.add_to_hass(hass)
|
||||
async def stt_only(hass: HomeAssistant) -> None:
|
||||
"""Enable only the stt platform."""
|
||||
with patch(
|
||||
"homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM",
|
||||
[Platform.STT],
|
||||
):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def setup_config_entry(hass: HomeAssistant, stt_only) -> None:
|
||||
"""Set up demo component from config entry."""
|
||||
config_entry = MockConfigEntry(domain=DEMO_DOMAIN)
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_legacy_platform")
|
||||
async def test_demo_settings(hass_client: ClientSessionGenerator) -> None:
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.get("/api/stt/demo")
|
||||
response = await client.get("/api/stt/stt.demo_stt")
|
||||
response_data = await response.json()
|
||||
|
||||
assert response.status == HTTPStatus.OK
|
||||
|
@ -53,22 +49,20 @@ async def test_demo_settings(hass_client: ClientSessionGenerator) -> None:
|
|||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_legacy_platform")
|
||||
async def test_demo_speech_no_metadata(hass_client: ClientSessionGenerator) -> None:
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post("/api/stt/demo", data=b"Test")
|
||||
response = await client.post("/api/stt/stt.demo_stt", data=b"Test")
|
||||
assert response.status == HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_legacy_platform")
|
||||
async def test_demo_speech_wrong_metadata(hass_client: ClientSessionGenerator) -> None:
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post(
|
||||
"/api/stt/demo",
|
||||
"/api/stt/stt.demo_stt",
|
||||
headers={
|
||||
"X-Speech-Content": (
|
||||
"format=wav; codec=pcm; sample_rate=8000; bit_rate=16; channel=1;"
|
||||
|
@ -80,13 +74,12 @@ async def test_demo_speech_wrong_metadata(hass_client: ClientSessionGenerator) -
|
|||
assert response.status == HTTPStatus.UNSUPPORTED_MEDIA_TYPE
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_legacy_platform")
|
||||
async def test_demo_speech(hass_client: ClientSessionGenerator) -> None:
|
||||
"""Test retrieve settings from demo provider."""
|
||||
client = await hass_client()
|
||||
|
||||
response = await client.post(
|
||||
"/api/stt/demo",
|
||||
"/api/stt/stt.demo_stt",
|
||||
headers={
|
||||
"X-Speech-Content": (
|
||||
"format=wav; codec=pcm; sample_rate=16000; bit_rate=16; channel=2;"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue