iobroker.zigbee 3.1.6 → 3.2.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.
package/main.js CHANGED
@@ -37,7 +37,7 @@ const dmZigbee = require('./lib/devicemgmt.js');
37
37
  const DeviceDebug = require('./lib/DeviceDebug');
38
38
  const dns = require('dns');
39
39
  const net = require('net');
40
- const { getNetAddress } = require('./lib/utils')
40
+ const { getNetAddress, zbIdorIeeetoAdId, adIdtoZbIdorIeee , removeFromArray } = require('./lib/utils');
41
41
 
42
42
  const createByteArray = function (hexString) {
43
43
  const bytes = [];
@@ -231,6 +231,8 @@ class Zigbee extends utils.Adapter {
231
231
  this.stController.on('changed', this.zbController.publishFromState.bind(this.zbController));
232
232
  this.stController.on('device_query', this.zbController.deviceQuery.bind(this.zbController));
233
233
  this.zbController.on('acknowledge_state', this.acknowledgeState.bind(this));
234
+ this.zbController.on('stash_error', this.stController.stashErrors.bind(this.stController));
235
+ this.zbController.on('stash_unknown_model', this.stController.stashUnknownModel.bind(this.stController));
234
236
 
235
237
  this.zbController.configure(zigbeeOptions);
236
238
  this.zbController.debugActive = this.debugActive;
@@ -302,6 +304,7 @@ class Zigbee extends utils.Adapter {
302
304
 
303
305
  * getExternalDefinition() {
304
306
 
307
+
305
308
  if (this.config.external === undefined) {
306
309
  return;
307
310
  }
@@ -353,20 +356,22 @@ class Zigbee extends utils.Adapter {
353
356
  try {
354
357
  this.log.warn('Trying to run sandbox for ' + mN);
355
358
  vm.runInNewContext(modifiedCode, sandbox);
356
- const converter = sandbox.module.exports;
359
+ const sandboxResult = sandbox.module.exports;
360
+ const converter = Array.isArray(sandboxResult) ? sandboxResult : [sandboxResult];
357
361
 
358
- if (Array.isArray(converter)) for (const item of converter) {
359
- this.log.info('Model ' + item.model + ' defined in external converter ' + mN);
362
+ for (const item of converter) {
360
363
  if (item.hasOwnProperty('icon')) {
361
364
  if (!item.icon.toLowerCase().startsWith('http') && !item.useadaptericon)
362
365
  item.icon = path.join(path.dirname(mN), item.icon);
363
366
  }
364
- yield item;
365
- }
366
- else {
367
- this.log.info('Model ' + converter.model + ' defined in external converter ' + mN);
368
- yield converter;
367
+ const rtz = removeFromArray(item.toZigbee);
368
+ const rfz = removeFromArray(item.fromZigbee);
369
+ const rtzfzmsg = [];
370
+ if (rtz) rtzfzmsg.push(`${rtz} unknown entr${rtz>1?'ies' : 'y'} in toZigbee`);
371
+ if (rfz) rtzfzmsg.push(`${rfz} unknown entr${rtz>1?'ies' : 'y'} in fromZigbee`);
372
+ this.log.info(`Model ${item.model} defined ${rtz+rfz ? 'with '+ rtzfzmsg.join(' and ') + ' ' : ''}in external converter ${mN}`);
369
373
  }
374
+ yield converter;
370
375
  }
371
376
  catch (e) {
372
377
  this.log.error(`Unable to apply converter from module: ${mN} - the code does not run: ${e}`);
@@ -381,17 +386,19 @@ class Zigbee extends utils.Adapter {
381
386
 
382
387
  applyExternalConverters() {
383
388
  for (const definition of this.getExternalDefinition()) {
384
- const toAdd = {...definition};
385
- delete toAdd['homeassistant'];
389
+ const toAdd = definition;
386
390
  try {
387
- const t = Date.now();
388
- if (zigbeeHerdsmanConverters.hasOwnProperty('addExternalDefinition')) {
389
- zigbeeHerdsmanConverters.addExternalDefinition(toAdd);
390
- this.log.info(`added external converter using addExternalDefinition (${Date.now()-t} ms)`)
391
- }
392
- else if (zigbeeHerdsmanConverters.hasOwnProperty('addDefinition')) {
393
- zigbeeHerdsmanConverters.addDefinition(toAdd);
394
- this.log.info(`added external converter using addDefinition (${Date.now()-t} ms)`);
391
+ for (const item of toAdd) {
392
+ delete item['homeassistant'];
393
+ const t = Date.now();
394
+ if (zigbeeHerdsmanConverters.hasOwnProperty('addExternalDefinition')) {
395
+ zigbeeHerdsmanConverters.addExternalDefinition(item);
396
+ this.log.info(`added external converter using addExternalDefinition (${Date.now()-t} ms)`)
397
+ }
398
+ else if (zigbeeHerdsmanConverters.hasOwnProperty('addDefinition')) {
399
+ zigbeeHerdsmanConverters.addDefinition(item);
400
+ this.log.info(`added external converter using addDefinition (${Date.now()-t} ms)`);
401
+ }
395
402
  }
396
403
  } catch (e) {
397
404
  this.log.error(`unable to apply external converter for ${JSON.stringify(toAdd.model)}: ${e && e.message ? e.message : 'no error message available'}`);
@@ -399,32 +406,39 @@ class Zigbee extends utils.Adapter {
399
406
  }
400
407
  }
401
408
 
402
- async testConnect(from, command, message, callback) {
409
+ async testConnect(message) {
403
410
  const response = {};
411
+ if (this.reconnectTimer) this.clearTimeout(this.reconnectTimer);
412
+ this.reconnectTimer = null;
413
+ const zo = message.zigbeeOptions || {};
404
414
  if (message.start) {
405
415
  try {
406
- this.logToPairing(`overriding zigbee options with:`);
407
- for (const k of Object.keys(message.zigbeeOptions)) {
408
- this.logToPairing(`${k} : ${message.zigbeeOptions[k]}`)
416
+ const keys = Object.keys(zo);
417
+ if (keys) {
418
+ this.logToPairing(`overriding zigbee options with:`);
419
+ for (const k of keys) {
420
+ this.logToPairing(`${k} : ${zo[k]}`)
421
+ }
409
422
  }
410
- this.zbController.configure(this.getZigbeeOptions(message.zigbeeOptions));
423
+ this.zbController.configure(this.getZigbeeOptions(zo));
411
424
  response.status = await this.doConnect(true);
412
425
  if (!response.status) response.error = { message: 'Unable to start the Zigbee Network. Please check the previous messages.'}
413
- this.sendTo(from, command, response, callback);
426
+ return response;
414
427
  }
415
428
  catch (error) {
416
- this.sendTo(from, command, { status:false, error }, callback);
429
+ return { status:false, error };
417
430
  }
418
431
  }
419
432
  else try {
420
433
  await this.zbController.stopHerdsman();
421
- this.sendTo(from, command, { status:true }, callback);
434
+ return { status:true };
422
435
  } catch (error) {
423
- this.sendTo(from, command, { status:true, error }, callback);
436
+ return { status:true, error };
424
437
  }
425
438
  }
426
439
 
427
440
  async doConnect(noReconnect) {
441
+
428
442
  let debugversion = '';
429
443
  try {
430
444
  const DebugIdentify = require('./debugidentify');
@@ -625,7 +639,7 @@ class Zigbee extends utils.Adapter {
625
639
  const model = entity.mapped ? entity.mapped.model : entity.device.modelID;
626
640
  const idx = devicesFromObjects.indexOf(device.ieeeAddr);
627
641
  if (idx > -1) devicesFromObjects.splice(idx, 1);
628
- this.stController.updateDev(device.ieeeAddr.substr(2), model, model, () =>
642
+ this.stController.updateDev(zbIdorIeeetoAdId(this.adapter, device.ieeeAddr, false), model, model, () =>
629
643
  this.stController.syncDevStates(device, model));
630
644
  }
631
645
  else (this.log.warn('resolveEntity returned no entity'));
@@ -643,25 +657,29 @@ class Zigbee extends utils.Adapter {
643
657
  }
644
658
 
645
659
 
660
+ /*
646
661
  async checkIfModelUpdate(entity) {
647
662
  const model = entity.mapped ? entity.mapped.model : entity.device.modelID;
648
663
  const device = entity.device;
649
- const devId = device.ieeeAddr.substr(2);
664
+ const devId = zbIdorIeeetoAdId(this.adapter, device.ieeeAddr, false);//device.ieeeAddr.substr(2);
650
665
 
651
666
  const obj = await this.getObjectAsync(devId);
652
667
  if (obj && obj.common.type !== model) {
653
- await this.stController.deleteObj(devId);
668
+ // await this.stController.deleteObj(devId);
654
669
  await this.stController.updateDev(devId, model, model);
655
670
  await this.stController.syncDevStates(device, model);
671
+ await this.stController.deleteOrphanedDeviceStates();
656
672
  }
657
673
  }
674
+ */
658
675
 
659
676
  acknowledgeState(deviceId, model, stateDesc, value) {
660
- const stateId = (model === 'group' ?
677
+ const stateId = `${zbIdorIeeetoAdId(this, deviceId, true)}.${stateDesc.id}`;
678
+ /*const stateId = (model === 'group' ?
661
679
  `${this.namespace}.group_${deviceId}.${stateDesc.id}` :
662
- `${this.namespace}.${deviceId.replace('0x', '')}.${stateDesc.id}`);
680
+ `${this.namespace}.${deviceId.replace('0x', '')}.${stateDesc.id}`); */
663
681
  if (value === undefined) try {
664
- this.getState(stateId, (err, state) => { if (!err && state.hasOwnProperty('val')) this.setState(stateId, state.val, true)});
682
+ this.getState(stateId, (err, state) => { if (!err && state?.hasOwnProperty('val')) this.setState(stateId, state.val, true)});
665
683
  }
666
684
  catch (error) {
667
685
  this.log.warn(`Error acknowledging ${stateId} without value: ${error && error.message ? error.message : 'no reason given'}`);
@@ -691,13 +709,13 @@ class Zigbee extends utils.Adapter {
691
709
  }
692
710
  await this.stController.AddModelFromHerdsman(entity.device, model)
693
711
  if (dev) {
694
- this.getObject(dev.ieeeAddr.substr(2), (err, obj) => {
712
+ this.getObject(zbIdorIeeetoAdId(this.adapter, dev.ieeeAddr, false), (err, obj) => {
695
713
  if (!obj) {
696
714
  const model = (entity.mapped) ? entity.mapped.model : entity.device.modelID;
697
715
  if (this.debugActive) this.log.debug(`new device ${dev.ieeeAddr} ${dev.networkAddress} ${model} `);
698
716
 
699
717
  this.logToPairing(`New device joined '${dev.ieeeAddr}' model ${model}`, true);
700
- this.stController.updateDev(dev.ieeeAddr.substr(2), model, model, () =>
718
+ this.stController.updateDev(zbIdorIeeetoAdId(this.adapter, dev.ieeeAddr, false), model, model, () =>
701
719
  this.stController.syncDevStates(dev, model));
702
720
  }
703
721
  else if (this.debugActive) this.log.debug(`Device ${safeJsonStringify(entity)} rejoined, no new device`);
@@ -708,7 +726,7 @@ class Zigbee extends utils.Adapter {
708
726
  leaveDevice(ieeeAddr) {
709
727
  if (this.debugActive) this.log.debug(`Leave device event: ${ieeeAddr}`);
710
728
  if (ieeeAddr) {
711
- const devId = ieeeAddr.substr(2);
729
+ const devId = zbIdorIeeetoAdId(this.adapter, ieeeAddr, false);
712
730
  if (this.debugActive) this.log.debug(`Delete device ${devId} from iobroker.`);
713
731
  this.stController.deleteObj(devId);
714
732
  }
@@ -808,6 +826,7 @@ class Zigbee extends utils.Adapter {
808
826
  dbDir: dbDir,
809
827
  dbPath: 'shepherd.db',
810
828
  backupPath: 'nvbackup.json',
829
+ localConfigPath: 'LocalOverrides.json',
811
830
  disableLed: this.config.disableLed,
812
831
  disablePing: (this.config.pingCluster=='off'),
813
832
  transmitPower: this.config.transmitPower,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.zigbee",
3
- "version": "3.1.6",
3
+ "version": "3.2.1",
4
4
  "author": {
5
5
  "name": "Kirov Ilya",
6
6
  "email": "kirovilya@gmail.com"
@@ -39,12 +39,10 @@
39
39
  "@alcalzone/release-script-plugin-manual-review": "^3.7.0",
40
40
  "@iobroker/testing": "^5.1.1",
41
41
  "chai": "^5.2.1",
42
- "chai-as-promised": "^7.1.1",
43
42
  "eslint": "^9.36.0",
44
43
  "eslint-config-prettier": "^9.1.0",
45
44
  "eslint-plugin-prettier": "^5.5.4",
46
45
  "mixin-deep": "^2.0.1",
47
- "mocha": "^11.7.1",
48
46
  "@iobroker/dev-server": "^0.7.8"
49
47
  },
50
48
  "homepage": "https://github.com/ioBroker/ioBroker.zigbee",