Allow joining through specified device.

This commit is contained in:
Koenkk 2018-09-23 00:14:52 +02:00
parent da06e87276
commit bf85ea1494
2 changed files with 17 additions and 8 deletions

View File

@ -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)) {

View File

@ -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}`);
}