From 4aeae601411533ae7bff25390a25bff2c8c16cf6 Mon Sep 17 00:00:00 2001 From: LiShuzhen Date: Wed, 5 Mar 2025 13:40:23 +0800 Subject: [PATCH] revert: multi_lang.json --- .../xiaomi_home/miot/miot_spec.py | 22 ++- .../xiaomi_home/miot/specs/multi_lang.json | 172 ++++++++++++++++++ 2 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 custom_components/xiaomi_home/miot/specs/multi_lang.json diff --git a/custom_components/xiaomi_home/miot/miot_spec.py b/custom_components/xiaomi_home/miot/miot_spec.py index 859453b..e5ccf9e 100644 --- a/custom_components/xiaomi_home/miot/miot_spec.py +++ b/custom_components/xiaomi_home/miot/miot_spec.py @@ -56,7 +56,7 @@ from slugify import slugify # pylint: disable=relative-beyond-top-level from .const import DEFAULT_INTEGRATION_LANGUAGE, SPEC_STD_LIB_EFFECTIVE_TIME -from .common import MIoTHttp, load_yaml_file +from .common import MIoTHttp, load_yaml_file, load_json_file from .miot_error import MIoTSpecError from .miot_storage import MIoTStorage @@ -837,6 +837,7 @@ class _MIoTSpecMultiLang: """MIoT SPEC multi lang class.""" # pylint: disable=broad-exception-caught _DOMAIN: str = 'miot_specs_multi_lang' + _MULTI_LANG_FILE = 'specs/multi_lang.json' _lang: str _storage: MIoTStorage _main_loop: asyncio.AbstractEventLoop @@ -892,6 +893,25 @@ class _MIoTSpecMultiLang: except Exception as err: trans_local = {} _LOGGER.info('get multi lang from local failed, %s, %s', urn, err) + # Revert: load multi_lang.json + try: + trans_local_json = await self._main_loop.run_in_executor( + None, load_json_file, + os.path.join( + os.path.dirname(os.path.abspath(__file__)), + self._MULTI_LANG_FILE)) + urn_strs: list[str] = urn.split(':') + urn_key: str = ':'.join(urn_strs[:6]) + if ( + isinstance(trans_local_json, dict) + and urn_key in trans_local_json + and self._lang in trans_local_json[urn_key] + ): + trans_cache.update(trans_local_json[urn_key][self._lang]) + trans_local = trans_local_json[urn_key] + except Exception as err: # pylint: disable=broad-exception-caught + _LOGGER.error('multi lang, load json file error, %s', err) + # Revert end # Default language if not trans_cache: if trans_cloud and DEFAULT_INTEGRATION_LANGUAGE in trans_cloud: diff --git a/custom_components/xiaomi_home/miot/specs/multi_lang.json b/custom_components/xiaomi_home/miot/specs/multi_lang.json new file mode 100644 index 0000000..7f16732 --- /dev/null +++ b/custom_components/xiaomi_home/miot/specs/multi_lang.json @@ -0,0 +1,172 @@ +{ + "urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1": { + "de": { + "service:001": "Geräteinformationen", + "service:001:property:003": "Geräte-ID", + "service:001:property:005": "Seriennummer (SN)", + "service:002": "Gateway", + "service:002:event:001": "Netzwerk geändert", + "service:002:event:002": "Netzwerk geändert", + "service:002:property:001": "Zugriffsmethode", + "service:002:property:001:valuelist:000": "Kabelgebunden", + "service:002:property:001:valuelist:001": "5G Drahtlos", + "service:002:property:001:valuelist:002": "2.4G Drahtlos", + "service:002:property:002": "IP-Adresse", + "service:002:property:003": "WiFi-Netzwerkname", + "service:002:property:004": "Aktuelle Zeit", + "service:002:property:005": "DHCP-Server-MAC-Adresse", + "service:003": "Anzeigelampe", + "service:003:property:001": "Schalter", + "service:004": "Virtueller Dienst", + "service:004:action:001": "Virtuelles Ereignis erzeugen", + "service:004:event:001": "Virtuelles Ereignis aufgetreten", + "service:004:property:001": "Ereignisname" + }, + "en": { + "service:001": "Device Information", + "service:001:property:003": "Device ID", + "service:001:property:005": "Serial Number (SN)", + "service:002": "Gateway", + "service:002:event:001": "Network Changed", + "service:002:event:002": "Network Changed", + "service:002:property:001": "Access Method", + "service:002:property:001:valuelist:000": "Wired", + "service:002:property:001:valuelist:001": "5G Wireless", + "service:002:property:001:valuelist:002": "2.4G Wireless", + "service:002:property:002": "IP Address", + "service:002:property:003": "WiFi Network Name", + "service:002:property:004": "Current Time", + "service:002:property:005": "DHCP Server MAC Address", + "service:003": "Indicator Light", + "service:003:property:001": "Switch", + "service:004": "Virtual Service", + "service:004:action:001": "Generate Virtual Event", + "service:004:event:001": "Virtual Event Occurred", + "service:004:property:001": "Event Name" + }, + "es": { + "service:001": "Información del dispositivo", + "service:001:property:003": "ID del dispositivo", + "service:001:property:005": "Número de serie (SN)", + "service:002": "Puerta de enlace", + "service:002:event:001": "Cambio de red", + "service:002:event:002": "Cambio de red", + "service:002:property:001": "Método de acceso", + "service:002:property:001:valuelist:000": "Cableado", + "service:002:property:001:valuelist:001": "5G inalámbrico", + "service:002:property:001:valuelist:002": "2.4G inalámbrico", + "service:002:property:002": "Dirección IP", + "service:002:property:003": "Nombre de red WiFi", + "service:002:property:004": "Hora actual", + "service:002:property:005": "Dirección MAC del servidor DHCP", + "service:003": "Luz indicadora", + "service:003:property:001": "Interruptor", + "service:004": "Servicio virtual", + "service:004:action:001": "Generar evento virtual", + "service:004:event:001": "Ocurrió un evento virtual", + "service:004:property:001": "Nombre del evento" + }, + "fr": { + "service:001": "Informations sur l'appareil", + "service:001:property:003": "ID de l'appareil", + "service:001:property:005": "Numéro de série (SN)", + "service:002": "Passerelle", + "service:002:event:001": "Changement de réseau", + "service:002:event:002": "Changement de réseau", + "service:002:property:001": "Méthode d'accès", + "service:002:property:001:valuelist:000": "Câblé", + "service:002:property:001:valuelist:001": "Sans fil 5G", + "service:002:property:001:valuelist:002": "Sans fil 2.4G", + "service:002:property:002": "Adresse IP", + "service:002:property:003": "Nom du réseau WiFi", + "service:002:property:004": "Heure actuelle", + "service:002:property:005": "Adresse MAC du serveur DHCP", + "service:003": "Voyant lumineux", + "service:003:property:001": "Interrupteur", + "service:004": "Service virtuel", + "service:004:action:001": "Générer un événement virtuel", + "service:004:event:001": "Événement virtuel survenu", + "service:004:property:001": "Nom de l'événement" + }, + "ja": { + "service:001": "デバイス情報", + "service:001:property:003": "デバイスID", + "service:001:property:005": "シリアル番号 (SN)", + "service:002": "ゲートウェイ", + "service:002:event:001": "ネットワークが変更されました", + "service:002:event:002": "ネットワークが変更されました", + "service:002:property:001": "アクセス方法", + "service:002:property:001:valuelist:000": "有線", + "service:002:property:001:valuelist:001": "5G ワイヤレス", + "service:002:property:001:valuelist:002": "2.4G ワイヤレス", + "service:002:property:002": "IPアドレス", + "service:002:property:003": "WiFiネットワーク名", + "service:002:property:004": "現在の時間", + "service:002:property:005": "DHCPサーバーMACアドレス", + "service:003": "インジケータライト", + "service:003:property:001": "スイッチ", + "service:004": "バーチャルサービス", + "service:004:action:001": "バーチャルイベントを生成", + "service:004:event:001": "バーチャルイベントが発生しました", + "service:004:property:001": "イベント名" + }, + "ru": { + "service:001": "Информация об устройстве", + "service:001:property:003": "ID устройства", + "service:001:property:005": "Серийный номер (SN)", + "service:002": "Шлюз", + "service:002:event:001": "Сеть изменена", + "service:002:event:002": "Сеть изменена", + "service:002:property:001": "Метод доступа", + "service:002:property:001:valuelist:000": "Проводной", + "service:002:property:001:valuelist:001": "5G Беспроводной", + "service:002:property:001:valuelist:002": "2.4G Беспроводной", + "service:002:property:002": "IP Адрес", + "service:002:property:003": "Название WiFi сети", + "service:002:property:004": "Текущее время", + "service:002:property:005": "MAC адрес DHCP сервера", + "service:003": "Световой индикатор", + "service:003:property:001": "Переключатель", + "service:004": "Виртуальная служба", + "service:004:action:001": "Создать виртуальное событие", + "service:004:event:001": "Произошло виртуальное событие", + "service:004:property:001": "Название события" + }, + "zh-Hant": { + "service:001": "設備信息", + "service:001:property:003": "設備ID", + "service:001:property:005": "序號 (SN)", + "service:002": "網關", + "service:002:event:001": "網路發生變化", + "service:002:event:002": "網路發生變化", + "service:002:property:001": "接入方式", + "service:002:property:001:valuelist:000": "有線", + "service:002:property:001:valuelist:001": "5G 無線", + "service:002:property:001:valuelist:002": "2.4G 無線", + "service:002:property:002": "IP地址", + "service:002:property:003": "WiFi網路名稱", + "service:002:property:004": "當前時間", + "service:002:property:005": "DHCP伺服器MAC地址", + "service:003": "指示燈", + "service:003:property:001": "開關", + "service:004": "虛擬服務", + "service:004:action:001": "產生虛擬事件", + "service:004:event:001": "虛擬事件發生", + "service:004:property:001": "事件名稱" + } + }, + "urn:miot-spec-v2:device:switch:0000A003:lumi-acn040": { + "en": { + "service:011": "Right Button On and Off", + "service:011:property:001": "Right Button On and Off", + "service:015:action:001": "Left Button Identify", + "service:016:action:001": "Middle Button Identify", + "service:017:action:001": "Right Button Identify" + }, + "zh-Hans": { + "service:015:action:001": "左键确认", + "service:016:action:001": "中键确认", + "service:017:action:001": "右键确认" + } + } +} \ No newline at end of file