From 7ff02f5dc762f0941adf2ef3b0565cee670597df Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Sun, 5 Jun 2022 09:23:01 +0200 Subject: [PATCH] fix path --- apps/nspanel-lovelace-ui/luibackend/localization.py | 13 +++++++------ apps/nspanel-lovelace-ui/luibackend/pages.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/nspanel-lovelace-ui/luibackend/localization.py b/apps/nspanel-lovelace-ui/luibackend/localization.py index 183049ed..b278aa73 100644 --- a/apps/nspanel-lovelace-ui/luibackend/localization.py +++ b/apps/nspanel-lovelace-ui/luibackend/localization.py @@ -14,13 +14,14 @@ def build_locale_filestring(locale): locale = locale.split("_")[0] filename = f"{locale}.json" - path_frontend_file = os.path.join(os.getcwd(), "translations", "frontend", filename) - path_backend_file = os.path.join(os.getcwd(), "translations", "backend" , filename) + dir_path = os.path.dirname(os.path.realpath(__file__)) + path_frontend_file = os.path.join(dir_path, "translations", "frontend", filename) + path_backend_file = os.path.join(dir_path, "translations", "backend" , filename) return path_frontend_file, path_backend_file def lookup(path_frontend_file, path_backend_file, lookupstr): if not (os.path.exists(path_frontend_file) and os.path.exists(path_backend_file)): - return "error" + return "error_fnf" with open(path_frontend_file, 'r') as f, open(path_backend_file, 'r') as b: translations = { "frontend": json.load(f), "backend": json.load(b)} res = translations @@ -28,15 +29,15 @@ def lookup(path_frontend_file, path_backend_file, lookupstr): if k in res: res = res[k] if type(res) is not str: - res = "error" + res = "error_tnf" return res def get_translation(locale, lookupstr): path_frontend_file, path_backend_file = build_locale_filestring(locale) res = lookup(path_frontend_file, path_backend_file, lookupstr) - if res == "error": + if res.startswith("error"): path_frontend_file, path_backend_file = build_locale_filestring("en_US") res = lookup(path_frontend_file, path_backend_file, lookupstr) return res -#print(get_translation("en_US", "frontend.state_attributes.climate.hvac_action.idle")) \ No newline at end of file +#print(get_translation("en_US", "frontend.state_attributes.climate.hvac_action.idle")) \ No newline at end of file diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py index 5c8edadd..a70468a7 100644 --- a/apps/nspanel-lovelace-ui/luibackend/pages.py +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -287,7 +287,7 @@ class LuiPagesGen(object): current_temp = get_attr_safe(entity, "current_temperature", "") dest_temp = int(get_attr_safe(entity, "temperature", 0)*10) - hvac_action = get_attr_safe(entity, "hvac_action", "") + hvac_action = get_attr_safe(entity, "hvac_action", "") state_value = "" if hvac_action != "": state_value = get_translation(self._locale, f"frontend.state_attributes.climate.hvac_action.{hvac_action}")