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
package/main.js CHANGED
@@ -82,6 +82,7 @@ class Zigbee extends utils.Adapter {
82
82
  this.deviceManagement = new dmZigbee(this);
83
83
  this.deviceDebug = new DeviceDebug(this),
84
84
  this.deviceDebug.on('log', this.onLog.bind(this));
85
+ this.debugActive = true;
85
86
 
86
87
 
87
88
  this.plugins = [
@@ -119,19 +120,6 @@ class Zigbee extends utils.Adapter {
119
120
  }
120
121
  }
121
122
 
122
- warn(message) {
123
- this.log.warn(message);
124
- }
125
- debug(message) {
126
- this.log.debug(message);
127
- }
128
- error(message) {
129
- this.log.error(message);
130
- }
131
- info(message) {
132
- this.log.info(message);
133
- }
134
-
135
123
  sendError(error, message) {
136
124
  try {
137
125
  if (this.supportsFeature && this.supportsFeature('PLUGINS')) {
@@ -168,7 +156,7 @@ class Zigbee extends utils.Adapter {
168
156
  em = em || error.stack.match(/failed \((.+?)\)/);
169
157
  this.log.error(`${message} no error code (${(em ? em[1] : 'undefined')})`);
170
158
  this.sendError(error, `${message} no error code`);
171
- this.log.debug(`Stack trace for ${em}: ${error.stack}`);
159
+ if (this.debugActive) this.log.debug(`Stack trace for ${em}: ${error.stack}`);
172
160
  return;
173
161
  }
174
162
 
@@ -184,7 +172,7 @@ class Zigbee extends utils.Adapter {
184
172
  this.log.info(`${message}: Code ${error.code} (${ecode.message})`);
185
173
  break;
186
174
  case E_DEBUG:
187
- this.log.debug(`${message}: Code ${error.code} (${ecode.message})`);
175
+ if (this.debugActive) this.log.debug(`${message}: Code ${error.code} (${ecode.message})`);
188
176
  break;
189
177
  case E_WARN:
190
178
  this.log.warn(`${message}: Code ${error.code} (${ecode.message})`);
@@ -202,10 +190,14 @@ class Zigbee extends utils.Adapter {
202
190
 
203
191
  debugLog(data, ...args) {
204
192
  const message = (args) ? util.format(data, ...args) : data;
205
- this.log.debug(message.slice(message.indexOf('zigbee-herdsman')));
193
+ if (this.debugActive) this.log.debug(message.slice(message.indexOf('zigbee-herdsman')));
206
194
  }
207
195
 
208
196
  async onReady() {
197
+
198
+ const dbActive = await this.getForeignState(`system.adapter.${this.namespace}.logLevel`);
199
+ this.debugActive = (dbActive && dbActive.val === 'debug');
200
+ this.log.info('Adapter ready - starting subsystems. Adapter is running in '+dbActive.val+ ' mode.');
209
201
  if (this.config.debugHerdsman) {
210
202
  debug.log = this.debugLog.bind(this);
211
203
  debug.enable('zigbee-herdsman*');
@@ -217,6 +209,7 @@ class Zigbee extends utils.Adapter {
217
209
  this.stController.getExposes();
218
210
 
219
211
  this.subscribeStates('*');
212
+ this.subscribeForeignStates(`system.adapter.${this.namespace}.logLevel`)
220
213
  // set connection false before connect to zigbee
221
214
  this.setState('info.connection', false, true);
222
215
  const zigbeeOptions = this.getZigbeeOptions();
@@ -231,13 +224,22 @@ class Zigbee extends utils.Adapter {
231
224
  this.zbController.on('msg', this.stController.onZigbeeEvent.bind(this.stController));
232
225
  this.zbController.on('publish', this.publishToState.bind(this));
233
226
  this.zbController.configure(zigbeeOptions);
227
+ this.zbController.debugActive = this.debugActive;
228
+ this.stController.debugActive = this.debugActive;
234
229
  await this.callPluginMethod('configure', [zigbeeOptions]);
235
230
 
236
231
  // elevated debug handling
237
232
  this.deviceDebug.start(this.stController, this.zbController);
238
233
 
239
234
  this.reconnectCounter = 1;
240
- this.doConnect();
235
+ if (this.config.autostart) this.doConnect();
236
+ }
237
+ updateDebugLevel(state) {
238
+ const dbActive = state === 'debug';
239
+ this.debugActive = dbActive;
240
+ this.stController.debugActive = dbActive;
241
+ this.zbController.debugActive = dbActive;
242
+ this.log.info('Change of log level while running to ' + state);
241
243
  }
242
244
 
243
245
  sandboxAdd(sandbox, item, module) {
@@ -262,18 +264,18 @@ class Zigbee extends utils.Adapter {
262
264
 
263
265
  let zhcm1 = modulePath.match(/^zigbee-herdsman-converters\//);
264
266
  if (zhcm1) {
265
- const i2 = modulePath.replace(/^zigbee-herdsman-converters\//, `../zigbee-herdsman-converters/`);
266
267
  try {
268
+ const i2 = modulePath.replace(/^zigbee-herdsman-converters\//, `../${sandbox.zhclibBase}/`);
267
269
  this.sandboxAdd(sandbox, item[1], i2);
268
270
  }
269
271
  catch (error) {
270
- this.log.error(`Sandbox error: ${(error && error.message ? error.message : 'no error message given')}`);
272
+ this.log.error(`Sandbox error: ${(error && error.message ? error.message : 'no error message given')}`)
271
273
  }
272
274
  continue;
273
275
  }
274
276
  zhcm1 = modulePath.match(/^..\//);
275
277
  if (zhcm1) {
276
- const i2 = modulePath.replace(/^..\//, `../zigbee-herdsman-converters/`);
278
+ const i2 = modulePath.replace(/^..\//, `../${sandbox.zhclibBase}/`);
277
279
  try {
278
280
  this.sandboxAdd(sandbox, item[1], i2);
279
281
  }
@@ -303,11 +305,14 @@ class Zigbee extends utils.Adapter {
303
305
  const extfiles = this.config.external.split(';');
304
306
  for (const moduleName of extfiles) {
305
307
  if (!moduleName) continue;
308
+ const ZHCP = zigbeeHerdsmanConvertersPackage;
306
309
  const sandbox = {
307
310
  require,
308
311
  module: {},
312
+ zhclibBase : path.join('zigbee-herdsman-converters',(ZHCP && ZHCP.exports && ZHCP.exports['.'] ? path.dirname(ZHCP.exports['.']) : ''))
309
313
  };
310
- const mN = (fs.existsSync(moduleName) ? moduleName : this.expandFileName(moduleName).replace('zigbee.', 'zigbee_'));
314
+
315
+ const mN = (fs.existsSync(moduleName) ? moduleName : this.expandFileName(moduleName));
311
316
  if (!fs.existsSync(mN)) {
312
317
  this.log.warn(`External converter not loaded - neither ${moduleName} nor ${mN} exist.`);
313
318
  }
@@ -333,13 +338,18 @@ class Zigbee extends utils.Adapter {
333
338
  //fs.writeFileSync(mN+'.tmp5', modifiedCode)
334
339
  converterLoaded &= this.SandboxRequire(sandbox,[...modifiedCode.matchAll(/const\s+(\S+)\s+=\s+require\((.+)\)/gm)]);
335
340
  modifiedCode = modifiedCode.replace(/const\s+\S+\s+=\s+require\(.+\)/gm, '');
336
- //fs.writeFileSync(mN+'.tmp6', modifiedCode)
341
+ //mfs.writeFileSync(mN+'.tmp', modifiedCode)
337
342
 
338
343
  for(const component of modifiedCode.matchAll(/const (.+):(.+)=/gm)) {
339
344
  modifiedCode = modifiedCode.replace(component[0], `const ${component[1]} = `);
340
345
  }
341
346
  modifiedCode = modifiedCode.replace(/export .+;/gm, '');
342
347
 
348
+ if (modifiedCode.indexOf('module.exports') < 0) {
349
+ converterLoaded = false;
350
+ this.log.error(`converter does not export any converter array, please add 'module.exports' statement to ${mN}`);
351
+ }
352
+
343
353
  fs.writeFileSync(mN+'.tmp', modifiedCode)
344
354
 
345
355
  if (converterLoaded) {
@@ -388,7 +398,32 @@ class Zigbee extends utils.Adapter {
388
398
  }
389
399
  }
390
400
 
391
- async doConnect() {
401
+ async testConnect(from, command, message, callback) {
402
+ const response = {};
403
+ if (message.start) {
404
+ try {
405
+ this.logToPairing(`overriding zigbee options with:`);
406
+ for (const k of Object.keys(message.zigbeeOptions)) {
407
+ this.logToPairing(`${k} : ${message.zigbeeOptions[k]}`)
408
+ }
409
+ this.zbController.configure(this.getZigbeeOptions(message.zigbeeOptions));
410
+ response.status = await this.doConnect(true);
411
+ this.sendTo(from, command, response, callback);
412
+ }
413
+ catch (error) {
414
+ this.sendTo(from, command, { status:false }, callback);
415
+ }
416
+ }
417
+ else try {
418
+ await this.zbController.stopHerdsman();
419
+ //this.logToPairing('herdsman stopped !');
420
+ this.sendTo(from, command, { status:true }, callback);
421
+ } catch (error) {
422
+ this.sendTo(from, command, { status:false }, callback);
423
+ }
424
+ }
425
+
426
+ async doConnect(noReconnect) {
392
427
  let debugversion = '';
393
428
  try {
394
429
  const DebugIdentify = require('./debugidentify');
@@ -400,33 +435,44 @@ class Zigbee extends utils.Adapter {
400
435
  // installed version
401
436
  let gitVers = '';
402
437
  try {
438
+ if (noReconnect) this.logToPairing(`Starting Adapter ${debugversion}`);
403
439
  this.log.info(`Starting Adapter ${debugversion}`);
404
440
 
405
441
  this.getForeignObject(`system.adapter.${this.namespace}`,async (err, obj) => {
406
- if (!err && obj && obj.common.installedFrom && obj.common.installedFrom.includes('://')) {
407
- const instFrom = obj.common.installedFrom;
408
- gitVers = gitVers + instFrom.replace('tarball', 'commit');
409
- } else {
410
- gitVers = obj.common.installedFrom;
442
+ try {
443
+ if (!err && obj && obj.common.installedFrom && obj.common.installedFrom.includes('://')) {
444
+ const instFrom = obj.common.installedFrom;
445
+ gitVers = gitVers + instFrom.replace('tarball', 'commit');
446
+ } else {
447
+ gitVers = obj.common.installedFrom;
448
+ }
449
+ if (noReconnect) this.logToPairing(`Installed Version: ${gitVers} (Converters ${zigbeeHerdsmanConvertersPackage.version} Herdsman ${zigbeeHerdsmanPackage.version})`);
450
+ this.log.info(`Installed Version: ${gitVers} (Converters ${zigbeeHerdsmanConvertersPackage.version} Herdsman ${zigbeeHerdsmanPackage.version})`);
451
+ await this.zbController.start(noReconnect);
452
+ } catch (error) {
453
+ this.logToPairing(error && error.message ? error.message : error);
454
+ this.log.error(error && error.message ? error.message : error);
411
455
  }
412
- this.log.info(`Installed Version: ${gitVers} (Converters ${zigbeeHerdsmanConvertersPackage.version} Herdsman ${zigbeeHerdsmanPackage.version})`);
413
- await this.zbController.start();
456
+ return false;
414
457
  });
415
-
416
458
  } catch (error) {
417
459
  this.setState('info.connection', false, true);
418
- this.log.error(`Failed to start Zigbee`);
419
- if (error.stack) {
460
+ this.logToPairing(`Failed to start Zigbee: ${error && error.message ? error.message : 'no message given'}`)
461
+ this.log.error(`Failed to start Zigbee: ${error && error.message ? error.message : 'no message given'}`);
462
+ /* if (error.stack) {
420
463
  this.log.error(error.stack);
421
464
  } else {
422
465
  this.log.error(error);
423
466
  }
467
+ */
424
468
  this.sendError(error, `Failed to start Zigbee`);
469
+ if (noReconnect) return false;
425
470
 
426
471
  if (this.reconnectCounter > 0) {
427
472
  this.tryToReconnect();
428
473
  }
429
474
  }
475
+ return true;
430
476
  }
431
477
 
432
478
  UploadRequired(status) {
@@ -489,14 +535,16 @@ class Zigbee extends utils.Adapter {
489
535
  ]
490
536
  );
491
537
  const nwExtPanId = `0x${result.payload.value.reverse().toString('hex')}`;
492
- this.log.debug(`Config value ${configExtPanId} : nw value ${nwExtPanId}`);
538
+ if (this.debugActive) this.log.debug(`Config value ${configExtPanId} : nw value ${nwExtPanId}`);
539
+ this.logToPairing(`Config value ${configExtPanId} : nw value ${nwExtPanId}`)
493
540
  if (configExtPanId !== nwExtPanId) {
494
541
  networkExtPanId = nwExtPanId;
495
542
  needChange = true;
496
543
  }
497
544
  } catch (e) {
498
- this.log.error(`Unable to apply ExtPanID changes: ${e}`);
499
- this.sendError(e, `Unable to apply ExtPanID changes`);
545
+ const msg = `Unable to apply ExtPanID changes: ${e}`;
546
+ this.log.error(msg);
547
+ this.logToPairing(msg)
500
548
  needChange = false;
501
549
  }
502
550
  } else {
@@ -505,11 +553,11 @@ class Zigbee extends utils.Adapter {
505
553
  }
506
554
  if (needChange) {
507
555
  // need change config value and mark that fix is applied
508
- this.log.debug(`Fix extPanId value to ${networkExtPanId}. And restart adapter.`);
556
+ if (this.debugActive) this.log.debug(`Fix extPanId value to ${networkExtPanId}. And restart adapter.`);
509
557
  this.updateConfig({extPanID: networkExtPanId.substr(2), extPanIdFix: true});
510
558
  } else {
511
559
  // only mark that fix is applied
512
- this.log.debug(`Fix without changes. And restart adapter.`);
560
+ if (this.debugActive) this.log.debug(`Fix without changes. And restart adapter.`);
513
561
  this.updateConfig({extPanIdFix: true});
514
562
  }
515
563
  }
@@ -596,18 +644,18 @@ class Zigbee extends utils.Adapter {
596
644
  this.emit('device_debug', { ID:debugID, data: { ID: deviceId, flag: '03', IO:false }, message: message});
597
645
  }
598
646
  else
599
- this.log.debug(`publishFromState : ${deviceId} ${model} ${safeJsonStringify(stateList)}`);
647
+ if (this.debugActive) this.log.debug(`publishFromState : ${deviceId} ${model} ${safeJsonStringify(stateList)}`);
600
648
  if (model === 'group') {
601
649
  isGroup = true;
602
650
  deviceId = parseInt(deviceId);
603
651
  }
604
652
  try {
605
653
  const entity = await this.zbController.resolveEntity(deviceId);
606
- this.log.debug(`entity: ${deviceId} ${model} ${safeJsonStringify(entity)}`);
654
+ if (this.debugActive) this.log.debug(`entity: ${deviceId} ${model} ${safeJsonStringify(entity)}`);
607
655
  const mappedModel = entity ? entity.mapped : undefined;
608
656
 
609
657
  if (!mappedModel) {
610
- this.log.debug(`No mapped model for ${model}`);
658
+ if (this.debugActive) this.log.debug(`No mapped model for ${model}`);
611
659
  if (has_elevated_debug) {
612
660
  const message=`No mapped model ${deviceId} (model ${model})`;
613
661
  this.emit('device_debug', { ID:debugID, data: { error: 'NOMODEL' , IO:false }, message: message});
@@ -636,12 +684,12 @@ class Zigbee extends utils.Adapter {
636
684
  this.acknowledgeState(deviceId, model, stateDesc, value);
637
685
  }
638
686
  else {
639
- this.error('Error in SendPayload: '+result.error.message);
687
+ this.log.error('Error in SendPayload: '+result.error.message);
640
688
  }
641
689
  } catch (error) {
642
690
  const message = `send_payload: ${value} does not parse as JSON Object : ${error.message}`;
643
691
  if (has_elevated_debug) this.emit('device_debug', { ID:debugID, data: { error: 'EXSEND' ,states:[{id:stateDesc.id, value:value, payload:error.message}], IO:false }, message:message});
644
- else this.error(message);
692
+ else this.log.error(message);
645
693
  return;
646
694
  }
647
695
  return;
@@ -654,7 +702,7 @@ class Zigbee extends utils.Adapter {
654
702
  this.emit('device_debug', { ID:debugID, data: { flag: 'cc', states:[{id:stateDesc.id, value:value, payload:'none (OC State)'}] , IO:false }, message:message});
655
703
  }
656
704
  else
657
- this.log.debug('changed composite state: ' + JSON.stringify(changedState));
705
+ if (this.debugActive) this.log.debug('changed composite state: ' + JSON.stringify(changedState));
658
706
 
659
707
  this.acknowledgeState(deviceId, model, stateDesc, value);
660
708
  if (stateDesc.compositeState && stateDesc.compositeTimeout) {
@@ -673,7 +721,7 @@ class Zigbee extends utils.Adapter {
673
721
  this.emit('device_debug', { ID:debugID, data: { flag: 'qs' ,states:[{id:stateDesc.id, value:value, payload:'none for device query'}], IO:false }, message:message});
674
722
  }
675
723
  else
676
- this.log.debug(`Device query for '${entity.device.ieeeAddr}' started`);
724
+ if (this.debugActive) this.log.debug(`Device query for '${entity.device.ieeeAddr}' started`);
677
725
  for (const converter of mappedModel.toZigbee) {
678
726
  if (converter.hasOwnProperty('convertGet')) {
679
727
  for (const ckey of converter.key) {
@@ -715,7 +763,7 @@ class Zigbee extends utils.Adapter {
715
763
  for (const c of mappedModel.toZigbee) {
716
764
 
717
765
  if (!c.hasOwnProperty('convertSet')) continue;
718
- this.log.debug(`Type of toZigbee is '${typeof c}', Contains key ${(c.hasOwnProperty('key')?JSON.stringify(c.key):'false ')}`)
766
+ if (this.debugActive) this.log.debug(`Type of toZigbee is '${typeof c}', Contains key ${(c.hasOwnProperty('key')?JSON.stringify(c.key):'false ')}`)
719
767
  if (!c.hasOwnProperty('key'))
720
768
  {
721
769
  if (converter === undefined)
@@ -726,7 +774,7 @@ class Zigbee extends utils.Adapter {
726
774
  this.emit('device_debug', { ID:debugID, data: { flag: `s4.${msg_counter}` , IO:false }, message:message});
727
775
  }
728
776
  else
729
- this.log.debug(`Setting converter to keyless converter for ${deviceId} of type ${model}`);
777
+ if (this.debugActive) this.log.debug(`Setting converter to keyless converter for ${deviceId} of type ${model}`);
730
778
  msg_counter++;
731
779
  }
732
780
  else
@@ -737,7 +785,7 @@ class Zigbee extends utils.Adapter {
737
785
  this.emit('device_debug', { ID:debugID, data: { flag: `i4.${msg_counter}` , IO:false} , message:message});
738
786
  }
739
787
  else
740
- this.log.debug(`ignoring keyless converter for ${deviceId} of type ${model}`);
788
+ if (this.debugActive) this.log.debug(`ignoring keyless converter for ${deviceId} of type ${model}`);
741
789
  msg_counter++;
742
790
  }
743
791
  continue;
@@ -750,7 +798,7 @@ class Zigbee extends utils.Adapter {
750
798
 
751
799
  }
752
800
  else
753
- this.log.debug(message);
801
+ if (this.debugActive) this.log.debug(message);
754
802
  converter = c;
755
803
  msg_counter++;
756
804
  }
@@ -761,7 +809,7 @@ class Zigbee extends utils.Adapter {
761
809
  this.emit('device_debug', { ID:debugID, data: { error: 'NOCONV',states:[{id:stateDesc.id, value:value, payload:'no converter'}] , IO:false }, message:message});
762
810
  }
763
811
  else {
764
- this.log.warn(message);
812
+ this.log.info(message);
765
813
  }
766
814
  return;
767
815
  }
@@ -786,7 +834,7 @@ class Zigbee extends utils.Adapter {
786
834
  this.emit('device_debug', { ID:debugID, data: { flag: '04', payload: {key:key, ep: stateDesc.epname, value:preparedValue, options:preparedOptions}, IO:false }, message:message});
787
835
  }
788
836
  else
789
- this.log.debug(message);
837
+ if (this.debugActive) this.log.debug(message);
790
838
 
791
839
  let target;
792
840
  if (model === 'group') {
@@ -796,7 +844,7 @@ class Zigbee extends utils.Adapter {
796
844
  target = target.endpoint;
797
845
  }
798
846
 
799
- this.log.debug(`target: ${safeJsonStringify(target)}`);
847
+ if (this.debugActive) this.log.debug(`target: ${safeJsonStringify(target)}`);
800
848
 
801
849
  const meta = {
802
850
  endpoint_name: epName,
@@ -833,7 +881,7 @@ class Zigbee extends utils.Adapter {
833
881
  this.emit('device_debug', { ID:debugID, data: { flag: 'SUCCESS' , IO:false }, message:message});
834
882
  }
835
883
  else
836
- this.log.debug(message);
884
+ if (this.debugActive) this.log.debug(message);
837
885
  if (result !== undefined) {
838
886
  if (stateModel && !isGroup && !stateDesc.noack) {
839
887
  this.acknowledgeState(deviceId, model, stateDesc, value);
@@ -969,6 +1017,10 @@ class Zigbee extends utils.Adapter {
969
1017
 
970
1018
 
971
1019
  newDevice(entity) {
1020
+
1021
+ if (this.debugActive) this.log.debug(`New device event: ${safeJsonStringify(entity)}`);
1022
+ this.stController.AddModelFromHerdsman(entity.device, entity.mapped ? entity.mapped.model : entity.device.modelID)
1023
+
972
1024
  const dev = entity.device;
973
1025
  const model = (entity.mapped) ? entity.mapped.model : dev.modelID;
974
1026
  this.log.debug(`New device event: ${safeJsonStringify(entity)}`);
@@ -981,21 +1033,23 @@ class Zigbee extends utils.Adapter {
981
1033
  if (dev) {
982
1034
  this.getObject(dev.ieeeAddr.substr(2), (err, obj) => {
983
1035
  if (!obj) {
984
- this.log.debug(`new device ${dev.ieeeAddr} ${dev.networkAddress} ${model} `);
1036
+ const model = (entity.mapped) ? entity.mapped.model : entity.device.modelID;
1037
+ if (this.debugActive) this.log.debug(`new device ${dev.ieeeAddr} ${dev.networkAddress} ${model} `);
1038
+
985
1039
  this.logToPairing(`New device joined '${dev.ieeeAddr}' model ${model}`, true);
986
1040
  this.stController.updateDev(dev.ieeeAddr.substr(2), model, model, () =>
987
1041
  this.stController.syncDevStates(dev, model));
988
1042
  }
989
- else this.log.debug(`Device ${safeJsonStringify(entity)} rejoined, no new device`);
1043
+ else if (this.debugActive) this.log.debug(`Device ${safeJsonStringify(entity)} rejoined, no new device`);
990
1044
  });
991
1045
  }
992
1046
  }
993
1047
 
994
1048
  leaveDevice(ieeeAddr) {
995
- this.log.debug(`Leave device event: ${ieeeAddr}`);
1049
+ if (this.debugActive) this.log.debug(`Leave device event: ${ieeeAddr}`);
996
1050
  if (ieeeAddr) {
997
1051
  const devId = ieeeAddr.substr(2);
998
- this.log.debug(`Delete device ${devId} from iobroker.`);
1052
+ if (this.debugActive) this.log.debug(`Delete device ${devId} from iobroker.`);
999
1053
  this.stController.deleteObj(devId);
1000
1054
  }
1001
1055
  }
@@ -1030,12 +1084,13 @@ class Zigbee extends utils.Adapter {
1030
1084
  debug.log = originalLogMethod;
1031
1085
  }
1032
1086
 
1033
- this.log.info('cleaned everything up...');
1034
- if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
1087
+ this.log.info('cleaning everything up...');
1035
1088
  await this.callPluginMethod('stop');
1089
+ await this.stController.stop();
1036
1090
  if (this.zbController) {
1037
1091
  await this.zbController.stop();
1038
1092
  }
1093
+ this.log.info('cleanup successful');
1039
1094
  callback();
1040
1095
  } catch (error) {
1041
1096
  if (error) {
@@ -1046,10 +1101,10 @@ class Zigbee extends utils.Adapter {
1046
1101
  }
1047
1102
  }
1048
1103
 
1049
- getZigbeeOptions() {
1104
+ getZigbeeOptions(_overrideOptions) {
1105
+ const override = (_overrideOptions ? _overrideOptions:{});
1050
1106
  // file path for db
1051
- let dbDir = path.join(utils.getAbsoluteInstanceDataDir(this), '');
1052
- dbDir = dbDir.replace('zigbee.', 'zigbee_');
1107
+ const dbDir = this.expandFileName('');
1053
1108
 
1054
1109
  if (this.systemConfig && !fs.existsSync(dbDir)) {
1055
1110
  try {
@@ -1059,21 +1114,21 @@ class Zigbee extends utils.Adapter {
1059
1114
  this.sendError(`Cannot create directory ${dbDir}: ${e}`);
1060
1115
  }
1061
1116
  }
1062
- const port = this.config.port;
1117
+ const port = override.port ? override.port : this.config.port;
1063
1118
  if (!port) {
1064
1119
  this.log.error('Serial port not selected! Go to settings page.');
1065
1120
  this.sendError('Serial port not selected! Go to settings page.');
1066
1121
  }
1067
- const panID = parseInt(this.config.panID ? this.config.panID : 0x1a62);
1068
- const channel = parseInt(this.config.channel ? this.config.channel : 11);
1069
- const precfgkey = createByteArray(this.config.precfgkey ? this.config.precfgkey : '01030507090B0D0F00020406080A0C0D');
1070
- const extPanId = createByteArray(this.config.extPanID ? this.config.extPanID : 'DDDDDDDDDDDDDDDD').reverse();
1071
- const adapterType = this.config.adapterType || 'zstack';
1122
+ const panID = parseInt(override.panID ? override.panID : this.config.panID ? this.config.panID : 0x1a62);
1123
+ const channel = parseInt(override.channel ? override.channel : this.config.channel ? this.config.channel : 11);
1124
+ const precfgkey = createByteArray(override.precfgkey ? override.precfgkey : this.config.precfgkey ? this.config.precfgkey : '01030507090B0D0F00020406080A0C0D');
1125
+ const extPanId = createByteArray(override.extPanID ? override.extPanID : this.config.extPanID ? this.config.extPanID : 'DDDDDDDDDDDDDDDD').reverse();
1126
+ const adapterType = override.adapterType ? override.adapterType : this.config.adapterType || 'zstack';
1072
1127
  // https://github.com/ioBroker/ioBroker.zigbee/issues/668
1073
1128
  const extPanIdFix = this.config.extPanIdFix ? this.config.extPanIdFix : false;
1074
- const baudRate = parseInt(this.config.baudRate ? this.config.baudRate : 115200);
1129
+ const baudRate = parseInt(override.baudRate ? override.baudRate : this.config.baudRate ? this.config.baudRate : 115200);
1075
1130
 
1076
- const setRtscts = this.config.flowCTRL ? this.config.flowCTRL : false;
1131
+ const setRtscts = override.flowCTRL ? override.flowCTRL : this.config.flowCTRL ? this.config.flowCTRL : false;
1077
1132
 
1078
1133
  return {
1079
1134
  net: {
@@ -1088,6 +1143,7 @@ class Zigbee extends utils.Adapter {
1088
1143
  rtscts: setRtscts,
1089
1144
  adapter: adapterType,
1090
1145
  },
1146
+ transmitpower: this.transmitPower,
1091
1147
  dbDir: dbDir,
1092
1148
  dbPath: 'shepherd.db',
1093
1149
  backupPath: 'nvbackup.json',
@@ -1096,7 +1152,7 @@ class Zigbee extends utils.Adapter {
1096
1152
  transmitPower: this.config.transmitPower,
1097
1153
  disableBackup: this.config.disableBackup,
1098
1154
  extPanIdFix: extPanIdFix,
1099
- startWithInconsistent: this.config.startWithInconsistent || false,
1155
+ startWithInconsistent: override.startWithInconsistent ? override.startWithInconsistent: this.config.startWithInconsistent || false,
1100
1156
  };
1101
1157
  }
1102
1158
 
@@ -1120,7 +1176,12 @@ class Zigbee extends utils.Adapter {
1120
1176
  }
1121
1177
 
1122
1178
  expandFileName(fn) {
1123
- return path.join(utils.getAbsoluteInstanceDataDir(this), fn);
1179
+ return path.join(this.getDataFolder(), fn);
1180
+ }
1181
+
1182
+ getDataFolder() {
1183
+ const datapath=this.namespace.replace('.','_');
1184
+ return path.join(utils.getAbsoluteInstanceDataDir(this).replace(this.namespace, datapath));
1124
1185
  }
1125
1186
 
1126
1187
  onLog(level, msg, data) {
@@ -1131,7 +1192,8 @@ class Zigbee extends utils.Adapter {
1131
1192
  logger = this.log.error;
1132
1193
  if (data)
1133
1194
  data = data.toString();
1134
- this.logToPairing(`Error: ${msg}. ${data}`, true);
1195
+ if (this.ErrorMessagesToPairing)
1196
+ this.logToPairing(`Error: ${msg}. ${data}`, true);
1135
1197
  this.sendError(`Error: ${msg}. ${data}`);
1136
1198
  break;
1137
1199
  case 'debug':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.zigbee",
3
- "version": "2.0.5",
3
+ "version": "3.0.1",
4
4
  "author": {
5
5
  "name": "Kirov Ilya",
6
6
  "email": "kirovilya@gmail.com"
@@ -18,18 +18,18 @@
18
18
  "node": ">=18"
19
19
  },
20
20
  "optionalDependencies": {
21
- "serialport": "^12.0.0"
21
+ "serialport": "^13.0.0"
22
22
  },
23
23
  "dependencies": {
24
- "@iobroker/adapter-core": "^3.2.2",
25
- "@iobroker/dm-utils": "^0.5.0",
24
+ "@iobroker/adapter-core": "^3.2.3",
25
+ "@iobroker/dm-utils": "^1.0.9",
26
26
  "humanize-duration": "^3.32.1",
27
27
  "tar": "^7.4.3",
28
28
  "ajv": "^8.17.1",
29
29
  "uri-js": "^4.4.1",
30
30
  "typescript": "^5.6.3",
31
- "zigbee-herdsman": "^3.3.0",
32
- "zigbee-herdsman-converters": "23.6.0"
31
+ "zigbee-herdsman": "3.3.2",
32
+ "zigbee-herdsman-converters": "23.13.0"
33
33
  },
34
34
  "description": "Zigbee devices",
35
35
  "devDependencies": {
@@ -37,12 +37,12 @@
37
37
  "@alcalzone/release-script-plugin-iobroker": "^3.7.2",
38
38
  "@alcalzone/release-script-plugin-license": "^3.7.0",
39
39
  "@alcalzone/release-script-plugin-manual-review": "^3.7.0",
40
- "@iobroker/testing": "^5.0.0",
40
+ "@iobroker/testing": "^5.0.4",
41
41
  "chai": "^5.1.2",
42
42
  "chai-as-promised": "^7.1.1",
43
43
  "eslint": "^9.19.0",
44
44
  "eslint-config-prettier": "^9.1.0",
45
- "eslint-plugin-prettier": "^5.2.3",
45
+ "eslint-plugin-prettier": "^5.2.5",
46
46
  "gulp": "^4.0.2",
47
47
  "gulp-jsdoc3": "^3.0.0",
48
48
  "gulp-replace": "^1.1.4",
Binary file
Binary file
Binary file
Binary file
Binary file