Skip to content

Commit 6816692

Browse files
committed
Fix error decoding non existing property
If a property is sent from the device to the cloud when the property is non existing on the cloud an error was raised.
1 parent 3ef46f5 commit 6816692

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const connect = options => new Promise((resolve, reject) => {
134134
const valueKey = p.v !== undefined ? 'v' : '2';
135135
const valueStringKey = p.vs !== undefined ? 'vs' : '3';
136136
const valueBooleanKey = p.vb !== undefined ? 'vb' : '4';
137-
let value;
137+
let value = null;
138138
propertyNameKey = propertyNameKeySplit[propertyNameId];
139139
if (propertyCallback[msg.topic][propertyNameKey]) {
140140
if (!(p[valueKey] === undefined)) {
@@ -148,19 +148,19 @@ const connect = options => new Promise((resolve, reject) => {
148148
if (propertyNameKeyPrevious === '') {
149149
propertyNameKeyPrevious = propertyNameKeySplit[propertyNameId];
150150
}
151-
if (propertyNameKeyPrevious !== propertyNameKey) {
151+
if (propertyNameKeyPrevious !== propertyNameKey && propertyCallback[msg.topic][propertyNameKeyPrevious]) {
152152
propertyCallback[msg.topic][propertyNameKeyPrevious](valueToSend);
153153
propertyNameKeyPrevious = propertyNameKey;
154154
valueToSend = {};
155155
}
156-
if (propertyNameKeySplit.length === 1) {
156+
if (propertyNameKeySplit.length === 1 && value != null) {
157157
valueToSend = value;
158158
} else {
159159
const attributeName = propertyNameKeySplit[attributeNameId];
160160
valueToSend[attributeName] = value;
161161
}
162162
});
163-
if (valueToSend !== {}) {
163+
if (valueToSend !== {} && propertyCallback[msg.topic][propertyNameKeyPrevious]) {
164164
propertyCallback[msg.topic][propertyNameKeyPrevious](valueToSend);
165165
}
166166
}

0 commit comments

Comments
 (0)