From bd5e34e64fdc79cbb2ddbea07ad1557304c60044 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 13 Dec 2023 19:57:05 +0200 Subject: [PATCH] treewide: optimize build_msg --- app/internal/was.py | 8 +++----- app/main.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/internal/was.py b/app/internal/was.py index adef01e..bf0d544 100644 --- a/app/internal/was.py +++ b/app/internal/was.py @@ -36,7 +36,7 @@ def build_msg(config, container): try: - msg = json.dumps({container: json.loads(config)}, sort_keys=True) + msg = json.dumps({container: config}, sort_keys=True) return msg except Exception as e: log.error(f"Failed to build config message: {e}") @@ -314,7 +314,7 @@ async def post_config(request, apply=False): if 'hostname' in data: hostname = data["hostname"] data = get_config_db() - msg = build_msg(json.dumps(data), "config") + msg = build_msg(data, "config") try: ws = request.app.connmgr.get_client_by_hostname(hostname) await ws.send_text(msg) @@ -329,7 +329,6 @@ async def post_config(request, apply=False): log.debug(f"wis_tts_url_v2: {data['wis_tts_url_v2']}") save_config_to_db(data) - data = json.dumps(data) msg = build_msg(data, "config") log.debug(str(msg)) if apply: @@ -342,7 +341,7 @@ async def post_nvs(request, apply=False): if 'hostname' in data: hostname = data["hostname"] data = get_nvs_db() - msg = build_msg(json.dumps(data), "nvs") + msg = build_msg(data, "nvs") try: ws = request.app.connmgr.get_client_by_hostname(hostname) await ws.send_text(msg) @@ -352,7 +351,6 @@ async def post_nvs(request, apply=False): return "Error" else: save_nvs_to_db(data) - data = json.dumps(data) msg = build_msg(data, "nvs") log.debug(str(msg)) if apply: diff --git a/app/main.py b/app/main.py index 33a1326..c2b3c2d 100644 --- a/app/main.py +++ b/app/main.py @@ -238,7 +238,7 @@ async def websocket_endpoint( log.error("WAS Command Endpoint not active") elif msg["cmd"] == "get_config": - asyncio.ensure_future(websocket.send_text(build_msg(json.dumps(get_config_db()), "config"))) + asyncio.ensure_future(websocket.send_text(build_msg(get_config_db(), "config"))) elif "goodbye" in msg: app.connmgr.disconnect(websocket)