Skip to content

Commit 2846eb7

Browse files
committed
ucloud: Add workaround for int/float conversion bug.
1 parent 6eab8ce commit 2846eb7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arduino_iot_cloud/ucloud.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class InvalidStateError(Exception):
5252
class DoneException(Exception):
5353
pass
5454

55-
5655
def timestamp():
5756
return int(time.time())
5857

@@ -110,9 +109,12 @@ def runnable(self):
110109
def value(self, value):
111110
if value is not None:
112111
if self.value is not None:
112+
# This is a workaround for the cloud float/int conversion bug.
113+
if isinstance(self.value, float) and isinstance(value, int):
114+
value = float(value)
113115
if not isinstance(self.value, type(value)):
114116
raise TypeError(
115-
f"record: {self.name} invalid data type. Expected {type(self.value)} not {type(value)}"
117+
f"{self.name} set to invalid data type, expected: {type(self.value)} got: {type(value)}"
116118
)
117119
self._updated = True
118120
self.timestamp = timestamp()
@@ -375,5 +377,6 @@ async def run(self, user_main=None):
375377
logging.error(f"task: {name} raised exception: {str(task_except)}.")
376378
if name == "mqtt_task":
377379
self.create_task("conn_task", self.conn_task)
380+
break # Break after the first task is removed.
378381
except (CancelledError, InvalidStateError):
379382
pass

0 commit comments

Comments
 (0)