iobroker.zigbee 2.0.5 → 3.0.1

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.
Files changed (42) hide show
  1. package/README.md +22 -3
  2. package/admin/admin.js +420 -115
  3. package/admin/index_m.html +285 -229
  4. package/admin/tab_m.html +108 -91
  5. package/docs/de/img/Bild30.png +0 -0
  6. package/docs/de/img/Bild38.png +0 -0
  7. package/docs/de/img/Info.png +0 -0
  8. package/docs/de/img/Zigbee_config_de.jpg +0 -0
  9. package/docs/de/img/battery.png +0 -0
  10. package/docs/de/img/debug.png +0 -0
  11. package/docs/de/img/delete.png +0 -0
  12. package/docs/de/img/disconnected.png +0 -0
  13. package/docs/de/img/edit_grp.png +0 -0
  14. package/docs/de/img/edit_image.png +0 -0
  15. package/docs/de/img/grp_nok.png +0 -0
  16. package/docs/de/img/grp_ok.png +0 -0
  17. package/docs/de/img/on_off.png +0 -0
  18. package/docs/de/img/reconfigure.png +0 -0
  19. package/docs/de/readme.md +52 -43
  20. package/docs/en/img/Zigbee_config_en.png +0 -0
  21. package/docs/en/img/Zigbee_pairing_en.png +0 -0
  22. package/docs/en/readme.md +66 -66
  23. package/io-package.json +32 -31
  24. package/lib/DeviceDebug.js +2 -1
  25. package/lib/commands.js +203 -40
  26. package/lib/devices.js +2 -2
  27. package/lib/exposes.js +8 -30
  28. package/lib/groups.js +1 -1
  29. package/lib/localConfig.js +33 -10
  30. package/lib/networkmap.js +2 -1
  31. package/lib/seriallist.js +9 -2
  32. package/lib/statescontroller.js +185 -91
  33. package/lib/utils.js +41 -11
  34. package/lib/zbDeviceConfigure.js +10 -3
  35. package/lib/zigbeecontroller.js +121 -94
  36. package/main.js +135 -73
  37. package/package.json +8 -8
  38. package/docs/en/img/Bild23.png +0 -0
  39. package/docs/en/img/Bild25.png +0 -0
  40. package/docs/en/img/Bild26.png +0 -0
  41. package/docs/en/img/Bild4.png +0 -0
  42. package/docs/en/img/Bild9.png +0 -0
@@ -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,10 @@ 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;
672
+ this.info('zigbecontroller stopped successfully');
636
673
  } catch (error) {
637
674
  this.sendError(error);
638
675
  if (this.herdsmanStarted) {
@@ -666,7 +703,7 @@ class ZigbeeController extends EventEmitter {
666
703
  async handlePermitJoinChanged(data)
667
704
  {
668
705
  try {
669
- this.debug(`Event handlePermitJoinChanged received with ${JSON.stringify(data)}`);
706
+ if (this.debugActive) this.debug(`Event handlePermitJoinChanged received with ${JSON.stringify(data)}`);
670
707
  if (data.permitted) {
671
708
  if (!this._permitJoinInterval) {
672
709
  this.emit('pairing',`Pairing possible for ${this._permitJoinTime} seconds`)
@@ -701,12 +738,12 @@ class ZigbeeController extends EventEmitter {
701
738
  } catch (error) {
702
739
  this.sendError(error);
703
740
  if (error)
704
- this.debug(`Failed to remove device. If device is remove is all fine, when not use Force remove`);
741
+ if (this.debugActive) this.debug(`Failed to remove device. If device is remove is all fine, when not use Force remove`);
705
742
  // skip error if force
706
743
  if (!force) {
707
744
  throw error;
708
745
  } else {
709
- this.debug(`Force remove`);
746
+ if (this.debugActive) this.debug(`Force remove`);
710
747
  }
711
748
  }
712
749
 
@@ -716,9 +753,9 @@ class ZigbeeController extends EventEmitter {
716
753
  this.sendError(error);
717
754
  // skip error
718
755
  if (error)
719
- this.debug(`Failed to remove from DB ${error.stack}`);
756
+ if (this.debugActive) this.debug(`Failed to remove from DB ${error.stack}`);
720
757
  }
721
- this.debug('Remove successful.');
758
+ if (this.debugActive) this.debug('Remove successful.');
722
759
  callback && callback();
723
760
  this.callExtensionMethod(
724
761
  'onDeviceRemove',
@@ -735,7 +772,7 @@ class ZigbeeController extends EventEmitter {
735
772
  // Zigbee events
736
773
  async handleDeviceLeave(message) {
737
774
  try {
738
- this.debug('handleDeviceLeave', message);
775
+ if (this.debugActive) this.debug('handleDeviceLeave', message);
739
776
  const entity = await this.resolveEntity(message.device || message.ieeeAddr);
740
777
  const friendlyName = entity ? entity.name : message.ieeeAddr;
741
778
  if (this.adapter.stController.checkDebugDevice(friendlyName)) {
@@ -756,7 +793,7 @@ class ZigbeeController extends EventEmitter {
756
793
  }
757
794
 
758
795
  async handleDeviceAnnounce(message) {
759
- this.debug('handleDeviceAnnounce', message);
796
+ if (this.debugActive) this.debug('handleDeviceAnnounce', message);
760
797
  const entity = await this.resolveEntity(message.device || message.ieeeAddr);
761
798
  const friendlyName = entity.name;
762
799
  if (this.adapter.stController.checkDebugDevice(friendlyName)) {
@@ -791,13 +828,13 @@ class ZigbeeController extends EventEmitter {
791
828
  }
792
829
 
793
830
  async handleDeviceJoined(message) {
794
- this.debug('handleDeviceJoined', message);
831
+ if (this.debugActive) this.debug('handleDeviceJoined', message);
795
832
  //const entity = await this.resolveEntity(message.device || message.ieeeAddr);
796
833
  //this.emit('new', entity);
797
834
  }
798
835
 
799
836
  async handleDeviceInterview(message) {
800
- this.debug('handleDeviceInterview', message);
837
+ if (this.debugActive) this.debug('handleDeviceInterview', message);
801
838
  // safeguard: We do not allow to start an interview if the network is not opened
802
839
  if (message.status === 'started' && !this.herdsman.getPermitJoin()) {
803
840
  this.warn(`Blocked interview for '${message.ieeeAddr}' because the network is closed`);
@@ -825,7 +862,7 @@ class ZigbeeController extends EventEmitter {
825
862
  [message, entity ? entity.mapped : null],
826
863
  );
827
864
  } else {
828
- this.debug(
865
+ if (this.debugActive) this.debug(
829
866
  `Device '${friendlyName}' with Zigbee model '${message.device.modelID}' is NOT supported, ` +
830
867
  `please follow https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html`
831
868
  );
@@ -851,10 +888,10 @@ class ZigbeeController extends EventEmitter {
851
888
  }
852
889
 
853
890
  async handleMessage(data) {
854
- this.debug(`handleMessage`, data);
891
+ if (this.debugActive) this.debug(`handleMessage`, data);
855
892
  const entity = await this.resolveEntity(data.device || data.ieeeAddr);
856
893
  const name = (entity && entity._modelID) ? entity._modelID : data.device.ieeeAddr;
857
- this.debug(
894
+ if (this.debugActive) this.debug(
858
895
  `Received Zigbee message from '${name}', type '${data.type}', cluster '${data.cluster}'` +
859
896
  `, data '${JSON.stringify(data.data)}' from endpoint ${data.endpoint.ID}` +
860
897
  (data.hasOwnProperty('groupID') ? ` with groupID ${data.groupID}` : ``)
@@ -881,7 +918,7 @@ class ZigbeeController extends EventEmitter {
881
918
  let resolved = await this.resolveEntity(device, 0);
882
919
  if (!resolved) {
883
920
  resolved = { name:'unresolved device', device:device }
884
- this.debug('resolve Entity failed for ' + device.ieeeAddr)
921
+ if (this.debugActive) this.debug('resolve Entity failed for ' + device.ieeeAddr)
885
922
  }
886
923
  let result;
887
924
 
@@ -941,9 +978,9 @@ class ZigbeeController extends EventEmitter {
941
978
 
942
979
  callback && callback({lqis, routing, errors});
943
980
  if (errors.length) {
944
- this.debug(`Map Data collection complete with ${errors.length} issues:`);
981
+ if (this.debugActive) this.debug(`Map Data collection complete with ${errors.length} issues:`);
945
982
  for (const msg of errors)
946
- this.debug(msg);
983
+ if (this.debugActive) this.debug(msg);
947
984
  }
948
985
  else
949
986
  this.info('Map data collection complete');
@@ -971,7 +1008,7 @@ class ZigbeeController extends EventEmitter {
971
1008
  return;
972
1009
  }
973
1010
 
974
- this.debug(`Zigbee publish to '${deviceID}', ${cid} - cmd ${cmd} - payload ${JSON.stringify(zclData)} - cfg ${JSON.stringify(cfg)} - endpoint ${ep}`);
1011
+ if (this.debugActive) this.debug(`Zigbee publish to '${deviceID}', ${cid} - cmd ${cmd} - payload ${JSON.stringify(zclData)} - cfg ${JSON.stringify(cfg)} - endpoint ${ep}`);
975
1012
 
976
1013
  if (cfg == null) {
977
1014
  cfg = {};
@@ -1010,23 +1047,23 @@ class ZigbeeController extends EventEmitter {
1010
1047
 
1011
1048
  async addDevToGroup(devId, groupId, epid) {
1012
1049
  try {
1013
- this.debug(`called addDevToGroup with ${devId}, ${groupId}, ${epid}`);
1050
+ if (this.debugActive) this.debug(`called addDevToGroup with ${devId}, ${groupId}, ${epid}`);
1014
1051
  const entity = await this.resolveEntity(devId);
1015
1052
  const group = await this.resolveEntity(groupId);
1016
- this.debug(`addDevFromGroup - entity: ${utils.getEntityInfo(entity)}`);
1053
+ if (this.debugActive) this.debug(`addDevFromGroup - entity: ${utils.getEntityInfo(entity)}`);
1017
1054
  // generate group debug info and display it
1018
1055
  const members = await this.getGroupMembersFromController(groupId);
1019
1056
  const memberIDs = [];
1020
1057
  for (const member of members) {
1021
1058
  memberIDs.push(member.ieee);
1022
1059
  }
1023
- this.debug(`addDevToGroup ${groupId} with ${memberIDs.length} members ${safeJsonStringify(memberIDs)}`);
1060
+ if (this.debugActive) this.debug(`addDevToGroup ${groupId} with ${memberIDs.length} members ${safeJsonStringify(memberIDs)}`);
1024
1061
  if (epid != undefined) {
1025
1062
  for (const ep of entity.endpoints) {
1026
- this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1063
+ if (this.debugActive) this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1027
1064
  if (ep.ID == epid) {
1028
1065
  if (ep.inputClusters.includes(4) || ep.outputClusters.includes(4)) {
1029
- this.debug(`adding endpoint ${ep.ID} (${epid}) to group ${groupId}`);
1066
+ if (this.debugActive) this.debug(`adding endpoint ${ep.ID} (${epid}) to group ${groupId}`);
1030
1067
  await (ep.addToGroup(group.mapped));
1031
1068
  }
1032
1069
  else this.error(`cluster genGroups not supported for endpoint ${epid} of ${devId}`);
@@ -1059,25 +1096,15 @@ class ZigbeeController extends EventEmitter {
1059
1096
  }
1060
1097
 
1061
1098
  async removeDevFromGroup(devId, groupId, epid) {
1062
- this.debug(`removeDevFromGroup with ${devId}, ${groupId}, ${epid}`);
1099
+ if (this.debugActive) this.debug(`removeDevFromGroup with ${devId}, ${groupId}, ${epid}`);
1063
1100
  let entity;
1064
1101
  try {
1065
1102
  entity = await this.resolveEntity(devId);
1066
1103
  const group = await this.resolveEntity(groupId);
1067
1104
 
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
1105
  if (epid != undefined) {
1079
1106
  for (const ep of entity.endpoints) {
1080
- this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1107
+ if (this.debugActive) this.debug(`checking ep ${ep.ID} of ${devId} (${epid})`);
1081
1108
  if (ep.ID == epid && (ep.inputClusters.includes(4) || ep.outputClusters.includes(4))) {
1082
1109
  await ep.removeFromGroup(group.mapped);
1083
1110
  this.info(`removing endpoint ${ep.ID} of ${devId} from group ${groupId}`);
@@ -1099,7 +1126,7 @@ class ZigbeeController extends EventEmitter {
1099
1126
  async removeDevFromAllGroups(devId) {
1100
1127
  try {
1101
1128
  const entity = await this.resolveEntity(devId);
1102
- this.debug(`entity: ${safeJsonStringify(entity)}`);
1129
+ if (this.debugActive) this.debug(`entity: ${safeJsonStringify(entity)}`);
1103
1130
  for (const ep of entity.endpoints) {
1104
1131
  if (ep.inputClusters.includes(4) || ep.outputClusters.includes(4)) {
1105
1132
  await ep.removefromAllGroups();
@@ -1117,14 +1144,14 @@ class ZigbeeController extends EventEmitter {
1117
1144
  const log = ` ${ep.device.ieeeAddr} - ${cluster}`;
1118
1145
  target = !target ? this.getCoordinator() : target;
1119
1146
 
1120
- this.debug(`Binding ${log}`);
1147
+ if (this.debugActive) this.debug(`Binding ${log}`);
1121
1148
  try {
1122
1149
  ep.bind(cluster, target, error => {
1123
1150
  if (error) {
1124
1151
  this.sendError(error);
1125
1152
  this.error(`Failed to bind ${log} - (${error})`);
1126
1153
  } else {
1127
- this.debug(`Successfully bound ${log}`);
1154
+ if (this.debugActive) this.debug(`Successfully bound ${log}`);
1128
1155
  }
1129
1156
 
1130
1157
  callback(error);
@@ -1139,13 +1166,13 @@ class ZigbeeController extends EventEmitter {
1139
1166
  const log = ` ${ep.device.ieeeAddr} - ${cluster}`;
1140
1167
  target = !target ? this.getCoordinator() : target;
1141
1168
 
1142
- this.debug(`Unbinding ${log}`);
1169
+ if (this.debugActive) this.debug(`Unbinding ${log}`);
1143
1170
  try {
1144
1171
  ep.unbind(cluster, target, (error) => {
1145
1172
  if (error) {
1146
1173
  this.error(`Failed to unbind ${log} - (${error})`);
1147
1174
  } else {
1148
- this.debug(`Successfully unbound ${log}`);
1175
+ if (this.debugActive) this.debug(`Successfully unbound ${log}`);
1149
1176
  }
1150
1177
 
1151
1178
  callback(error);
@@ -1184,9 +1211,9 @@ class ZigbeeController extends EventEmitter {
1184
1211
  {
1185
1212
  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
1213
  const scanresult = await this.herdsman.adapter.sendZdo(0x0, 0x0, clusterId , payload, false);
1187
- this.debug(`scanresult is ${JSON.stringify(scanresult)}`)
1214
+ if (this.debugActive) this.debug(`scanresult is ${JSON.stringify(scanresult)}`)
1188
1215
  result.energyvalues = scanresult[1].entryList;
1189
- this.debug(`result is ${JSON.stringify(result)}`)
1216
+ if (this.debugActive) this.debug(`result is ${JSON.stringify(result)}`)
1190
1217
  }
1191
1218
  catch (error) {
1192
1219
  this.sendError(error);