From 55ef5c1580e5f49b838a5127fd6a08a82b0ffb64 Mon Sep 17 00:00:00 2001 From: jimmy Date: Wed, 4 Jun 2025 19:22:09 +1200 Subject: [PATCH] Move json load out of set_settings --- src/main.py | 6 ++++-- src/settings.py | 3 +-- src/web.py | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index c6bd8df..6e2a194 100644 --- a/src/main.py +++ b/src/main.py @@ -8,7 +8,7 @@ import utime import machine import time import wifi - +import json async def main(): settings = Settings() @@ -31,7 +31,9 @@ async def main(): e.active(True) async for mac, msg in e: print(msg) - settings.set_settings(msg, patterns) + data = json.loads(msg) + + settings.set_settings(data, patterns) print("should not print") async def wifi_connect(): diff --git a/src/settings.py b/src/settings.py index 625f857..4c314d3 100644 --- a/src/settings.py +++ b/src/settings.py @@ -48,9 +48,8 @@ class Settings(dict): self.set_defaults() self.save() - def set_settings(self, raw_json, patterns): + def set_settings(self, data, patterns): try: - data = json.loads(raw_json) print(data) for key, value in data.items(): print(key, value) diff --git a/src/web.py b/src/web.py index aba0213..67b7440 100644 --- a/src/web.py +++ b/src/web.py @@ -33,8 +33,9 @@ def web(settings, patterns): while True: data = await ws.receive() if data: + # Process the received data - _, status_code = settings.set_settings(data, patterns) + _, status_code = settings.set_settings(json.loads(data), patterns) #await ws.send(status_code) else: break