diff --git a/custom_components/xiaomi_home/config_flow.py b/custom_components/xiaomi_home/config_flow.py
index 1c3f12c..888b16e 100644
--- a/custom_components/xiaomi_home/config_flow.py
+++ b/custom_components/xiaomi_home/config_flow.py
@@ -1984,12 +1984,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')
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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..b12eff1 100644
--- a/custom_components/xiaomi_home/miot/web_pages.py
+++ b/custom_components/xiaomi_home/miot/web_pages.py
@@ -46,237 +46,24 @@ off Xiaomi or its affiliates' products.
MIoT redirect web pages.
"""
-# pylint: disable=line-too-long
+import os
+import asyncio
-def oauth_redirect_page(lang: str, status: str) -> str:
+_template = ""
+
+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:
+ global _template
+ _template = f.read()
+
+async def oauth_redirect_page(lang: str, status: str) -> str:
"""Return oauth redirect page."""
- return '''
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- '''
+ 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