iobroker.zigbee 2.0.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,11 +12,10 @@ const DeviceConfigureExt = require('./zbDeviceConfigure');
12
12
  const DeviceEventExt = require('./zbDeviceEvent');
13
13
  const DelayedActionExt = require('./zbDelayedAction');
14
14
  const Groups = require('./groups');
15
-
16
15
  const utils = require('./utils');
17
- const { waitForDebugger } = require('inspector');
18
- const { table } = require('console');
19
- const { extract } = require('tar');
16
+
17
+ const { access, constants } =require('node:fs/promises');
18
+
20
19
  const groupConverters = [
21
20
  zigbeeHerdsmanConverters.toZigbee.light_onoff_brightness,
22
21
  zigbeeHerdsmanConverters.toZigbee.light_color_colortemp,
@@ -74,21 +73,32 @@ class ZigbeeController extends EventEmitter {
74
73
  new DelayedActionExt(this, {}),
75
74
  ];
76
75
  this.herdsmanTimeoutRegexp = new RegExp(/(\d+)ms/);
77
- this.herdsmanLogSettings = {}
76
+ this.herdsmanLogSettings = {};
77
+ this.debugActive = true;
78
78
 
79
79
  }
80
80
 
81
81
 
82
- ByteArrayToString(data) {
83
- if (data) {
84
- return data.map(function (x) {
85
- x = x + 0x100 + 1; // twos complement
86
- x = x.toString(16); // to hex
87
- x = ('00'+x).substr(-2); // zero-pad to 8-digits
88
- return x
89
- }).join('');
82
+
83
+ reverseIEEE(source) {
84
+ const rv = [];
85
+ for (let i=0;i<source.length;i+=2)
86
+ rv.push(source.slice(i,i+2))
87
+ return rv.reverse().join('');
88
+ }
89
+
90
+ async testConnectable(port) {
91
+ const netAddress = utils.getNetAddress(port);
92
+ if (netAddress && netAddress.strAddress) return netAddress.strAddress;
93
+ try {
94
+ const _port = port.trim();
95
+ await access(_port, constants.R_OK | constants.W_OK);
96
+ return _port;
97
+ }
98
+ catch (error) {
99
+ console.warn(`unable to access ${port}`)
100
+ return '';
90
101
  }
91
- else return '';
92
102
  }
93
103
 
94
104
  configure(options) {
@@ -122,7 +132,7 @@ class ZigbeeController extends EventEmitter {
122
132
  serialPort: {
123
133
  baudRate: options.sp.baudRate,
124
134
  rtscts: options.sp.rtscts,
125
- path: options.sp.port,
135
+ path: (typeof options.sp.port == 'string' ? options.sp.port.trim() : options.sp.port),
126
136
  adapter: options.sp.adapter,
127
137
  },
128
138
  transmitpower: this.transmitPower,
@@ -132,17 +142,24 @@ class ZigbeeController extends EventEmitter {
132
142
  legacy : false,
133
143
 
134
144
  };
145
+ // detect net port and rebuild
146
+ const tcpPort = utils.getNetAddress(herdsmanSettings.serialPort.path);
147
+ if (tcpPort && tcpPort.host)
148
+ herdsmanSettings.serialPort.path = `tcp://${tcpPort.host}:${tcpPort.port ? tcpPort.port : 80}`;
135
149
  // https://github.com/ioBroker/ioBroker.zigbee/issues/668
136
150
  if (!options.extPanIdFix) {
137
151
  delete herdsmanSettings.network.extendedPanID;
138
152
  herdsmanSettings.network.extenedPanID = options.net.extPanId;
139
153
  }
140
154
 
155
+ if (options.transmitPower != undefined) {
156
+ herdsmanSettings.transmitPower = options.transmitPower;
157
+ }
141
158
  this.disableLed = options.disableLed;
142
159
  this.warnOnDeviceAnnouncement = options.warnOnDeviceAnnouncement;
143
160
  this.herdsmanLogSettings.panID = herdsmanSettings.network.panID;
144
161
  this.herdsmanLogSettings.channel = herdsmanSettings.network.channelList[0];
145
- this.herdsmanLogSettings.extendedPanID = this.ByteArrayToString(herdsmanSettings.network.extendedPanID);
162
+ this.herdsmanLogSettings.extendedPanID = utils.byteArrayToString(herdsmanSettings.network.extendedPanID);
146
163
  this.herdsman = new ZigbeeHerdsman.Controller(herdsmanSettings, this.adapter.log);
147
164
  this.callExtensionMethod('setOptions', [{
148
165
  disableActivePing: options.disablePing,
@@ -152,11 +169,23 @@ class ZigbeeController extends EventEmitter {
152
169
  }]);
153
170
  }
154
171
 
172
+ async stopHerdsman() {
173
+ try {
174
+ this.emit('pairing', 'stopping zigbee-herdsman');
175
+ await this.herdsman.stop();
176
+ this.emit('pairing', 'herdsman stopped !');
177
+ this.herdsmanStarted = false;
178
+ }
179
+ catch (error) {
180
+ this.emit('pairing', `error stopping zigbee-herdsman: ${error && error.message ? error.message : 'no reason given'}`);
181
+ }
182
+ }
183
+
155
184
  // Start controller
156
185
  async start() {
157
186
  try {
158
- //this.debug(`Using zigbee-herdsman with settings2: ${JSON.stringify(this)}`);
159
- this.debug(`Starting zigbee-herdsman...`);
187
+ this.emit('pairing',`Starting zigbee-herdsman...`);
188
+ if (this.debugActive) this.debug(`Starting zigbee-herdsman...`);
160
189
 
161
190
  // install event handlers before start
162
191
  this.herdsman.on('adapterDisconnected', this.handleDisconnected.bind(this));
@@ -170,44 +199,45 @@ class ZigbeeController extends EventEmitter {
170
199
  this.info('Starting Zigbee-Herdsman');
171
200
  await this.herdsman.start();
172
201
  this.herdsmanStarted = true;
173
- this.info(`Zigbee-Herdsman started successfully with Coordinator firmware version: ${JSON.stringify(await this.herdsman.getCoordinatorVersion())}`);
202
+ const cv = await this.herdsman.getCoordinatorVersion();
203
+ const MetaSt = `${cv.meta.transportrev ? cv.meta.transportrev : 'X'}-${cv.meta.product ? cv.meta.product : 'X'}.${cv.meta.majorrel ? cv.meta.majorrel : 'X'}.${cv.meta.minorrel ? cv.meta.minorrel : 'X'}.${cv.meta.maintrel ? cv.meta.maintrel : 'X'}`;
204
+ const msg = `Zigbee-Herdsman started successfully with Coordinator firmware version: ${cv.type} : ${cv.meta.revision ? cv.meta.revision : ''} (${MetaSt})`;
205
+ this.emit('pairing',msg)
206
+ this.info(msg);
174
207
 
175
208
  // debug info from herdsman getNetworkParameters
176
209
  const debNetworkParam = JSON.parse(JSON.stringify(await this.herdsman.getNetworkParameters()));
177
210
  const extendedPanIDDebug = typeof debNetworkParam.extendedPanID === 'string' ? debNetworkParam.extendedPanID.replace('0x', '') : debNetworkParam.extendedPanID;
178
211
 
179
- let extPanIDDebug = '';
180
- for (let i = extendedPanIDDebug.length - 1; i >= 0; i--) {
181
- extPanIDDebug += extendedPanIDDebug[i - 1];
182
- extPanIDDebug += extendedPanIDDebug[i];
183
- i--;
184
- }
185
- this.debug(`Network parameters: panID=${debNetworkParam.panID} channel=${debNetworkParam.channel} extendedPanID=${extPanIDDebug}`);
212
+ this.emit('pairing',`Network parameters: panID=${debNetworkParam.panID} channel=${debNetworkParam.channel} extendedPanID=${this.reverseIEEE(extendedPanIDDebug)}`);
213
+ if (this.debugActive) this.debug(`Network parameters: panID=${debNetworkParam.panID} channel=${debNetworkParam.channel} extendedPanID=${this.reverseIEEE(extendedPanIDDebug)}`);
186
214
  } catch (e) {
187
215
  try {
188
216
  const debNetworkParam = JSON.parse(JSON.stringify(await this.herdsman.getNetworkParameters()));
189
217
  const extendedPanIDDebug = typeof debNetworkParam.extendedPanID === 'string' ? debNetworkParam.extendedPanID.replace('0x', '') : debNetworkParam.extendedPanID;
190
218
 
191
- let extPanIDDebug = '';
192
- for (let i = extendedPanIDDebug.length - 1; i >= 0; i--) {
193
- extPanIDDebug += extendedPanIDDebug[i - 1];
194
- extPanIDDebug += extendedPanIDDebug[i];
195
- i--;
196
- }
197
- this.warn(`Network parameters in Config : panID=${this.herdsmanLogSettings.panID} channel=${this.herdsmanLogSettings.channel} extendedPanID=${this.herdsmanLogSettings.extendedPanID}`)
198
- this.warn(`Network parameters on Coordinator: panID=${debNetworkParam.panID} channel=${debNetworkParam.channel} extendedPanID=${extPanIDDebug}`);
219
+ const configParameters = `Network parameters in Config : panID=${this.herdsmanLogSettings.panID} channel=${this.herdsmanLogSettings.channel} extendedPanID=${this.reverseIEEE(this.herdsmanLogSettings.extendedPanID)}`;
220
+ const networkParameters = `Network parameters on Coordinator: panID=${debNetworkParam.panID} channel=${debNetworkParam.channel} extendedPanID=${this.reverseIEEE(extendedPanIDDebug)}`;
221
+ this.emit('pairing',configParameters)
222
+ this.emit('pairing',networkParameters);
223
+ this.warn(configParameters)
224
+ this.warn(networkParameters);
199
225
  }
200
226
  catch (error) {
227
+ this.emit('pairing',`Unable to obtain herdsman settings`);
201
228
  this.info(`Unable to obtain herdsman settings`)
202
229
  }
203
230
  try {
204
231
  await this.herdsman.stop();
205
232
  }
206
233
  catch (error) {
234
+ this.emit('pairing','unable to stop zigbee-herdsman after failed startup');
207
235
  this.warn('unable to stop zigbee-herdsman after failed startup');
208
236
  }
209
237
  this.sendError(e);
210
- this.error(`Starting zigbee-herdsman problem : ${(e && e.message ? e.message : 'no error message')}`);
238
+ const msg = `Starting zigbee-herdsman problem : ${(e && e.message ? e.message : 'no error message')}`
239
+ this.error(msg);
240
+ this.emit('pairing', msg);
211
241
  throw 'Error herdsman start';
212
242
  }
213
243
  // Check if we have to turn off the LED
@@ -220,19 +250,20 @@ class ZigbeeController extends EventEmitter {
220
250
  }
221
251
  } catch (e) {
222
252
  this.info('Unable to disable LED, unsupported function.');
223
- this.sendError(e);
253
+ this.emit('pairing','Unable to disable LED, unsupported function.');
224
254
  }
225
255
 
226
-
227
256
  const deviceIterator = this.getClientIterator();
228
257
  let deviceCount = 0;
229
258
  try {
259
+ //this.emit('pairing','identifying connected devices')
230
260
  for (const device of deviceIterator) {
231
261
  deviceCount++;
232
262
  // get the model description for the known devices
233
263
  const entity = await this.resolveEntity(device);
234
264
  if (!entity) {
235
265
  this.warn('failed to resolve Entity for ' + device.ieeeAddr);
266
+ //this.emit('pairing','failed to resolve Entity for ' + device.ieeeAddr)
236
267
  continue;
237
268
  }
238
269
  //await this.adapter.stController.AddModelFromHerdsman(device, entity.mapped.model);
@@ -249,33 +280,37 @@ class ZigbeeController extends EventEmitter {
249
280
  if (entity.mapped) {
250
281
  this.emit('new', entity);
251
282
  }
252
- this.info(
253
- (entity.device.ieeeAddr) +
283
+ const msg = (entity.device.ieeeAddr +
254
284
  ` (addr ${entity.device.networkAddress}): ` +
255
- (entity.mapped ?
256
- `${entity.mapped.model} - ${entity.mapped.vendor} ${entity.mapped.description} ` :
257
- `Unsupported (model ${entity.device.modelID})`) +
258
- `(${entity.device.type})`
259
- );
285
+ (entity.mapped ? `${entity.mapped.model} - ${entity.mapped.vendor} ${entity.mapped.description} ` : `Unsupported (model ${entity.device.modelID})`) +
286
+ `(${entity.device.type})`);
287
+ //this.emit('pairing',msg);
288
+ this.info(msg);
260
289
  }
261
290
 
262
291
  // Log zigbee clients on startup
263
292
  // const devices = await this.getClients();
264
293
  if (deviceCount > 0) {
265
294
  this.info(`Currently ${deviceCount} devices are joined:`);
295
+ this.emit('pairing',`Currently ${deviceCount} devices are joined:`)
266
296
  } else {
267
- this.info(`Currently no devices.`);
297
+ this.info(`No devices are currently joined.`);
298
+ this.emit('pairing',`No devices are currently joined.`);
268
299
  }
269
300
  this.callExtensionMethod('onZigbeeStarted', []);
270
301
  }
271
302
  catch (error) {
272
- this.error('error iterating devices : '+ (error && error.message ? error.message: 'no reason given'));
303
+ const msg = 'error iterating devices : '+ (error && error.message ? error.message: 'no reason given');
304
+ this.error(msg);
305
+ this.emit('pairing',msg);
273
306
  }
274
307
  try {
275
308
  this.getGroups();
276
309
  }
277
310
  catch (error) {
278
- this.error('error iterating groups : '+ (error && error.message ? error.message: 'no reason given'));
311
+ const msg = 'error iterating groups : '+ (error && error.message ? error.message: 'no reason given');
312
+ this.error(msg);
313
+ this.emit('pairing',msg);
279
314
  }
280
315
  this.emit('ready');
281
316
  }
@@ -399,9 +434,9 @@ class ZigbeeController extends EventEmitter {
399
434
  group = await this.herdsman.createGroup(nid);
400
435
  group.toZigbee = groupConverters;
401
436
  group.model = 'group';
402
- this.debug(`verifyGroupExists: created group ${nid}`);
437
+ if (this.debugActive) this.debug(`verifyGroupExists: created group ${nid}`);
403
438
  } else {
404
- this.debug(`verifyGroupExists: group ${nid} exists`);
439
+ if (this.debugActive) this.debug(`verifyGroupExists: group ${nid} exists`);
405
440
  }
406
441
  return group
407
442
  }
@@ -421,7 +456,7 @@ class ZigbeeController extends EventEmitter {
421
456
  }
422
457
 
423
458
  async addPairingCode(code) {
424
- this.debug(`calling addPairingCode with ${code}`);
459
+ if (this.debugActive) this.debug(`calling addPairingCode with ${code}`);
425
460
  if (code) {
426
461
  try {
427
462
  await this.herdsman.addInstallCode(code);
@@ -600,15 +635,15 @@ class ZigbeeController extends EventEmitter {
600
635
 
601
636
  async incMsgHandler(message) {
602
637
  try {
603
- this.debug('incoming msg', message);
638
+ if (this.debugActive) this.debug('incoming msg', message);
604
639
  const device = await this.herdsman.getDeviceByIeeeAddr(message.srcaddr);
605
640
  if (!device) {
606
- this.debug('Message without device!');
641
+ if (this.debugActive) this.debug('Message without device!');
607
642
  return;
608
643
  }
609
644
  // We can't handle devices without modelId.
610
645
  if (!device.modelId) {
611
- this.debug('Message without modelId!');
646
+ if (this.debugActive) this.debug('Message without modelId!');
612
647
  return;
613
648
  }
614
649
  this.event('msg', device.ieeeAddr, message, {
@@ -631,8 +666,9 @@ class ZigbeeController extends EventEmitter {
631
666
  }
632
667
 
633
668
  try {
634
- await this.permitJoin(0);
669
+ if (this.HerdsmanStarted) await this.permitJoin(0);
635
670
  await this.herdsman.stop();
671
+ this.HerdsmanStarted = false;
636
672
  } catch (error) {
637
673
  this.sendError(error);
638
674
  if (this.herdsmanStarted) {
@@ -666,7 +702,7 @@ class ZigbeeController extends EventEmitter {
666
702
  async handlePermitJoinChanged(data)
667
703
  {
668
704
  try {
669
- this.debug(`Event handlePermitJoinChanged received with ${JSON.stringify(data)}`);
705
+ if (this.debugActive) this.debug(`Event handlePermitJoinChanged received with ${JSON.stringify(data)}`);
670
706
  if (data.permitted) {
671
707
  if (!this._permitJoinInterval) {
672
708
  this.emit('pairing',`Pairing possible for ${this._permitJoinTime} seconds`)
@@ -701,12 +737,12 @@ class ZigbeeController extends EventEmitter {
701
737
  } catch (error) {
702
738
  this.sendError(error);
703
739
  if (error)
704
- this.debug(`Failed to remove device. If device is remove is all fine, when not use Force remove`);
740
+ if (this.debugActive) this.debug(`Failed to remove device. If device is remove is all fine, when not use Force remove`);
705
741
  // skip error if force
706
742
  if (!force) {
707
743
  throw error;
708
744
  } else {
709
- this.debug(`Force remove`);
745
+ if (this.debugActive) this.debug(`Force remove`);
710
746
  }
711
747
  }
712
748
 
@@ -716,9 +752,9 @@ class ZigbeeController extends EventEmitter {
716
752
  this.sendError(error);
717
753
  // skip error
718
754
  if (error)
719
- this.debug(`Failed to remove from DB ${error.stack}`);
755
+ if (this.debugActive) this.debug(`Failed to remove from DB ${error.stack}`);
720
756
  }
721
- this.debug('Remove successful.');
757
+ if (this.debugActive) this.debug('Remove successful.');
722
758
  callback && callback();
723
759
  this.callExtensionMethod(
724
760
  'onDeviceRemove',
@@ -735,7 +771,7 @@ class ZigbeeController extends EventEmitter {
735
771
  // Zigbee events
736
772
  async handleDeviceLeave(message) {
737
773
  try {
738
- this.debug('handleDeviceLeave', message);
774
+ if (this.debugActive) this.debug('handleDeviceLeave', message);
739
775
  const entity = await this.resolveEntity(message.device || message.ieeeAddr);
740
776
  const friendlyName = entity ? entity.name : message.ieeeAddr;
741
777
  if (this.adapter.stController.checkDebugDevice(friendlyName)) {
@@ -756,7 +792,7 @@ class ZigbeeController extends EventEmitter {
756
792
  }
757
793
 
758
794
  async handleDeviceAnnounce(message) {
759
- this.debug('handleDeviceAnnounce', message);
795
+ if (this.debugActive) this.debug('handleDeviceAnnounce', message);
760
796
  const entity = await this.resolveEntity(message.device || message.ieeeAddr);
761
797
  const friendlyName = entity.name;
762
798
  if (this.adapter.stController.checkDebugDevice(friendlyName)) {
@@ -791,13 +827,13 @@ class ZigbeeController extends EventEmitter {
791
827
  }
792
828
 
793
829
  async handleDeviceJoined(message) {
794
- this.debug('handleDeviceJoined', message);
830
+ if (this.debugActive) this.debug('handleDeviceJoined', message);
795
831
  //const entity = await this.resolveEntity(message.device || message.ieeeAddr);
796
832
  //this.emit('new', entity);
797
833
  }
798
834
 
799
835
  async handleDeviceInterview(message) {
800
- this.debug('handleDeviceInterview', message);
836
+ if (this.debugActive) this.debug('handleDeviceInterview', message);
801
837
  // safeguard: We do not allow to start an interview if the network is not opened
802
838
  if (message.status === 'started' && !this.herdsman.getPermitJoin()) {
803
839
  this.warn(`Blocked interview for '${message.ieeeAddr}' because the network is closed`);
@@ -825,7 +861,7 @@ class ZigbeeController extends EventEmitter {
825
861
  [message, entity ? entity.mapped : null],
826
862
  );
827
863
  } else {
828
- this.debug(
864
+ if (this.debugActive) this.debug(
829
865
  `Device '${friendlyName}' with Zigbee model '${message.device.modelID}' is NOT supported, ` +
830
866
  `please follow https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html`
831
867
  );
@@ -851,10 +887,10 @@ class ZigbeeController extends EventEmitter {
851
887
  }
852
888
 
853
889
  async handleMessage(data) {
854
- this.debug(`handleMessage`, data);
890
+ if (this.debugActive) this.debug(`handleMessage`, data);
855
891
  const entity = await this.resolveEntity(data.device || data.ieeeAddr);
856
892
  const name = (entity && entity._modelID) ? entity._modelID : data.device.ieeeAddr;
857
- this.debug(
893
+ if (this.debugActive) this.debug(
858
894
  `Received Zigbee message from '${name}', type '${data.type}', cluster '${data.cluster}'` +
859
895
  `, data '${JSON.stringify(data.data)}' from endpoint ${data.endpoint.ID}` +
860
896
  (data.hasOwnProperty('groupID') ? ` with groupID ${data.groupID}` : ``)
@@ -881,7 +917,7 @@ class ZigbeeController extends EventEmitter {
881
917
  let resolved = await this.resolveEntity(device, 0);
882
918
  if (!resolved) {
883
919
  resolved = { name:'unresolved device', device:device }
884
- this.debug('resolve Entity failed for ' + device.ieeeAddr)
920
+ if (this.debugActive) this.debug('resolve Entity failed for ' + device.ieeeAddr)
885
921
  }
886
922
  let result;
887
923
 
@@ -941,9 +977,9 @@ class ZigbeeController extends EventEmitter {
941
977
 
942
978
  callback && callback({lqis, routing, errors});
943
979
  if (errors.length) {
944
- this.debug(`Map Data collection complete with ${errors.length} issues:`);
980
+ if (this.debugActive) this.debug(`Map Data collection complete with ${errors.length} issues:`);
945
981
  for (const msg of errors)
946
- this.debug(msg);
982
+ if (this.debugActive) this.debug(msg);
947
983
  }
948
984
  else
949
985
  this.info('Map data collection complete');
@@ -971,7 +1007,7 @@ class ZigbeeController extends EventEmitter {
971
1007
  return;
972
1008
  }
973
1009
 
974
- this.debug(`Zigbee publish to '${deviceID}', ${cid} - cmd ${cmd} - payload ${JSON.stringify(zclData)} - cfg ${JSON.stringify(cfg)} - endpoint ${ep}`);
1010
+ if (this.debugActive) this.debug(`Zigbee publish to '${deviceID}', ${cid} - cmd ${cmd} - payload ${JSON.stringify(zclData)} - cfg ${JSON.stringify(cfg)} - endpoint ${ep}`);
975
1011
 
976
1012
  if (cfg == null) {
977
1013
  cfg = {};
@@ -1010,23 +1046,23 @@ class ZigbeeController extends EventEmitter {
1010
1046
 
1011
1047
  async addDevToGroup(devId, groupId, epid) {
1012
1048
  try {
1013
- this.debug(`called addDevToGroup with ${devId}, ${groupId}, ${epid}`);
1049
+ if (this.debugActive) this.debug(`called addDevToGroup with ${devId}, ${groupId}, ${epid}`);
1014
1050
  const entity = await this.resolveEntity(devId);
1015
1051
  const group = await this.resolveEntity(groupId);
1016
- this.debug(`addDevFromGroup - entity: ${utils.getEntityInfo(entity)}`);
1052
+ if (this.debugActive) this.debug(`addDevFromGroup - entity: ${utils.getEntityInfo(entity)}`);
1017
1053
  // generate group debug info and display it
1018
1054
  const members = await this.getGroupMembersFromController(groupId);
1019
1055
  const memberIDs = [];
1020
1056
  for (const member of members) {
1021
1057
  memberIDs.push(member.ieee);
1022
1058
  }
1023
- this.debug(`addDevToGroup ${groupId} with ${memberIDs.length} members ${safeJsonStringify(memberIDs)}`);
1059
+ if (this.debugActive) this.debug(`addDevToGroup ${groupId} with ${memberIDs.length} members ${safeJsonStringify(memberIDs)}`);
1024
1060
  if (epid != undefined) {
1025
1061
  for (const ep of entity.endpoints) {
1026
- this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1062
+ if (this.debugActive) this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1027
1063
  if (ep.ID == epid) {
1028
1064
  if (ep.inputClusters.includes(4) || ep.outputClusters.includes(4)) {
1029
- this.debug(`adding endpoint ${ep.ID} (${epid}) to group ${groupId}`);
1065
+ if (this.debugActive) this.debug(`adding endpoint ${ep.ID} (${epid}) to group ${groupId}`);
1030
1066
  await (ep.addToGroup(group.mapped));
1031
1067
  }
1032
1068
  else this.error(`cluster genGroups not supported for endpoint ${epid} of ${devId}`);
@@ -1059,25 +1095,15 @@ class ZigbeeController extends EventEmitter {
1059
1095
  }
1060
1096
 
1061
1097
  async removeDevFromGroup(devId, groupId, epid) {
1062
- this.debug(`removeDevFromGroup with ${devId}, ${groupId}, ${epid}`);
1098
+ if (this.debugActive) this.debug(`removeDevFromGroup with ${devId}, ${groupId}, ${epid}`);
1063
1099
  let entity;
1064
1100
  try {
1065
1101
  entity = await this.resolveEntity(devId);
1066
1102
  const group = await this.resolveEntity(groupId);
1067
1103
 
1068
- /*
1069
- const members = await this.getGroupMembersFromController(groupId);
1070
- const memberIDs = [];
1071
- for (const member of members) {
1072
- memberIDs.push(member.ieee);
1073
- }
1074
-
1075
- this.debug(`removeDevFromGroup - entity: ${utils.getEntityInfo(entity)}`);
1076
- this.debug(`removeDevFromGroup ${groupId} with ${memberIDs.length} members ${safeJsonStringify(memberIDs)}`);
1077
- */
1078
1104
  if (epid != undefined) {
1079
1105
  for (const ep of entity.endpoints) {
1080
- this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1106
+ if (this.debugActive) this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1081
1107
  if (ep.ID == epid && (ep.inputClusters.includes(4) || ep.outputClusters.includes(4))) {
1082
1108
  await ep.removeFromGroup(group.mapped);
1083
1109
  this.info(`removing endpoint ${ep.ID} of ${devId} from group ${groupId}`);
@@ -1099,7 +1125,7 @@ class ZigbeeController extends EventEmitter {
1099
1125
  async removeDevFromAllGroups(devId) {
1100
1126
  try {
1101
1127
  const entity = await this.resolveEntity(devId);
1102
- this.debug(`entity: ${safeJsonStringify(entity)}`);
1128
+ if (this.debugActive) this.debug(`entity: ${safeJsonStringify(entity)}`);
1103
1129
  for (const ep of entity.endpoints) {
1104
1130
  if (ep.inputClusters.includes(4) || ep.outputClusters.includes(4)) {
1105
1131
  await ep.removefromAllGroups();
@@ -1117,14 +1143,14 @@ class ZigbeeController extends EventEmitter {
1117
1143
  const log = ` ${ep.device.ieeeAddr} - ${cluster}`;
1118
1144
  target = !target ? this.getCoordinator() : target;
1119
1145
 
1120
- this.debug(`Binding ${log}`);
1146
+ if (this.debugActive) this.debug(`Binding ${log}`);
1121
1147
  try {
1122
1148
  ep.bind(cluster, target, error => {
1123
1149
  if (error) {
1124
1150
  this.sendError(error);
1125
1151
  this.error(`Failed to bind ${log} - (${error})`);
1126
1152
  } else {
1127
- this.debug(`Successfully bound ${log}`);
1153
+ if (this.debugActive) this.debug(`Successfully bound ${log}`);
1128
1154
  }
1129
1155
 
1130
1156
  callback(error);
@@ -1139,13 +1165,13 @@ class ZigbeeController extends EventEmitter {
1139
1165
  const log = ` ${ep.device.ieeeAddr} - ${cluster}`;
1140
1166
  target = !target ? this.getCoordinator() : target;
1141
1167
 
1142
- this.debug(`Unbinding ${log}`);
1168
+ if (this.debugActive) this.debug(`Unbinding ${log}`);
1143
1169
  try {
1144
1170
  ep.unbind(cluster, target, (error) => {
1145
1171
  if (error) {
1146
1172
  this.error(`Failed to unbind ${log} - (${error})`);
1147
1173
  } else {
1148
- this.debug(`Successfully unbound ${log}`);
1174
+ if (this.debugActive) this.debug(`Successfully unbound ${log}`);
1149
1175
  }
1150
1176
 
1151
1177
  callback(error);
@@ -1184,9 +1210,9 @@ class ZigbeeController extends EventEmitter {
1184
1210
  {
1185
1211
  const payload = ZDO.Buffalo.buildRequest(false, clusterId, [11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26], 0x05, 1, 0, undefined);
1186
1212
  const scanresult = await this.herdsman.adapter.sendZdo(0x0, 0x0, clusterId , payload, false);
1187
- this.debug(`scanresult is ${JSON.stringify(scanresult)}`)
1213
+ if (this.debugActive) this.debug(`scanresult is ${JSON.stringify(scanresult)}`)
1188
1214
  result.energyvalues = scanresult[1].entryList;
1189
- this.debug(`result is ${JSON.stringify(result)}`)
1215
+ if (this.debugActive) this.debug(`result is ${JSON.stringify(result)}`)
1190
1216
  }
1191
1217
  catch (error) {
1192
1218
  this.sendError(error);