Fix saving and loading device params in config files

This commit is contained in:
Daniel Markstedt 2021-09-20 10:46:48 -07:00
parent ef28a5b491
commit 1cd5e8cea1

View File

@ -136,7 +136,7 @@ def write_config(file_name):
if device["block_size"] == 0: if device["block_size"] == 0:
device["block_size"] = None device["block_size"] = None
# Convert to a data type that can be serialized # Convert to a data type that can be serialized
device["params"] = list(device["params"]) device["params"] = dict(device["params"])
dump(devices, json_file, indent=4) dump(devices, json_file, indent=4)
return {"status": True, "msg": f"Successfully wrote to file: {file_name}"} return {"status": True, "msg": f"Successfully wrote to file: {file_name}"}
except (IOError, ValueError, EOFError, TypeError) as e: except (IOError, ValueError, EOFError, TypeError) as e:
@ -155,10 +155,14 @@ def read_config(file_name):
detach_all() detach_all()
devices = load(json_file) devices = load(json_file)
for row in devices: for row in devices:
process = attach_image(row["id"], device_type=row["device_type"], \ kwargs = {"device_type": row["device_type"], \
image=row["image"], unit=int(row["un"]), \ "image": row["image"], "unit": int(row["un"]), \
params=row["params"], vendor=row["vendor"], product=row["product"], \ "vendor": row["vendor"], "product": row["product"], \
revision=row["revision"], block_size=row["block_size"]) "revision": row["revision"], "block_size": row["block_size"]}
params = dict(row["params"])
for p in params.keys():
kwargs[p] = params[p]
process = attach_image(row["id"], **kwargs)
if process["status"] == True: if process["status"] == True:
return {"status": process["status"], "msg": f"Successfully read from file: {file_name}"} return {"status": process["status"], "msg": f"Successfully read from file: {file_name}"}
else: else: