From 1bac3d84b465d4a2c1a5b5e4725cff82c69e65c4 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 13:32:16 +0800 Subject: [PATCH 01/10] move web page to html --- .../miot/resource/oauth_redirect_page.html | 260 ++++++++++++++++++ .../xiaomi_home/miot/web_pages.py | 238 +--------------- 2 files changed, 267 insertions(+), 231 deletions(-) create mode 100644 custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html diff --git a/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html b/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html new file mode 100644 index 0000000..293819e --- /dev/null +++ b/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html @@ -0,0 +1,260 @@ + + + + + + + + + + + + +
+ +
+ + 编组 + Created with Sketch. + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ + +
+ + + + \ No newline at end of file diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index e4cde5a..97f2e6b 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -46,237 +46,13 @@ off Xiaomi or its affiliates' products. MIoT redirect web pages. """ -# pylint: disable=line-too-long +# preload the template +template = "" +with open("./resource/oauth_redirect_page.html", "r") as f: + template = f.read() def oauth_redirect_page(lang: str, status: str) -> str: """Return oauth redirect page.""" - return ''' - - - - - - - - - - -
- -
- 编组 - Created with Sketch. - - - - - - - - - - - - - - - - -
- -
- -
- -
- -
- - -
- - - - ''' + web_page = template.replace('LANG_PLACEHOLDER', lang) + web_page = web_page.replace('STATUS_PLACEHOLDER', status) + return web_page From dbde931d361f68e5f5d8db228c255fca2ad8b0f6 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 13:38:51 +0800 Subject: [PATCH 02/10] move loading into function --- custom_components/xiaomi_home/miot/web_pages.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index 97f2e6b..df63478 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -46,12 +46,12 @@ off Xiaomi or its affiliates' products. MIoT redirect web pages. """ -# preload the template template = "" -with open("./resource/oauth_redirect_page.html", "r") as f: - template = f.read() - def oauth_redirect_page(lang: str, status: str) -> str: + global template + if template == "": + with open("./resource/oauth_redirect_page.html", "r") as f: + template = f.read() """Return oauth redirect page.""" web_page = template.replace('LANG_PLACEHOLDER', lang) web_page = web_page.replace('STATUS_PLACEHOLDER', status) From 2f0c2278cc1b19dac49621e17d67957d09504544 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 13:59:07 +0800 Subject: [PATCH 03/10] make the loading async --- .../xiaomi_home/miot/web_pages.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index df63478..e2ee79b 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -46,13 +46,25 @@ off Xiaomi or its affiliates' products. MIoT redirect web pages. """ -template = "" -def oauth_redirect_page(lang: str, status: str) -> str: - global template - if template == "": - with open("./resource/oauth_redirect_page.html", "r") as f: - template = f.read() +import os +import asyncio + +_template = "" + +def __load_page_template(): + path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'resource/oauth_redirect_page.html') + global _template + with open(path, "r") as f: + _template = f.read() + +async def oauth_redirect_page(lang: str, status: str) -> str: """Return oauth redirect page.""" - web_page = template.replace('LANG_PLACEHOLDER', lang) + global template + if _template == "": + await asyncio.get_event_loop().run_in_executor( + None, __load_page_template) + web_page = _template.replace('LANG_PLACEHOLDER', lang) web_page = web_page.replace('STATUS_PLACEHOLDER', status) return web_page From 2f804421cf7283d050e84c215e887321471aefb7 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 14:04:06 +0800 Subject: [PATCH 04/10] fix usage --- custom_components/xiaomi_home/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/xiaomi_home/config_flow.py b/custom_components/xiaomi_home/config_flow.py index 8e48849..cb72c03 100644 --- a/custom_components/xiaomi_home/config_flow.py +++ b/custom_components/xiaomi_home/config_flow.py @@ -1991,12 +1991,12 @@ async def _handle_oauth_webhook(hass, webhook_id, request): _LOGGER.info('webhook code: %s', data['code']) return web.Response( - body=oauth_redirect_page( + body=await oauth_redirect_page( hass.config.language, 'success'), content_type='text/html') except MIoTConfigError: return web.Response( - body=oauth_redirect_page(hass.config.language, 'fail'), + body=await oauth_redirect_page(hass.config.language, 'fail'), content_type='text/html') From 43104736a6a9cbe5cbba26d9bd6f0c226c6a035d Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 14:11:30 +0800 Subject: [PATCH 05/10] Fix function naming --- custom_components/xiaomi_home/miot/web_pages.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index e2ee79b..ab11cf4 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -51,7 +51,7 @@ import asyncio _template = "" -def __load_page_template(): +def _load_page_template(): path = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'resource/oauth_redirect_page.html') @@ -64,7 +64,7 @@ async def oauth_redirect_page(lang: str, status: str) -> str: global template if _template == "": await asyncio.get_event_loop().run_in_executor( - None, __load_page_template) + None, _load_page_template) web_page = _template.replace('LANG_PLACEHOLDER', lang) web_page = web_page.replace('STATUS_PLACEHOLDER', status) return web_page From 7607cc3e32a8b812f7e5ea01dd342bff698af03c Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 14:19:36 +0800 Subject: [PATCH 06/10] fix lint --- custom_components/xiaomi_home/miot/web_pages.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index ab11cf4..e28ee38 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -54,17 +54,17 @@ _template = "" def _load_page_template(): path = os.path.join( os.path.dirname(os.path.abspath(__file__)), - 'resource/oauth_redirect_page.html') - global _template - with open(path, "r") as f: + "resource/oauth_redirect_page.html") + with open(path, "r", encoding='utf-8') as f: + global _template _template = f.read() async def oauth_redirect_page(lang: str, status: str) -> str: """Return oauth redirect page.""" - global template + global _template if _template == "": await asyncio.get_event_loop().run_in_executor( None, _load_page_template) - web_page = _template.replace('LANG_PLACEHOLDER', lang) - web_page = web_page.replace('STATUS_PLACEHOLDER', status) + web_page = _template.replace("LANG_PLACEHOLDER", lang) + web_page = web_page.replace("STATUS_PLACEHOLDER", status) return web_page From d9a9edd42da54bd43a59dbb8f71d1de0bf2c8b1b Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 14:27:04 +0800 Subject: [PATCH 07/10] fix lint --- custom_components/xiaomi_home/miot/web_pages.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index e28ee38..b12eff1 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -55,13 +55,12 @@ def _load_page_template(): path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "resource/oauth_redirect_page.html") - with open(path, "r", encoding='utf-8') as f: + with open(path, "r", encoding="utf-8") as f: global _template _template = f.read() async def oauth_redirect_page(lang: str, status: str) -> str: """Return oauth redirect page.""" - global _template if _template == "": await asyncio.get_event_loop().run_in_executor( None, _load_page_template) From d64f6da78ed26d883586a5568d5bdcd7a81012ec Mon Sep 17 00:00:00 2001 From: topsworld Date: Mon, 13 Jan 2025 18:08:39 +0800 Subject: [PATCH 08/10] feat: use get_running_loop replace get_event_loop --- custom_components/xiaomi_home/miot/web_pages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/xiaomi_home/miot/web_pages.py b/custom_components/xiaomi_home/miot/web_pages.py index b12eff1..6be3a39 100644 --- a/custom_components/xiaomi_home/miot/web_pages.py +++ b/custom_components/xiaomi_home/miot/web_pages.py @@ -51,6 +51,7 @@ import asyncio _template = "" + def _load_page_template(): path = os.path.join( os.path.dirname(os.path.abspath(__file__)), @@ -59,10 +60,11 @@ def _load_page_template(): global _template _template = f.read() + async def oauth_redirect_page(lang: str, status: str) -> str: """Return oauth redirect page.""" if _template == "": - await asyncio.get_event_loop().run_in_executor( + await asyncio.get_running_loop().run_in_executor( None, _load_page_template) web_page = _template.replace("LANG_PLACEHOLDER", lang) web_page = web_page.replace("STATUS_PLACEHOLDER", status) From 820d5e1e1b1c0b3fb2dff0876af9097f0c019a88 Mon Sep 17 00:00:00 2001 From: topsworld Date: Mon, 13 Jan 2025 22:18:21 +0800 Subject: [PATCH 09/10] feat: translate using the i18n module --- custom_components/xiaomi_home/config_flow.py | 53 ++++++- .../xiaomi_home/miot/i18n/de.json | 16 ++ .../xiaomi_home/miot/i18n/en.json | 16 ++ .../xiaomi_home/miot/i18n/es.json | 16 ++ .../xiaomi_home/miot/i18n/fr.json | 16 ++ .../xiaomi_home/miot/i18n/ja.json | 16 ++ .../xiaomi_home/miot/i18n/nl.json | 16 ++ .../xiaomi_home/miot/i18n/pt-BR.json | 16 ++ .../xiaomi_home/miot/i18n/pt.json | 16 ++ .../xiaomi_home/miot/i18n/ru.json | 16 ++ .../xiaomi_home/miot/i18n/zh-Hans.json | 16 ++ .../xiaomi_home/miot/i18n/zh-Hant.json | 16 ++ .../xiaomi_home/miot/miot_error.py | 2 + .../miot/resource/oauth_redirect_page.html | 140 +----------------- .../xiaomi_home/miot/web_pages.py | 19 ++- 15 files changed, 243 insertions(+), 147 deletions(-) diff --git a/custom_components/xiaomi_home/config_flow.py b/custom_components/xiaomi_home/config_flow.py index 888b16e..5b78c27 100644 --- a/custom_components/xiaomi_home/config_flow.py +++ b/custom_components/xiaomi_home/config_flow.py @@ -91,7 +91,8 @@ from .miot.miot_cloud import MIoTHttpClient, MIoTOauthClient from .miot.miot_storage import MIoTStorage, MIoTCert from .miot.miot_mdns import MipsService from .miot.web_pages import oauth_redirect_page -from .miot.miot_error import MIoTConfigError, MIoTError, MIoTOauthError +from .miot.miot_error import ( + MIoTConfigError, MIoTError, MIoTErrorCode, MIoTOauthError) from .miot.miot_i18n import MIoTI18n from .miot.miot_network import MIoTNetwork from .miot.miot_client import MIoTClient, get_miot_instance_async @@ -430,6 +431,8 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): redirect_url=self._oauth_redirect_url_full) self.hass.data[DOMAIN][self._virtual_did]['oauth_state'] = ( miot_oauth.state) + self.hass.data[DOMAIN][self._virtual_did]['i18n'] = ( + self._miot_i18n) _LOGGER.info( 'async_step_oauth, oauth_url: %s', self._cc_oauth_auth_url) webhook_async_unregister( @@ -1152,6 +1155,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow): redirect_url=self._oauth_redirect_url_full) self.hass.data[DOMAIN][self._virtual_did]['oauth_state'] = ( self._miot_oauth.state) + self.hass.data[DOMAIN][self._virtual_did]['i18n'] = ( + self._miot_i18n) _LOGGER.info( 'async_step_oauth, oauth_url: %s', self._cc_oauth_auth_url) webhook_async_unregister( @@ -1967,29 +1972,61 @@ class OptionsFlowHandler(config_entries.OptionsFlow): async def _handle_oauth_webhook(hass, webhook_id, request): """Webhook to handle oauth2 callback.""" # pylint: disable=inconsistent-quotes + i18n: MIoTI18n = hass.data[DOMAIN][webhook_id].get('i18n', None) try: data = dict(request.query) if data.get('code', None) is None or data.get('state', None) is None: - raise MIoTConfigError('invalid oauth code') + raise MIoTConfigError( + 'invalid oauth code or state', + MIoTErrorCode.CODE_CONFIG_INVALID_INPUT) if data['state'] != hass.data[DOMAIN][webhook_id]['oauth_state']: raise MIoTConfigError( - f'invalid oauth state, ' - f'{hass.data[DOMAIN][webhook_id]["oauth_state"]}, ' - f'{data["state"]}') + f'inconsistent state, ' + f'{hass.data[DOMAIN][webhook_id]["oauth_state"]}!=' + f'{data["state"]}', MIoTErrorCode.CODE_CONFIG_INVALID_STATE) fut_oauth_code: asyncio.Future = hass.data[DOMAIN][webhook_id].pop( 'fut_oauth_code', None) fut_oauth_code.set_result(data['code']) _LOGGER.info('webhook code: %s', data['code']) + success_trans: dict = {} + if i18n: + success_trans = i18n.translate( + 'oauth2.success') or {} # type: ignore + # Delete + del hass.data[DOMAIN][webhook_id]['oauth_state'] + del hass.data[DOMAIN][webhook_id]['i18n'] return web.Response( body=await oauth_redirect_page( - hass.config.language, 'success'), content_type='text/html') + title=success_trans.get('title', 'Success'), + content=success_trans.get( + 'content', ( + 'Please close this page and return to the account ' + 'authentication page to click NEXT')), + button=success_trans.get('button', 'Close Page'), + success=True, + ), content_type='text/html') - except MIoTConfigError: + except Exception as err: # pylint: disable=broad-exception-caught + fail_trans: dict = {} + err_msg: str = str(err) + if i18n: + if isinstance(err, MIoTConfigError): + err_msg = i18n.translate( + f'oauth2.error_msg.{err.code.value}' + ) or err.message # type: ignore + fail_trans = i18n.translate('oauth2.fail') or {} # type: ignore return web.Response( - body=await oauth_redirect_page(hass.config.language, 'fail'), + body=await oauth_redirect_page( + title=fail_trans.get('title', 'Authentication Failed'), + content=str(fail_trans.get('content', ( + '{error_msg}, Please close this page and return to the ' + 'account authentication page to click the authentication ' + 'link again.'))).replace('{error_msg}', err_msg), + button=fail_trans.get('button', 'Close Page'), + success=False), content_type='text/html') diff --git a/custom_components/xiaomi_home/miot/i18n/de.json b/custom_components/xiaomi_home/miot/i18n/de.json index 81fb203..9dce0e9 100644 --- a/custom_components/xiaomi_home/miot/i18n/de.json +++ b/custom_components/xiaomi_home/miot/i18n/de.json @@ -64,6 +64,22 @@ "net_unavailable": "Schnittstelle nicht verfügbar" } }, + "oauth2": { + "success": { + "title": "Authentifizierung erfolgreich", + "content": "Bitte schließen Sie diese Seite und kehren Sie zur Kontoauthentifizierungsseite zurück, um auf „Weiter“ zu klicken.", + "button": "Schließen" + }, + "fail": { + "title": "Authentifizierung fehlgeschlagen", + "content": "{error_msg}, bitte schließen Sie diese Seite und kehren Sie zur Kontoauthentifizierungsseite zurück, um den Authentifizierungslink erneut zu klicken.", + "button": "Schließen" + }, + "error_msg": { + "-10100": "Ungültige Antwortparameter ('code' oder 'state' Feld ist leer)", + "-10101": "Übergebenes 'state' Feld stimmt nicht überein" + } + }, "miot": { "client": { "invalid_oauth_info": "Ungültige Authentifizierungsinformationen, Cloud-Verbindung nicht verfügbar, bitte betreten Sie die Xiaomi Home-Integrationsseite und klicken Sie auf 'Optionen', um die Authentifizierung erneut durchzuführen", diff --git a/custom_components/xiaomi_home/miot/i18n/en.json b/custom_components/xiaomi_home/miot/i18n/en.json index 219b276..7cf0ecb 100644 --- a/custom_components/xiaomi_home/miot/i18n/en.json +++ b/custom_components/xiaomi_home/miot/i18n/en.json @@ -64,6 +64,22 @@ "net_unavailable": "Interface unavailable" } }, + "oauth2": { + "success": { + "title": "Authentication Successful", + "content": "Please close this page and return to the account authentication page to click 'Next'.", + "button": "Close" + }, + "fail": { + "title": "Authentication Failed", + "content": "{error_msg}, please close this page and return to the account authentication page to click the authentication link again.", + "button": "Close" + }, + "error_msg": { + "-10100": "Invalid response parameters ('code' or 'state' field is empty)", + "-10101": "Passed-in 'state' field mismatch" + } + }, "miot": { "client": { "invalid_oauth_info": "Authentication information is invalid, cloud link will be unavailable, please enter the Xiaomi Home integration page, click 'Options' to re-authenticate", diff --git a/custom_components/xiaomi_home/miot/i18n/es.json b/custom_components/xiaomi_home/miot/i18n/es.json index 49a6ea6..a71312f 100644 --- a/custom_components/xiaomi_home/miot/i18n/es.json +++ b/custom_components/xiaomi_home/miot/i18n/es.json @@ -64,6 +64,22 @@ "net_unavailable": "Interfaz no disponible" } }, + "oauth2": { + "success": { + "title": "Autenticación exitosa", + "content": "Por favor, cierre esta página y regrese a la página de autenticación de la cuenta para hacer clic en 'Siguiente'.", + "button": "Cerrar" + }, + "fail": { + "title": "Autenticación fallida", + "content": "{error_msg}, por favor, cierre esta página y regrese a la página de autenticación de la cuenta para hacer clic en el enlace de autenticación nuevamente.", + "button": "Cerrar" + }, + "error_msg": { + "-10100": "Parámetros de respuesta inválidos ('code' o 'state' está vacío)", + "-10101": "El campo 'state' proporcionado no coincide" + } + }, "miot": { "client": { "invalid_oauth_info": "La información de autenticación es inválida, la conexión en la nube no estará disponible, por favor, vaya a la página de integración de Xiaomi Home, haga clic en 'Opciones' para volver a autenticar", diff --git a/custom_components/xiaomi_home/miot/i18n/fr.json b/custom_components/xiaomi_home/miot/i18n/fr.json index 40feb65..e64b614 100644 --- a/custom_components/xiaomi_home/miot/i18n/fr.json +++ b/custom_components/xiaomi_home/miot/i18n/fr.json @@ -64,6 +64,22 @@ "net_unavailable": "Interface non disponible" } }, + "oauth2": { + "success": { + "title": "Authentification réussie", + "content": "Veuillez fermer cette page et revenir à la page d'authentification du compte pour cliquer sur 'Suivant'.", + "button": "Fermer" + }, + "fail": { + "title": "Échec de l'authentification", + "content": "{error_msg}, veuillez fermer cette page et revenir à la page d'authentification du compte pour cliquer à nouveau sur le lien d'authentification.", + "button": "Fermer" + }, + "error_msg": { + "-10100": "Paramètres de réponse invalides ('code' ou 'state' est vide)", + "-10101": "Le champ 'state' transmis ne correspond pas" + } + }, "miot": { "client": { "invalid_oauth_info": "Informations d'authentification non valides, le lien cloud ne sera pas disponible, veuillez accéder à la page d'intégration Xiaomi Home, cliquez sur \"Options\" pour vous réauthentifier", diff --git a/custom_components/xiaomi_home/miot/i18n/ja.json b/custom_components/xiaomi_home/miot/i18n/ja.json index 3ffc22a..087467c 100644 --- a/custom_components/xiaomi_home/miot/i18n/ja.json +++ b/custom_components/xiaomi_home/miot/i18n/ja.json @@ -64,6 +64,22 @@ "net_unavailable": "インターフェースが利用できません" } }, + "oauth2": { + "success": { + "title": "認証成功", + "content": "このページを閉じて、アカウント認証ページに戻り、「次へ」をクリックしてください。", + "button": "閉じる" + }, + "fail": { + "title": "認証失敗", + "content": "{error_msg}、このページを閉じて、アカウント認証ページに戻り、再度認証リンクをクリックしてください。", + "button": "閉じる" + }, + "error_msg": { + "-10100": "無効な応答パラメータ('code'または'state'フィールドが空です)", + "-10101": "渡された'state'フィールドが一致しません" + } + }, "miot": { "client": { "invalid_oauth_info": "認証情報が無効です。クラウドリンクは利用できません。Xiaomi Home統合ページに入り、[オプション]をクリックして再認証してください", diff --git a/custom_components/xiaomi_home/miot/i18n/nl.json b/custom_components/xiaomi_home/miot/i18n/nl.json index 101ff3a..d71e90e 100644 --- a/custom_components/xiaomi_home/miot/i18n/nl.json +++ b/custom_components/xiaomi_home/miot/i18n/nl.json @@ -64,6 +64,22 @@ "net_unavailable": "Interface niet beschikbaar" } }, + "oauth2": { + "success": { + "title": "Authenticatie geslaagd", + "content": "Sluit deze pagina en ga terug naar de accountauthenticatiepagina om op 'Volgende' te klikken.", + "button": "Sluiten" + }, + "fail": { + "title": "Authenticatie mislukt", + "content": "{error_msg}, sluit deze pagina en ga terug naar de accountauthenticatiepagina om opnieuw op de authenticatielink te klikken.", + "button": "Sluiten" + }, + "error_msg": { + "-10100": "Ongeldige antwoordparameters ('code' of 'state' veld is leeg)", + "-10101": "Doorgegeven 'state' veld komt niet overeen" + } + }, "miot": { "client": { "invalid_oauth_info": "Authenticatie-informatie is ongeldig, cloudverbinding zal niet beschikbaar zijn. Ga naar de Xiaomi Home-integratiepagina en klik op 'Opties' om opnieuw te verifiëren.", diff --git a/custom_components/xiaomi_home/miot/i18n/pt-BR.json b/custom_components/xiaomi_home/miot/i18n/pt-BR.json index 8e37ecb..0364f7d 100644 --- a/custom_components/xiaomi_home/miot/i18n/pt-BR.json +++ b/custom_components/xiaomi_home/miot/i18n/pt-BR.json @@ -64,6 +64,22 @@ "net_unavailable": "Interface indisponível" } }, + "oauth2": { + "success": { + "title": "Autenticação bem-sucedida", + "content": "Por favor, feche esta página e volte para a página de autenticação da conta para clicar em 'Próximo'.", + "button": "Fechar" + }, + "fail": { + "title": "Falha na autenticação", + "content": "{error_msg}, por favor, feche esta página e volte para a página de autenticação da conta para clicar no link de autenticação novamente.", + "button": "Fechar" + }, + "error_msg": { + "-10100": "Parâmetros de resposta inválidos ('code' ou 'state' está vazio)", + "-10101": "O campo 'state' fornecido não corresponde" + } + }, "miot": { "client": { "invalid_oauth_info": "Informações de autenticação inválidas, a conexão com a nuvem estará indisponível. Vá para a página de integração do Xiaomi Home e clique em 'Opções' para reautenticar.", diff --git a/custom_components/xiaomi_home/miot/i18n/pt.json b/custom_components/xiaomi_home/miot/i18n/pt.json index 08afe4d..d02180f 100644 --- a/custom_components/xiaomi_home/miot/i18n/pt.json +++ b/custom_components/xiaomi_home/miot/i18n/pt.json @@ -64,6 +64,22 @@ "net_unavailable": "Interface indisponível" } }, + "oauth2": { + "success": { + "title": "Autenticação bem-sucedida", + "content": "Por favor, feche esta página e volte para a página de autenticação da conta para clicar em 'Seguinte'.", + "button": "Fechar" + }, + "fail": { + "title": "Falha na autenticação", + "content": "{error_msg}, por favor, feche esta página e volte para a página de autenticação da conta para clicar no link de autenticação novamente.", + "button": "Fechar" + }, + "error_msg": { + "-10100": "Parâmetros de resposta inválidos ('code' ou 'state' está vazio)", + "-10101": "O campo 'state' fornecido não corresponde" + } + }, "miot": { "client": { "invalid_oauth_info": "Informações de autenticação inválidas, a conexão na nuvem ficará indisponível. Por favor, acesse a página de integração do Xiaomi Home e clique em 'Opções' para autenticar novamente.", diff --git a/custom_components/xiaomi_home/miot/i18n/ru.json b/custom_components/xiaomi_home/miot/i18n/ru.json index d018603..7065c39 100644 --- a/custom_components/xiaomi_home/miot/i18n/ru.json +++ b/custom_components/xiaomi_home/miot/i18n/ru.json @@ -64,6 +64,22 @@ "net_unavailable": "Интерфейс недоступен" } }, + "oauth2": { + "success": { + "title": "Аутентификация успешна", + "content": "Пожалуйста, закройте эту страницу и вернитесь на страницу аутентификации учетной записи, чтобы нажать 'Далее'.", + "button": "Закрыть" + }, + "fail": { + "title": "Аутентификация не удалась", + "content": "{error_msg}, пожалуйста, закройте эту страницу и вернитесь на страницу аутентификации учетной записи, чтобы снова нажать на ссылку аутентификации.", + "button": "Закрыть" + }, + "error_msg": { + "-10100": "Недействительные параметры ответа ('code' или 'state' поле пусто)", + "-10101": "Переданное поле 'state' не совпадает" + } + }, "miot": { "client": { "invalid_oauth_info": "Информация об аутентификации недействительна, облако будет недоступно, пожалуйста, войдите на страницу интеграции Xiaomi Home, нажмите 'Опции' для повторной аутентификации", diff --git a/custom_components/xiaomi_home/miot/i18n/zh-Hans.json b/custom_components/xiaomi_home/miot/i18n/zh-Hans.json index d8f7c8a..3d47d2a 100644 --- a/custom_components/xiaomi_home/miot/i18n/zh-Hans.json +++ b/custom_components/xiaomi_home/miot/i18n/zh-Hans.json @@ -64,6 +64,22 @@ "net_unavailable": "接口不可用" } }, + "oauth2": { + "success": { + "title": "认证成功", + "content": "请关闭此页面,返回账号认证页面点击“下一步”", + "button": "关闭" + }, + "fail": { + "title": "认证失败", + "content": "{error_msg},请关闭此页面,返回账号认证页面重新点击认链接进行认证。", + "button": "关闭" + }, + "error_msg": { + "-10100": "无效的响应参数(“code”或者“state”字段为空)", + "-10101": "传入“state”字段不一致" + } + }, "miot": { "client": { "invalid_oauth_info": "认证信息失效,云端链路将不可用,请进入 Xiaomi Home 集成页面,点击“选项”重新认证", diff --git a/custom_components/xiaomi_home/miot/i18n/zh-Hant.json b/custom_components/xiaomi_home/miot/i18n/zh-Hant.json index 73bfa98..644b0e0 100644 --- a/custom_components/xiaomi_home/miot/i18n/zh-Hant.json +++ b/custom_components/xiaomi_home/miot/i18n/zh-Hant.json @@ -64,6 +64,22 @@ "net_unavailable": "接口不可用" } }, + "oauth2": { + "success": { + "title": "認證成功", + "content": "請關閉此頁面,返回帳號認證頁面點擊“下一步”", + "button": "關閉" + }, + "fail": { + "title": "認證失敗", + "content": "{error_msg},請關閉此頁面,返回帳號認證頁面重新點擊認鏈接進行認證。", + "button": "關閉" + }, + "error_msg": { + "-10100": "無效的響應參數('code'或者'state'字段為空)", + "-10101": "傳入的'state'字段不一致" + } + }, "miot": { "client": { "invalid_oauth_info": "認證信息失效,雲端鏈路將不可用,請進入 Xiaomi Home 集成頁面,點擊“選項”重新認證", diff --git a/custom_components/xiaomi_home/miot/miot_error.py b/custom_components/xiaomi_home/miot/miot_error.py index 6e65ad8..e32103e 100644 --- a/custom_components/xiaomi_home/miot/miot_error.py +++ b/custom_components/xiaomi_home/miot/miot_error.py @@ -72,6 +72,8 @@ class MIoTErrorCode(Enum): # MIoT ev error code, -10080 # Mips service error code, -10090 # Config flow error code, -10100 + CODE_CONFIG_INVALID_INPUT = -10100 + CODE_CONFIG_INVALID_STATE = -10101 # Options flow error code , -10110 # MIoT lan error code, -10120 CODE_LAN_UNAVAILABLE = -10120 diff --git a/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html b/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html index 293819e..1205f10 100644 --- a/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html +++ b/custom_components/xiaomi_home/miot/resource/oauth_redirect_page.html @@ -7,7 +7,7 @@ - + TITLE_PLACEHOLDER