Skip to content

Commit c221d09

Browse files
ilcatoaentinger
authored andcommitted
fix_boolean_management (#49)
Manage the case to have boolean values received as integers 0/1 in the CBOR message.
1 parent 279a98e commit c221d09

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ArduinoCloudProperty.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,18 @@ void ArduinoCloudProperty::setAttributesFromCloud(LinkedList<CborMapData *> *map
170170

171171
void ArduinoCloudProperty::setAttributeReal(bool& value, String attributeName) {
172172
setAttributeReal(attributeName, [&value](CborMapData * md) {
173-
value = md->bool_val.get();
173+
// Manage the case to have boolean values received as integers 0/1
174+
if (md->bool_val.isSet()) {
175+
value = md->bool_val.get();
176+
} else if (md->val.isSet()) {
177+
if (md->val.get() == 0) {
178+
value = false;
179+
} else if (md->val.get() == 1) {
180+
value = true;
181+
} else {
182+
/* This should not happen. Leave the previous value */
183+
}
184+
}
174185
});
175186
}
176187

0 commit comments

Comments
 (0)