From bf4fa5b25cb95e276a9d6f548e71aa932cb41edb Mon Sep 17 00:00:00 2001 From: chliny Date: Sun, 18 May 2025 21:19:58 +0800 Subject: [PATCH] fix: update model translation --- .../tencentcloud_asr/config_flow.py | 34 ++++++++++++------- .../tencentcloud_asr/tencentcloud_api.py | 7 ---- .../tencentcloud_asr/translations/en.json | 21 ++++++++++++ .../translations/zh-Hans.json | 21 ++++++++++++ 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/custom_components/tencentcloud_asr/config_flow.py b/custom_components/tencentcloud_asr/config_flow.py index 2eebfef..014655c 100644 --- a/custom_components/tencentcloud_asr/config_flow.py +++ b/custom_components/tencentcloud_asr/config_flow.py @@ -3,8 +3,9 @@ import voluptuous as vol from typing import Any, Dict from homeassistant.core import callback from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow, ConfigEntry +from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig, SelectOptionDict -from .tencentcloud_api import Modules, DefaultModel +from .tencentcloud_api import ModuleSupportLanguage, DefaultModel from .tencentcloud_api import TencentCloudAsrAPi from . import SecretIdKey, SecretKeyKey, ModelKey from . import DOMAIN @@ -12,6 +13,16 @@ from . import DOMAIN _LOGGER = logging.getLogger(__name__) +modelSelector = SelectSelector( + SelectSelectorConfig( + options=[ + SelectOptionDict(value=model_id, label=model_id) for model_id in ModuleSupportLanguage + ], + translation_key="model_descriptions", + ) +) + + class ConfigFlowHandler(ConfigFlow, domain=DOMAIN): async def async_step_user(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult: errors: Dict[str, str] = {} @@ -27,17 +38,14 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN): 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(SecretIdKey): str, - vol.Required(SecretKeyKey): str, - vol.Required(ModelKey, default=DefaultModel): vol.In(Modules.keys()), - }, - ), - errors=errors - ) + config_schema = vol.Schema( + { + vol.Required(SecretIdKey): str, + vol.Required(SecretKeyKey): str, + vol.Required(ModelKey, default=DefaultModel): modelSelector, + }) + + return self.async_show_form(step_id="user", data_schema=config_schema, errors=errors) @staticmethod @callback @@ -59,6 +67,6 @@ class TencentCloudAsrOptionFlow(OptionsFlow): return self.async_create_entry(title=DOMAIN, data=user_input) model = user_input.get(ModelKey, DefaultModel) config_schema = vol.Schema({ - vol.Optional(ModelKey, default=model): vol.In(Modules.keys()), + vol.Optional(ModelKey, default=model): modelSelector, }) return self.async_show_form(step_id="user", data_schema=config_schema, errors={}) diff --git a/custom_components/tencentcloud_asr/tencentcloud_api.py b/custom_components/tencentcloud_asr/tencentcloud_api.py index 26c094c..f277381 100644 --- a/custom_components/tencentcloud_asr/tencentcloud_api.py +++ b/custom_components/tencentcloud_asr/tencentcloud_api.py @@ -10,13 +10,6 @@ _LOGGER = logging.getLogger(__name__) SentenceRecognitionSourceTypePost = 1 SentenceRecognitionSourceTypeURL = 0 -Modules = { - "16k_zh": "中文", - "16k_zh-PY": "中英粤", - "16k_en": "英语", - "16k_yue": "粤语", - "16k_zh_dialect": "多方言", -} ModuleSupportLanguage = { "16k_zh": ["zh"], "16k_zh-PY": ["zh", "en", "yue"], diff --git a/custom_components/tencentcloud_asr/translations/en.json b/custom_components/tencentcloud_asr/translations/en.json index 613351e..cddc9af 100644 --- a/custom_components/tencentcloud_asr/translations/en.json +++ b/custom_components/tencentcloud_asr/translations/en.json @@ -8,8 +8,29 @@ "secretid": "tencentcloud asr secretid", "secretkey": "tencnetcloud asr secretkey", "model": "model" + }, + "description": "The integration is based on [Tencent Cloud API](https://cloud.tencent.com/document/product/1093/35646)." + } + } + }, + "options": { + "step": { + "user": { + "data": { + "model": "model" } } } + }, + "selector": { + "model_descriptions": { + "options": { + "16k_zh": "16k_zh Chinese", + "16k_zh-PY": "16k_zh-PY - Chinese, English, and Cantonese", + "16k_en": "16k_en - English", + "16k_yue": "16k_yue - Cantonese", + "16k_zh_dialect": "16k_zh_dialect - Chinese dialects" + } + } } } diff --git a/custom_components/tencentcloud_asr/translations/zh-Hans.json b/custom_components/tencentcloud_asr/translations/zh-Hans.json index f1d306f..1e86d46 100644 --- a/custom_components/tencentcloud_asr/translations/zh-Hans.json +++ b/custom_components/tencentcloud_asr/translations/zh-Hans.json @@ -8,8 +8,29 @@ "secretid": "请输入腾讯云ASR服务secretid", "secretkey": "请输入腾讯云ASR服务secretkey", "model": "模型" + }, + "description": "此集成基于腾讯云API, 具体见[腾讯云文档](https://cloud.tencent.com/document/product/1093/35646)" + } + } + }, + "options": { + "step": { + "user": { + "data": { + "model": "模型" } } } + }, + "selector": { + "model_descriptions": { + "options": { + "16k_zh": "16k_zh - 中文通用", + "16k_zh-PY": "16k_zh-PY - 中英粤", + "16k_en": "16k_en - 英语", + "16k_yue": "16k_yue - 粤语", + "16k_zh_dialect": "16k_zh_dialect - 中文多方言" + } + } } }