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 machine
import time import time
import wifi import wifi
import json
async def main(): async def main():
settings = Settings() settings = Settings()
@ -31,7 +31,9 @@ async def main():
e.active(True) e.active(True)
async for mac, msg in e: async for mac, msg in e:
print(msg) print(msg)
settings.set_settings(msg, patterns) data = json.loads(msg)
settings.set_settings(data, patterns)
print("should not print") print("should not print")
async def wifi_connect(): async def wifi_connect():

View File

@ -48,9 +48,8 @@ class Settings(dict):
self.set_defaults() self.set_defaults()
self.save() self.save()
def set_settings(self, raw_json, patterns): def set_settings(self, data, patterns):
try: try:
data = json.loads(raw_json)
print(data) print(data)
for key, value in data.items(): for key, value in data.items():
print(key, value) print(key, value)

View File

@ -33,8 +33,9 @@ def web(settings, patterns):
while True: while True:
data = await ws.receive() data = await ws.receive()
if data: if data:
# Process the received 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) #await ws.send(status_code)
else: else:
break break