Skip to content

Commit 7e73472

Browse files
authored
Merge pull request #12 from bcmi-labs/compat
ucloud: Fix compatibility with MicroPython.
2 parents cae015d + 6262516 commit 7e73472

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

arduino_iot_cloud/ucloud.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,14 @@ def value(self, value):
112112
logging.debug(f"Update: {self.name} value: {value} ts: {self.timestamp}")
113113
self._value = value
114114

115-
def __is_subrecord(self, attr):
116-
return (hasattr(super(), '__dict__')
117-
and isinstance(super().__dict__.get("_value", None), dict)
118-
and attr in super().value)
119-
120115
def __getattr__(self, attr):
121-
if self.__is_subrecord(attr):
122-
return super().value[attr].value
116+
if isinstance(self.__dict__.get("_value", None), dict) and attr in self._value:
117+
return self._value[attr].value
123118
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{attr}'")
124119

125120
def __setattr__(self, attr, value):
126-
if self.__is_subrecord(attr):
127-
self.value[attr].value = value
121+
if isinstance(self.__dict__.get("_value", None), dict) and attr in self._value:
122+
self._value[attr].value = value
128123
else:
129124
super().__setattr__(attr, value)
130125

@@ -187,7 +182,7 @@ def __init__(
187182
self.update_systime()
188183
self.last_ping = timestamp()
189184
self.device_topic = b"/a/d/" + device_id + b"/e/i"
190-
self.senmlpack = SenmlPack("urn:uuid:" + device_id.decode("utf-8"), self.senml_generic_callback)
185+
self.senmlpack = SenmlPack("", self.senml_generic_callback)
191186
self.mqtt = MQTTClient(device_id, server, port, ssl_params, username, password, keepalive, self.mqtt_callback)
192187
# Note: the following internal objects are initialized by the cloud.
193188
for name in ["thing_id", "tz_offset", "tz_dst_until"]:
@@ -312,7 +307,8 @@ async def run(self, user_main=None):
312307
await asyncio.gather(*self.tasks.values(), return_exceptions=False)
313308
logging.info("All tasks finished!")
314309
break
315-
except Exception:
310+
except Exception as e:
311+
except_msg = str(e)
316312
pass # import traceback; traceback.print_exc()
317313

318314
for name in list(self.tasks):
@@ -321,6 +317,6 @@ async def run(self, user_main=None):
321317
if task.done():
322318
self.tasks.pop(name)
323319
self.records.pop(name, None)
324-
logging.error(f"Removed task: {name}. Raised exception: {task.exception()}.")
320+
logging.error(f"Removed task: {name}. Raised exception: {except_msg}.")
325321
except (CancelledError, InvalidStateError):
326322
pass

0 commit comments

Comments
 (0)