From c24f23e6a3056b2c86136c541c04100a187a8800 Mon Sep 17 00:00:00 2001 From: sworld Date: Mon, 30 Dec 2024 16:52:28 +0800 Subject: [PATCH] feat: check mqtt broker --- custom_components/xiaomi_home/config_flow.py | 16 ++++++++++++++++ .../xiaomi_home/translations/de.json | 3 ++- .../xiaomi_home/translations/en.json | 3 ++- .../xiaomi_home/translations/es.json | 3 ++- .../xiaomi_home/translations/fr.json | 3 ++- .../xiaomi_home/translations/ja.json | 3 ++- .../xiaomi_home/translations/nl.json | 3 ++- .../xiaomi_home/translations/pt-BR.json | 3 ++- .../xiaomi_home/translations/pt.json | 3 ++- .../xiaomi_home/translations/ru.json | 3 ++- .../xiaomi_home/translations/zh-Hans.json | 3 ++- .../xiaomi_home/translations/zh-Hant.json | 3 ++- 12 files changed, 38 insertions(+), 11 deletions(-) diff --git a/custom_components/xiaomi_home/config_flow.py b/custom_components/xiaomi_home/config_flow.py index bd6d938..07bc3bd 100644 --- a/custom_components/xiaomi_home/config_flow.py +++ b/custom_components/xiaomi_home/config_flow.py @@ -1756,6 +1756,22 @@ class OptionsFlowHandler(config_entries.OptionsFlow): return await self.__show_network_detect_config_form( reason='unreachable_spec_host') # MQTT Broker + # pylint: disable=import-outside-toplevel + try: + from paho.mqtt import client as mqtt + mqtt_client = mqtt.Client( + client_id=f'ha.{self._uid}', + protocol=mqtt.MQTTv5) + if mqtt_client.connect( + host=f'{self._cloud_server}-ha.mqtt.io.mi.com', + port=8883) != 0: + raise RuntimeError('mqtt connect error') + mqtt_client.disconnect() + del mqtt_client + except Exception as err: # pylint: disable=broad-exception-caught + _LOGGER.error('try connect mqtt broker error, %s', err) + return await self.__show_network_detect_config_form( + reason='unreachable_mqtt_broker') return await self.async_step_config_confirm() diff --git a/custom_components/xiaomi_home/translations/de.json b/custom_components/xiaomi_home/translations/de.json index a91834a..6ca4349 100644 --- a/custom_components/xiaomi_home/translations/de.json +++ b/custom_components/xiaomi_home/translations/de.json @@ -202,7 +202,8 @@ "invalid_default_addr": "Die Standard-Netzwerkerkennungsadresse ist nicht erreichbar, bitte überprüfen Sie die Netzwerkkonfiguration oder verwenden Sie eine benutzerdefinierte Netzwerkerkennungsadresse.", "unreachable_oauth2_host": "OAuth2-Authentifizierungsadresse ist nicht erreichbar, bitte überprüfen Sie die Netzwerkkonfiguration.", "unreachable_http_host": "Xiaomi HTTP API-Adresse ist nicht erreichbar, bitte überprüfen Sie die Netzwerkkonfiguration.", - "unreachable_spec_host": "Xiaomi SPEC API-Adresse ist nicht erreichbar, bitte überprüfen Sie die Netzwerkkonfiguration." + "unreachable_spec_host": "Xiaomi SPEC API-Adresse ist nicht erreichbar, bitte überprüfen Sie die Netzwerkkonfiguration.", + "unreachable_mqtt_broker": "Xiaomi MQTT Broker-Adresse ist nicht erreichbar, bitte überprüfen Sie die Netzwerkkonfiguration." }, "abort": { "network_connect_error": "Konfiguration fehlgeschlagen. Netzwerkverbindungsfehler. Überprüfen Sie die Netzwerkkonfiguration des Geräts.", diff --git a/custom_components/xiaomi_home/translations/en.json b/custom_components/xiaomi_home/translations/en.json index bb0d9b4..1b7e2d2 100644 --- a/custom_components/xiaomi_home/translations/en.json +++ b/custom_components/xiaomi_home/translations/en.json @@ -202,7 +202,8 @@ "invalid_default_addr": "Default network detection address is unreachable, please check network configuration or use a custom network detection address.", "unreachable_oauth2_host": "Unable to reach OAuth2 authentication address, please check network configuration.", "unreachable_http_host": "Unable to reach Xiaomi HTTP API address, please check network configuration.", - "unreachable_spec_host": "Unable to reach Xiaomi SPEC API address, please check network configuration." + "unreachable_spec_host": "Unable to reach Xiaomi SPEC API address, please check network configuration.", + "unreachable_mqtt_broker": "Unable to reach Xiaomi MQTT Broker address, please check network configuration." }, "abort": { "network_connect_error": "Configuration failed. The network connection is abnormal. Please check the equipment network configuration.", diff --git a/custom_components/xiaomi_home/translations/es.json b/custom_components/xiaomi_home/translations/es.json index a0ebdc8..965dce7 100644 --- a/custom_components/xiaomi_home/translations/es.json +++ b/custom_components/xiaomi_home/translations/es.json @@ -202,7 +202,8 @@ "invalid_default_addr": "La dirección de detección de red predeterminada no es accesible, por favor verifique la configuración de la red o use una dirección de detección de red personalizada.", "unreachable_oauth2_host": "No se puede acceder a la dirección de autenticación OAuth2, por favor verifique la configuración de la red.", "unreachable_http_host": "No se puede acceder a la dirección de la API HTTP de Xiaomi, por favor verifique la configuración de la red.", - "unreachable_spec_host": "No se puede acceder a la dirección de la API SPEC de Xiaomi, por favor verifique la configuración de la red." + "unreachable_spec_host": "No se puede acceder a la dirección de la API SPEC de Xiaomi, por favor verifique la configuración de la red.", + "unreachable_mqtt_broker": "No se puede acceder a la dirección del Broker MQTT de Xiaomi, por favor verifique la configuración de la red." }, "abort": { "network_connect_error": "La configuración ha fallado. Existe un problema con la conexión de red, verifique la configuración de red del dispositivo.", diff --git a/custom_components/xiaomi_home/translations/fr.json b/custom_components/xiaomi_home/translations/fr.json index 0392c4c..0c97ee5 100644 --- a/custom_components/xiaomi_home/translations/fr.json +++ b/custom_components/xiaomi_home/translations/fr.json @@ -202,7 +202,8 @@ "invalid_default_addr": "L'adresse de détection réseau par défaut est inaccessible, veuillez vérifier la configuration réseau ou utiliser une adresse de détection réseau personnalisée.", "unreachable_oauth2_host": "Impossible d'atteindre l'adresse d'authentification OAuth2, veuillez vérifier la configuration réseau.", "unreachable_http_host": "Impossible d'atteindre l'adresse de l'API HTTP de Xiaomi, veuillez vérifier la configuration réseau.", - "unreachable_spec_host": "Impossible d'atteindre l'adresse de l'API SPEC de Xiaomi, veuillez vérifier la configuration réseau." + "unreachable_spec_host": "Impossible d'atteindre l'adresse de l'API SPEC de Xiaomi, veuillez vérifier la configuration réseau.", + "unreachable_mqtt_broker": "Impossible d'atteindre l'adresse du Broker MQTT de Xiaomi, veuillez vérifier la configuration réseau." }, "abort": { "network_connect_error": "Échec de la configuration. Problème de connexion réseau, veuillez vérifier la configuration du périphérique.", diff --git a/custom_components/xiaomi_home/translations/ja.json b/custom_components/xiaomi_home/translations/ja.json index c412e49..66d2184 100644 --- a/custom_components/xiaomi_home/translations/ja.json +++ b/custom_components/xiaomi_home/translations/ja.json @@ -202,7 +202,8 @@ "invalid_default_addr": "デフォルトのネットワーク検出アドレスにアクセスできません。ネットワーク設定を確認するか、カスタムネットワーク検出アドレスを使用してください。", "unreachable_oauth2_host": "OAuth2 認証アドレスにアクセスできません。ネットワーク設定を確認してください。", "unreachable_http_host": "Xiaomi HTTP API アドレスにアクセスできません。ネットワーク設定を確認してください。", - "unreachable_spec_host": "Xiaomi SPEC API アドレスにアクセスできません。ネットワーク設定を確認してください。" + "unreachable_spec_host": "Xiaomi SPEC API アドレスにアクセスできません。ネットワーク設定を確認してください。", + "unreachable_mqtt_broker": "Xiaomi MQTT ブローカーアドレスにアクセスできません。ネットワーク設定を確認してください。" }, "abort": { "network_connect_error": "構成に失敗しました。ネットワーク接続に異常があります。デバイスのネットワーク構成を確認してください。", diff --git a/custom_components/xiaomi_home/translations/nl.json b/custom_components/xiaomi_home/translations/nl.json index 194b13e..4c42773 100644 --- a/custom_components/xiaomi_home/translations/nl.json +++ b/custom_components/xiaomi_home/translations/nl.json @@ -202,7 +202,8 @@ "invalid_default_addr": "Standaard netwerkdetectieadres is onbereikbaar, controleer de netwerkconfiguratie of gebruik een aangepast netwerkdetectieadres.", "unreachable_oauth2_host": "Kan OAuth2-authenticatieadres niet bereiken, controleer de netwerkconfiguratie.", "unreachable_http_host": "Kan Xiaomi HTTP API-adres niet bereiken, controleer de netwerkconfiguratie.", - "unreachable_spec_host": "Kan Xiaomi SPEC API-adres niet bereiken, controleer de netwerkconfiguratie." + "unreachable_spec_host": "Kan Xiaomi SPEC API-adres niet bereiken, controleer de netwerkconfiguratie.", + "unreachable_mqtt_broker": "Kan Xiaomi MQTT Broker-adres niet bereiken, controleer de netwerkconfiguratie." }, "abort": { "network_connect_error": "Configuratie mislukt. De netwerkverbinding is abnormaal. Controleer de netwerkinstellingen van de apparatuur.", diff --git a/custom_components/xiaomi_home/translations/pt-BR.json b/custom_components/xiaomi_home/translations/pt-BR.json index d761dd4..66a74fe 100644 --- a/custom_components/xiaomi_home/translations/pt-BR.json +++ b/custom_components/xiaomi_home/translations/pt-BR.json @@ -202,7 +202,8 @@ "invalid_default_addr": "O endereço de detecção de rede padrão está inacessível, por favor verifique a configuração da rede ou use um endereço de detecção de rede personalizado.", "unreachable_oauth2_host": "Não é possível acessar o endereço de autenticação OAuth2, verifique a configuração da rede.", "unreachable_http_host": "Não é possível acessar o endereço da API HTTP da Xiaomi, verifique a configuração da rede.", - "unreachable_spec_host": "Não é possível acessar o endereço da API SPEC da Xiaomi, verifique a configuração da rede." + "unreachable_spec_host": "Não é possível acessar o endereço da API SPEC da Xiaomi, verifique a configuração da rede.", + "unreachable_mqtt_broker": "Não é possível acessar o endereço do Broker MQTT da Xiaomi, verifique a configuração da rede." }, "abort": { "network_connect_error": "Configuração falhou. A conexão de rede está anormal. Verifique a configuração da rede do equipamento.", diff --git a/custom_components/xiaomi_home/translations/pt.json b/custom_components/xiaomi_home/translations/pt.json index ae78d6c..046d4bf 100644 --- a/custom_components/xiaomi_home/translations/pt.json +++ b/custom_components/xiaomi_home/translations/pt.json @@ -202,7 +202,8 @@ "invalid_default_addr": "O endereço de detecção de rede padrão está inacessível, por favor verifique a configuração da rede ou use um endereço de detecção de rede personalizado.", "unreachable_oauth2_host": "Não é possível acessar o endereço de autenticação OAuth2, verifique a configuração da rede.", "unreachable_http_host": "Não é possível acessar o endereço da API HTTP da Xiaomi, verifique a configuração da rede.", - "unreachable_spec_host": "Não é possível acessar o endereço da API SPEC da Xiaomi, verifique a configuração da rede." + "unreachable_spec_host": "Não é possível acessar o endereço da API SPEC da Xiaomi, verifique a configuração da rede.", + "unreachable_mqtt_broker": "Não é possível acessar o endereço do Broker MQTT da Xiaomi, verifique a configuração da rede." }, "abort": { "network_connect_error": "A configuração falhou. A ligação de rede é anormal. Verifique a configuração da rede do equipamento.", diff --git a/custom_components/xiaomi_home/translations/ru.json b/custom_components/xiaomi_home/translations/ru.json index 14aa470..3be3e02 100644 --- a/custom_components/xiaomi_home/translations/ru.json +++ b/custom_components/xiaomi_home/translations/ru.json @@ -202,7 +202,8 @@ "invalid_default_addr": "Адрес обнаружения сети по умолчанию недоступен, пожалуйста, проверьте конфигурацию сети или используйте пользовательский адрес обнаружения сети.", "unreachable_oauth2_host": "Не удается подключиться к адресу аутентификации OAuth2, проверьте настройки сети.", "unreachable_http_host": "Не удается подключиться к адресу HTTP API Xiaomi, проверьте настройки сети.", - "unreachable_spec_host": "Не удается подключиться к адресу SPEC API Xiaomi, проверьте настройки сети." + "unreachable_spec_host": "Не удается подключиться к адресу SPEC API Xiaomi, проверьте настройки сети.", + "unreachable_mqtt_broker": "Не удается подключиться к адресу MQTT брокера Xiaomi, проверьте настройки сети." }, "abort": { "network_connect_error": "Ошибка конфигурации. Сбой сетевого подключения. Проверьте настройки сети устройства.", diff --git a/custom_components/xiaomi_home/translations/zh-Hans.json b/custom_components/xiaomi_home/translations/zh-Hans.json index b6d3670..9ac2e2b 100644 --- a/custom_components/xiaomi_home/translations/zh-Hans.json +++ b/custom_components/xiaomi_home/translations/zh-Hans.json @@ -202,7 +202,8 @@ "invalid_default_addr": "默认网络检测地址无法访问,请检查网络配置或者使用自定义网络检测地址。", "unreachable_oauth2_host": "无法访问 OAuth2 认证地址,请检查网络配置。", "unreachable_http_host": "无法访问小米 HTTP API 地址,请检查网络配置。", - "unreachable_spec_host": "无法访问小米 SPEC API 地址,请检查网络配置。" + "unreachable_spec_host": "无法访问小米 SPEC API 地址,请检查网络配置。", + "unreachable_mqtt_broker": "无法访问小米 MQTT Broker 地址,请检查网络配置。" }, "abort": { "network_connect_error": "配置失败。网络连接异常,请检查设备网络配置。", diff --git a/custom_components/xiaomi_home/translations/zh-Hant.json b/custom_components/xiaomi_home/translations/zh-Hant.json index d9133c1..cbbe017 100644 --- a/custom_components/xiaomi_home/translations/zh-Hant.json +++ b/custom_components/xiaomi_home/translations/zh-Hant.json @@ -202,7 +202,8 @@ "invalid_default_addr": "默認網絡檢測地址無法訪問,請檢查網絡配置或者使用自定義網絡檢測地址。", "unreachable_oauth2_host": "無法訪問 OAuth2 認證地址,請檢查網絡配置。", "unreachable_http_host": "無法訪問小米 HTTP API 地址,請檢查網絡配置。", - "unreachable_spec_host": "無法訪問小米 SPEC API 地址,請檢查網絡配置。" + "unreachable_spec_host": "無法訪問小米 SPEC API 地址,請檢查網絡配置。", + "unreachable_mqtt_broker": "無法訪問小米 MQTT Broker 地址,請檢查網絡配置。" }, "abort": { "network_connect_error": "配置失敗。網絡連接異常,請檢查設備網絡配置。",