From 68166928a259138bbcaeebf7a8381b45807b4ad0 Mon Sep 17 00:00:00 2001 From: ilcato Date: Tue, 18 Jun 2019 10:18:13 +0200 Subject: [PATCH 1/2] 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. --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index eed888f..e2b72f4 100644 --- a/src/index.js +++ b/src/index.js @@ -134,7 +134,7 @@ const connect = options => new Promise((resolve, reject) => { const valueKey = p.v !== undefined ? 'v' : '2'; const valueStringKey = p.vs !== undefined ? 'vs' : '3'; const valueBooleanKey = p.vb !== undefined ? 'vb' : '4'; - let value; + let value = null; propertyNameKey = propertyNameKeySplit[propertyNameId]; if (propertyCallback[msg.topic][propertyNameKey]) { if (!(p[valueKey] === undefined)) { @@ -148,19 +148,19 @@ const connect = options => new Promise((resolve, reject) => { if (propertyNameKeyPrevious === '') { propertyNameKeyPrevious = propertyNameKeySplit[propertyNameId]; } - if (propertyNameKeyPrevious !== propertyNameKey) { + if (propertyNameKeyPrevious !== propertyNameKey && propertyCallback[msg.topic][propertyNameKeyPrevious]) { propertyCallback[msg.topic][propertyNameKeyPrevious](valueToSend); propertyNameKeyPrevious = propertyNameKey; valueToSend = {}; } - if (propertyNameKeySplit.length === 1) { + if (propertyNameKeySplit.length === 1 && value != null) { valueToSend = value; } else { const attributeName = propertyNameKeySplit[attributeNameId]; valueToSend[attributeName] = value; } }); - if (valueToSend !== {}) { + if (valueToSend !== {} && propertyCallback[msg.topic][propertyNameKeyPrevious]) { propertyCallback[msg.topic][propertyNameKeyPrevious](valueToSend); } } From 6a4c023c7c4d324db516034a6c139df89a48705c Mon Sep 17 00:00:00 2001 From: ilcato Date: Wed, 19 Jun 2019 15:15:46 +0200 Subject: [PATCH 2/2] Fix check expression --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e2b72f4..8d42e8d 100644 --- a/src/index.js +++ b/src/index.js @@ -153,7 +153,7 @@ const connect = options => new Promise((resolve, reject) => { propertyNameKeyPrevious = propertyNameKey; valueToSend = {}; } - if (propertyNameKeySplit.length === 1 && value != null) { + if (propertyNameKeySplit.length === 1 && value !== null) { valueToSend = value; } else { const attributeName = propertyNameKeySplit[attributeNameId];