From 661efa48f091f4279098c99cfb4e942e2b8d1b51 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 6 Mar 2024 12:09:12 +0100 Subject: [PATCH] senml: Use the updated cbor2 API. Signed-off-by: iabdalkader --- micropython/senml/examples/basic_cbor.py | 4 ++-- micropython/senml/manifest.py | 2 +- micropython/senml/senml/senml_pack.py | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/micropython/senml/examples/basic_cbor.py b/micropython/senml/examples/basic_cbor.py index f5e92af..804a886 100644 --- a/micropython/senml/examples/basic_cbor.py +++ b/micropython/senml/examples/basic_cbor.py @@ -26,7 +26,7 @@ THE SOFTWARE. from senml import * import time -from cbor2 import decoder +import cbor2 pack = SenmlPack("device_name") @@ -38,5 +38,5 @@ while True: cbor_val = pack.to_cbor() print(cbor_val) print(cbor_val.hex()) - print(decoder.loads(cbor_val)) # convert to string again so we can print it. + print(cbor2.loads(cbor_val)) # convert to string again so we can print it. time.sleep(1) diff --git a/micropython/senml/manifest.py b/micropython/senml/manifest.py index 216717c..f474307 100644 --- a/micropython/senml/manifest.py +++ b/micropython/senml/manifest.py @@ -1,6 +1,6 @@ metadata( description="SenML serialisation for MicroPython.", - version="0.1.0", + version="0.1.1", pypi_publish="micropython-senml", ) diff --git a/micropython/senml/senml/senml_pack.py b/micropython/senml/senml/senml_pack.py index 85b26d4..4e106fd 100644 --- a/micropython/senml/senml/senml_pack.py +++ b/micropython/senml/senml/senml_pack.py @@ -27,8 +27,7 @@ THE SOFTWARE. from senml.senml_record import SenmlRecord from senml.senml_base import SenmlBase import json -from cbor2 import encoder -from cbor2 import decoder +import cbor2 class SenmlPackIterator: @@ -278,7 +277,7 @@ class SenmlPack(SenmlBase): :param data: a byte array. :return: None """ - records = decoder.loads(data) # load the raw senml data + records = cbor2.loads(data) # load the raw senml data naming_map = { "bn": -2, "bt": -3, @@ -320,7 +319,7 @@ class SenmlPack(SenmlBase): } converted = [] self._build_rec_dict(naming_map, converted) - return encoder.dumps(converted) + return cbor2.dumps(converted) def add(self, item): """