From dbde931d361f68e5f5d8db228c255fca2ad8b0f6 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Sat, 11 Jan 2025 13:38:51 +0800 Subject: [PATCH] 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)