* Add wyoming integration with stt/tts * Forward config entry setup * Use SpeechToTextEntity * Add strings to config flow * Move connection into config flow * Add tests * On load/unload used platforms * Tweaks * Add unload test * Fix stt * Add missing file * Add test for no services * Improve coverage * Finish test coverage --------- Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
"""Config flow for Wyoming integration."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
|
from homeassistant.data_entry_flow import FlowResult
|
|
|
|
from .const import DOMAIN
|
|
from .data import WyomingService
|
|
|
|
STEP_USER_DATA_SCHEMA = vol.Schema(
|
|
{
|
|
vol.Required(CONF_HOST): str,
|
|
vol.Required(CONF_PORT): int,
|
|
}
|
|
)
|
|
|
|
|
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|
"""Handle a config flow for Wyoming integration."""
|
|
|
|
VERSION = 1
|
|
|
|
async def async_step_user(
|
|
self, user_input: dict[str, Any] | None = None
|
|
) -> FlowResult:
|
|
"""Handle the initial step."""
|
|
if user_input is None:
|
|
return self.async_show_form(
|
|
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
|
)
|
|
|
|
service = await WyomingService.create(
|
|
user_input[CONF_HOST],
|
|
user_input[CONF_PORT],
|
|
)
|
|
|
|
if service is None:
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=STEP_USER_DATA_SCHEMA,
|
|
errors={"base": "cannot_connect"},
|
|
)
|
|
|
|
# ASR = automated speech recognition (STT)
|
|
asr_installed = [asr for asr in service.info.asr if asr.installed]
|
|
if not asr_installed:
|
|
return self.async_abort(reason="no_services")
|
|
|
|
name = asr_installed[0].name
|
|
|
|
return self.async_create_entry(title=name, data=user_input)
|