From bf85ea1494ecb915a42674b6e44567a54d23b1ed Mon Sep 17 00:00:00 2001 From: Koenkk Date: Sun, 23 Sep 2018 00:14:52 +0200 Subject: [PATCH] Allow joining through specified device. --- lib/controller.js | 11 ++++++++++- lib/zigbee.js | 14 +++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index 4a024754..ac6f27e8 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -396,7 +396,16 @@ class Controller { const option = topic.split('/').slice(-1)[0]; if (option === 'permit_join') { - this.zigbee.permitJoin(message.toString().toLowerCase() === 'true'); + const msg = message.toString().toLowerCase(); + let type = 'all'; + let join = msg === 'true'; + + if (!['true', 'false'].includes(msg)) { + join = true; + type = parseInt(msg); + } + + this.zigbee.permitJoin(join, type); } else if (option === 'log_level') { const level = message.toString().toLowerCase(); if (allowedLogLevels.includes(level)) { diff --git a/lib/zigbee.js b/lib/zigbee.js index 174e5452..57d9d90d 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -113,14 +113,14 @@ class Zigbee { logger.error(message); } - permitJoin(permit) { + permitJoin(permit, type='all') { if (permit) { - logger.info('Zigbee: allowing new devices to join.'); + logger.info(`Zigbee: allowing new devices to join. (${type})`); } else { - logger.info('Zigbee: disabling joining new devices.'); + logger.info(`Zigbee: disabling joining new devices. (${type})`); } - this.shepherd.permitJoin(permit ? 255 : 0, (error) => { + this.shepherd.permitJoin(permit ? 255 : 0, type, (error) => { if (error) { logger.info(error); } @@ -190,13 +190,13 @@ class Zigbee { return; } - logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - - ${JSON.stringify(zclData)} - ${JSON.stringify(cfg)} - ${ep}`); + logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd}` + + `- ${JSON.stringify(zclData)} - ${JSON.stringify(cfg)} - ${ep}`); const callback_ = (error) => { if (error) { logger.error( - `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} + `Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${JSON.stringify(cfg)} - ${ep} ` + `failed with error ${error}`); }