lpp json : let caller tell how to serialize

This commit is contained in:
Florent 2025-05-21 11:03:07 +02:00
parent aa43afc3e7
commit ad87eac280

View file

@ -1,7 +1,7 @@
from cayennelpp import LppFrame, LppData
from cayennelpp.lpp_type import LppType
# type name "how to display vale"
# Format : type name "how to display value"
# display : None: (use lib default), []: only one value to display, ["field1", "field2" ...]: meaning of each field
my_lpp_types = {
0: ('digital input', []),
@ -33,7 +33,7 @@ my_lpp_types = {
142: ('switch', []),
}
def lpp_json_encoder (obj) :
def lpp_json_encoder (obj, types = my_lpp_types) :
"""Encode LppType, LppData, and LppFrame to JSON."""
if isinstance(obj, LppFrame):
return obj.data
@ -53,4 +53,4 @@ def lpp_json_encoder (obj) :
i = i + 1
d["value"] = val_dict
return d
raise TypeError(repr(obj) + " is not JSON serialized")
raise TypeError(repr(obj) + " is not JSON serialized")