From c880b479fb47f6b6759bff5bd92d77f00e3fc515 Mon Sep 17 00:00:00 2001 From: Kai Kramer Date: Sat, 18 Nov 2017 22:16:37 +0100 Subject: [PATCH] fix: publish meta withoud id --- km200mqtt.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/km200mqtt.js b/km200mqtt.js index 84bf9cc..a410aae 100755 --- a/km200mqtt.js +++ b/km200mqtt.js @@ -88,18 +88,20 @@ function mnemonizeMeta (result) { } function publishMeta (result) { - if (typeof (result.id) === 'string' && endsWith(result.id, 'flameCurrent')) { - result.unitOfMeasure = 'µA'; + if (typeof (result.id) === 'string') { + if (endsWith(result.id, 'flameCurrent')) { + result.unitOfMeasure = 'µA'; + } + var topic = 'km200/meta' + result.id; + var metaData = { + native: result + }; + metaData.native.value = undefined; + metaData.native.id = undefined; + mqtt.publish(topic, JSON.stringify(metaData), { retain: true }, function () { + log.debug('meta', topic, metaData); + }); } - var topic = 'km200/meta' + result.id; - var metaData = { - native: result - }; - metaData.native.value = undefined; - metaData.native.id = undefined; - mqtt.publish(topic, JSON.stringify(metaData), { retain: true }, function () { - log.debug('meta', topic, metaData); - }); } function endsWith (str, suffix) {