From 85a8331f61d24a8ee1450b96d591101a1707874b Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sun, 10 Mar 2024 23:13:58 +0000 Subject: [PATCH 1/4] web_server options_json bug in standalone fix --- src/emhass/web_server.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index e78413c9..d419ae8f 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -204,6 +204,7 @@ def action_call(action_name): args = parser.parse_args() use_options = os.getenv('USE_OPTIONS', default=False) + options = None #Obtain url and key from ENV or ARG (if any) hass_url = os.getenv("EMHASS_URL", default=args.url) @@ -214,18 +215,21 @@ def action_call(action_name): if key is None: key = "" if hass_url is None: hass_url = "" + #find env's, not not set defaults + CONFIG_PATH = os.getenv("CONFIG_PATH", default="/app/config_emhass.yaml") + OPTIONS_PATH = os.getenv('OPTIONS_PATH', default="/app/options.json") + DATA_PATH = os.getenv("DATA_PATH", default="/app/data/") + # Define the paths if args.addon==1: - OPTIONS_PATH = os.getenv('OPTIONS_PATH', default="/app/options.json") options_json = Path(OPTIONS_PATH) - CONFIG_PATH = os.getenv("CONFIG_PATH", default="/app/config_emhass.yaml") - DATA_PATH = os.getenv("DATA_PATH", default="/app/data/") # Read options info if options_json.exists(): with options_json.open('r') as data: options = json.load(data) else: - app.logger.error("options.json does not exists") + app.logger.error("options.json does not exist") + raise Exception("options.json does not exist in path: "+str(options_json)) else: if use_options: OPTIONS_PATH = os.getenv('OPTIONS_PATH', default="/app/options.json") @@ -235,12 +239,13 @@ def action_call(action_name): with options_json.open('r') as data: options = json.load(data) else: - app.logger.error("options.json does not exists") + app.logger.error("options.json does not exist") + raise Exception("options.json does not exist in path: "+str(options_json)) else: options = None #if data path specified by options.json - if options_json.exists(): + if options is not None: if options.get('data_path', None) != None and options.get('data_path', None) != "default": DATA_PATH = options.get('data_path', None); From 31a1b5ffa6ebf803abc0cb643e794307022f0477 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sun, 10 Mar 2024 23:16:34 +0000 Subject: [PATCH 2/4] web_server options env refined --- src/emhass/web_server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index d419ae8f..745133ec 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -204,7 +204,7 @@ def action_call(action_name): args = parser.parse_args() use_options = os.getenv('USE_OPTIONS', default=False) - options = None + options = None #options None by default #Obtain url and key from ENV or ARG (if any) hass_url = os.getenv("EMHASS_URL", default=args.url) @@ -232,7 +232,6 @@ def action_call(action_name): raise Exception("options.json does not exist in path: "+str(options_json)) else: if use_options: - OPTIONS_PATH = os.getenv('OPTIONS_PATH', default="/app/options.json") options_json = Path(OPTIONS_PATH) # Read options info if options_json.exists(): From afe12c0f8d0bd70a4037767aa877ede57d645323 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Mon, 11 Mar 2024 04:24:35 +0000 Subject: [PATCH 3/4] web_server, refined env order --- src/emhass/web_server.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index 745133ec..7080c44c 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -203,9 +203,6 @@ def action_call(action_name): parser.add_argument('--no_response', type=strtobool, default='False', help='This is set if json response errors occur') args = parser.parse_args() - use_options = os.getenv('USE_OPTIONS', default=False) - options = None #options None by default - #Obtain url and key from ENV or ARG (if any) hass_url = os.getenv("EMHASS_URL", default=args.url) key = os.getenv("SUPERVISOR_TOKEN", default=args.key) @@ -216,9 +213,13 @@ def action_call(action_name): if hass_url is None: hass_url = "" #find env's, not not set defaults + use_options = os.getenv('USE_OPTIONS', default=False) CONFIG_PATH = os.getenv("CONFIG_PATH", default="/app/config_emhass.yaml") OPTIONS_PATH = os.getenv('OPTIONS_PATH', default="/app/options.json") DATA_PATH = os.getenv("DATA_PATH", default="/app/data/") + + options = None #options None by default + # Define the paths if args.addon==1: From 7c7afeea62d016c026b71b4a34e7a69bafaaf52f Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Mon, 11 Mar 2024 04:25:56 +0000 Subject: [PATCH 4/4] web_server slight neaten --- src/emhass/web_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index 7080c44c..3f7099e2 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -218,8 +218,8 @@ def action_call(action_name): OPTIONS_PATH = os.getenv('OPTIONS_PATH', default="/app/options.json") DATA_PATH = os.getenv("DATA_PATH", default="/app/data/") - options = None #options None by default - + #options None by default + options = None # Define the paths if args.addon==1: