From 236afaacafbed5ccf33bb693159823983e242afb Mon Sep 17 00:00:00 2001 From: Viet Dzung Date: Tue, 11 Sep 2018 13:59:49 +0700 Subject: [PATCH 1/3] Support Foundation Command for use in zigbee-shepherd converter https://github.com/zigbeer/zcl-packet/wiki/6.-Appendix#FoundCmdTbl --- lib/zigbee.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/zigbee.js b/lib/zigbee.js index 6a813ebba..d8c2ec582 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -191,15 +191,27 @@ class Zigbee { } logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep}`); - device.functional(cid, cmd, zclData, (error) => { + if(zclData['foudation']!==true){ + device.functional(cid, cmd, zclData, (error) => { if (error) { + logger.error( + `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + + `failed with error ${error}`); + } + + callback(error); + }); + }else{ // use foundation command + device.foundation(cid, cmd, [{ attrId: zclData['attrId'], dataType:zclData['dataType'], attrData:zclData['attrData'] }, ], function (error, rsp) { + if (error){ logger.error( - `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + - `failed with error ${error}`); + `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + + `failed with error ${error}, respond ${rsp}`); + } + callback(error); + }); } - callback(error); - }); } read(deviceID, cid, attr, ep, callback) { From fccb4de565a44b94bf1aad7c609cfe4fce477700 Mon Sep 17 00:00:00 2001 From: Viet Dzung Date: Tue, 11 Sep 2018 14:28:04 +0700 Subject: [PATCH 2/3] Fix Lint error --- lib/zigbee.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/zigbee.js b/lib/zigbee.js index d8c2ec582..a53e1079f 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -191,27 +191,27 @@ class Zigbee { } logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep}`); - if(zclData['foudation']!==true){ - device.functional(cid, cmd, zclData, (error) => { - if (error) { - logger.error( - `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + - `failed with error ${error}`); - } + if (zclData['foudation']!==true) { + device.functional(cid, cmd, zclData, (error) => { + if (error) { + logger.error( + `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + + `failed with error ${error}`); + } - callback(error); + callback(error); }); - }else{ // use foundation command - device.foundation(cid, cmd, [{ attrId: zclData['attrId'], dataType:zclData['dataType'], attrData:zclData['attrData'] }, ], function (error, rsp) { - if (error){ - logger.error( - `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + - `failed with error ${error}, respond ${rsp}`); + } else { // use foundation command + device.foundation(cid, cmd, [{attrId: zclData['attrId'], dataType: zclData['dataType'], + attrData: zclData['attrData']}], function(error, rsp) { + if (error) { + logger.error( + `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + + `failed with error ${error}, respond ${rsp}`); } callback(error); - }); - } - + }); + } } read(deviceID, cid, attr, ep, callback) { From 8433571b1ea20e0a84c328d850e09d49f70fd206 Mon Sep 17 00:00:00 2001 From: Koenkk Date: Tue, 11 Sep 2018 21:28:30 +0200 Subject: [PATCH 3/3] Refactor multiple foundation. --- lib/controller.js | 2 +- lib/zigbee.js | 31 ++++++++++--------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index 447f8bf0e..29d06effd 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -541,7 +541,7 @@ class Controller { } }; - this.zigbee.publish(deviceID, message.cid, message.cmd, message.zclData, ep, callback); + this.zigbee.publish(deviceID, message.cid, message.cmd, message.zclData, ep, message.type, callback); published.push({message: message, converter: converter}); }); diff --git a/lib/zigbee.js b/lib/zigbee.js index a53e1079f..bfe50d4b2 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -183,7 +183,7 @@ class Zigbee { return this.shepherd.find(device.ieeeAddr, 1); } - publish(deviceID, cid, cmd, zclData, ep, callback) { + publish(deviceID, cid, cmd, zclData, ep, type, callback) { const device = this._findDevice(deviceID, ep); if (!device) { logger.error(`Zigbee cannot publish message to device because '${deviceID}' not known by zigbee-shepherd`); @@ -191,27 +191,16 @@ class Zigbee { } logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep}`); - if (zclData['foudation']!==true) { - device.functional(cid, cmd, zclData, (error) => { - if (error) { - logger.error( - `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + - `failed with error ${error}`); - } - callback(error); - }); - } else { // use foundation command - device.foundation(cid, cmd, [{attrId: zclData['attrId'], dataType: zclData['dataType'], - attrData: zclData['attrData']}], function(error, rsp) { - if (error) { - logger.error( - `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + - `failed with error ${error}, respond ${rsp}`); - } - callback(error); - }); - } + device[type](cid, cmd, zclData, (error) => { + if (error) { + logger.error( + `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` + + `failed with error ${error}`); + } + + callback(error); + }); } read(deviceID, cid, attr, ep, callback) {