Skip to content

Commit 3c29b4d

Browse files
committed
ucloud: Fix exception when using an old version of CBOR2.
Outdated versions of the CBOR2 library will not raise an exception. Signed-off-by: iabdalkader <[email protected]>
1 parent 7ab1d8a commit 3c29b4d

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/arduino_iot_cloud/ucloud.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class InvalidStateError(Exception):
2222
try:
2323
from arduino_iot_cloud._version import __version__
2424
except (ImportError, AttributeError):
25-
__version__ = "1.3.0"
25+
__version__ = "1.3.1"
2626

2727
# Server/port for basic auth.
2828
_DEFAULT_SERVER = "iot.arduino.cc"
@@ -199,14 +199,6 @@ def __init__(
199199
self.async_mode = not sync_mode
200200
self.connected = False
201201

202-
if "pin" in ssl_params:
203-
try:
204-
# Use M2Crypto to load key and cert from HSM.
205-
import M2Crypto # noqa
206-
except (ImportError, AttributeError):
207-
logging.error("The m2crypto module is required to use HSM.")
208-
sys.exit(1)
209-
210202
# Convert args to bytes if they are passed as strings.
211203
if isinstance(device_id, str):
212204
device_id = bytes(device_id, "utf-8")
@@ -372,9 +364,11 @@ def poll_discovery(self, aiot=None):
372364
self.mqtt.subscribe(self.create_topic("shadow", "i"), qos=1)
373365
self.mqtt.publish(self.create_topic("shadow", "o"), self.senmlpack.to_cbor(), qos=1)
374366

375-
# Push library version and mode.
376-
libv = "%s-%s" % (__version__, "async" if self.async_mode else "sync")
377-
self.mqtt.publish(self.command_topic, cbor2.dumps(cbor2.CBORTag(67328, [libv])), qos=1)
367+
if hasattr(cbor2, "dumps"):
368+
# Push library version and mode.
369+
libv = "%s-%s" % (__version__, "async" if self.async_mode else "sync")
370+
# Note we have to add the tag manually because python-ecosys's cbor2 doesn't suppor CBORTags.
371+
self.mqtt.publish(self.command_topic, b"\xda\x00\x01\x07\x00" + cbor2.dumps([libv]), qos=1)
378372
logging.info("Device configured via discovery protocol.")
379373
if self.async_mode:
380374
raise DoneException()

0 commit comments

Comments
 (0)