Move json load out of set_settings

This commit is contained in:
jimmy 2025-06-04 19:22:09 +12:00
parent c15f9787a7
commit 55ef5c1580
3 changed files with 7 additions and 5 deletions

View File

@ -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():

View File

@ -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)

View File

@ -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