Files
HP_InHand_IG502/code snippets/receiveAttributeResponse.py
2023-12-14 13:16:36 -06:00

35 lines
963 B
Python

import json
from common.Logger import logger
from quickfaas.global_dict import get as get_params
from quickfaas.global_dict import _set_global_args
#v1/devices/me/attributes/response/+
def receiveAttributeResponse(topic, payload):
#All attributes were requested handle response
payload = json.loads(payload)
logger.info(topic)
logger.info(payload)
logger.info(payload["shared"].get("test"))
def updateConfig():
#get the stored config file and update the label with the new parameters
cfg = dict()
with open("/var/user/cfg/device_supervisor/device_supervisor.cfg", "r+") as f:
cfg = json.load(f)
labels = cfg.get("labels")
if labels:
labels = convertDStoJSON(labels)
def convertDStoJSON(ds):
j = dict()
for x in ds:
j[x["key"]] = x["value"]
return j
def convertJSONtoDS(j):
d = []
for key in j.keys():
d.append({"key": key, "value": j[key]})
return d