Skip to content

ucloud: Add workaround for int/float conversion bug. #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion arduino_iot_cloud/ucloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ def runnable(self):
def value(self, value):
if value is not None:
if self.value is not None:
# This is a workaround for the cloud float/int conversion bug.
if isinstance(self.value, float) and isinstance(value, int):
value = float(value)
if not isinstance(self.value, type(value)):
raise TypeError(
f"record: {self.name} invalid data type. Expected {type(self.value)} not {type(value)}"
f"{self.name} set to invalid data type, expected: {type(self.value)} got: {type(value)}"
)
self._updated = True
self.timestamp = timestamp()
Expand Down Expand Up @@ -375,5 +378,6 @@ async def run(self, user_main=None):
logging.error(f"task: {name} raised exception: {str(task_except)}.")
if name == "mqtt_task":
self.create_task("conn_task", self.conn_task)
break # Break after the first task is removed.
except (CancelledError, InvalidStateError):
pass