mirror of
https://github.com/chliny/hass-tencentcloud-asr.git
synced 2026-07-30 03:03:55 +08:00
fix: add translate & fix bugs
This commit is contained in:
@@ -1,43 +1,39 @@
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from typing import Any, Dict
|
||||
import aiohttp
|
||||
import logging
|
||||
from tencentcloud_api import Modules
|
||||
from .tencentcloud_api import Modules, DefaultModel
|
||||
from .tencentcloud_api import TencentCloudAsrAPi
|
||||
from . import SecretIdKey, SecretKeyKey, ModelKey
|
||||
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def validate_path(path: str) -> None:
|
||||
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(path) as response:
|
||||
_LOGGER.info(f'response.status {response.status}')
|
||||
if response.status != 200:
|
||||
raise ValueError
|
||||
await response.text()
|
||||
except Exception as e:
|
||||
_LOGGER.error('validate_path', e)
|
||||
raise ValueError
|
||||
|
||||
|
||||
class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
|
||||
errors: Dict[str, str] = {}
|
||||
if user_input:
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
try:
|
||||
secretId = user_input.get(SecretIdKey)
|
||||
secretKey = user_input.get(SecretKeyKey)
|
||||
TencentCloudAsrAPi(secretId, secretKey)
|
||||
except Exception as err:
|
||||
errors["base"] = str(err)
|
||||
_LOGGER.error("check secret failed:%s", err)
|
||||
|
||||
if not errors:
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required("secretid"): str,
|
||||
vol.Required("secretkey"): str,
|
||||
vol.Optional("model", default="16k_zh"): vol.In(Modules.keys()),
|
||||
vol.Required(SecretIdKey): str,
|
||||
vol.Required(SecretKeyKey): str,
|
||||
vol.Optional(ModelKey, default=DefaultModel): vol.In(Modules.keys()),
|
||||
},
|
||||
),
|
||||
errors=errors
|
||||
|
||||
Reference in New Issue
Block a user