zigbee-herdsman 0.49.3 → 0.50.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.
Files changed (41) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/dist/adapter/ember/adapter/emberAdapter.d.ts +4 -2
  4. package/dist/adapter/ember/adapter/emberAdapter.d.ts.map +1 -1
  5. package/dist/adapter/ember/adapter/emberAdapter.js +359 -318
  6. package/dist/adapter/ember/adapter/emberAdapter.js.map +1 -1
  7. package/dist/adapter/ember/adapter/endpoints.d.ts.map +1 -1
  8. package/dist/adapter/ember/adapter/endpoints.js +2 -3
  9. package/dist/adapter/ember/adapter/endpoints.js.map +1 -1
  10. package/dist/adapter/ember/adapter/oneWaitress.d.ts +3 -3
  11. package/dist/adapter/ember/adapter/oneWaitress.js +1 -1
  12. package/dist/adapter/ember/adapter/oneWaitress.js.map +1 -1
  13. package/dist/adapter/ember/adapter/tokensManager.js +16 -16
  14. package/dist/adapter/ember/adapter/tokensManager.js.map +1 -1
  15. package/dist/adapter/ember/consts.d.ts +0 -50
  16. package/dist/adapter/ember/consts.d.ts.map +1 -1
  17. package/dist/adapter/ember/consts.js +1 -53
  18. package/dist/adapter/ember/consts.js.map +1 -1
  19. package/dist/adapter/ember/ezsp/ezsp.d.ts +2 -3
  20. package/dist/adapter/ember/ezsp/ezsp.d.ts.map +1 -1
  21. package/dist/adapter/ember/ezsp/ezsp.js +30 -12
  22. package/dist/adapter/ember/ezsp/ezsp.js.map +1 -1
  23. package/dist/adapter/ember/utils/initters.d.ts.map +1 -1
  24. package/dist/adapter/ember/utils/initters.js +28 -4
  25. package/dist/adapter/ember/utils/initters.js.map +1 -1
  26. package/dist/adapter/ezsp/driver/driver.d.ts.map +1 -1
  27. package/dist/adapter/ezsp/driver/driver.js +1 -0
  28. package/dist/adapter/ezsp/driver/driver.js.map +1 -1
  29. package/dist/controller/controller.d.ts.map +1 -1
  30. package/dist/controller/controller.js +5 -9
  31. package/dist/controller/controller.js.map +1 -1
  32. package/dist/controller/events.d.ts +2 -5
  33. package/dist/controller/events.d.ts.map +1 -1
  34. package/dist/controller/events.js +1 -98
  35. package/dist/controller/events.js.map +1 -1
  36. package/dist/zspec/zcl/definition/cluster.d.ts.map +1 -1
  37. package/dist/zspec/zcl/definition/cluster.js +6 -28
  38. package/dist/zspec/zcl/definition/cluster.js.map +1 -1
  39. package/dist/zspec/zcl/definition/tstype.d.ts +1 -1
  40. package/dist/zspec/zcl/definition/tstype.d.ts.map +1 -1
  41. package/package.json +12 -6
@@ -36,13 +36,15 @@ const socketPortUtils_1 = __importDefault(require("../../socketPortUtils"));
36
36
  const utils_1 = require("../../../utils");
37
37
  const __1 = require("../..");
38
38
  const Zcl = __importStar(require("../../../zspec/zcl"));
39
+ const enums_1 = require("../../../zspec/enums");
40
+ const ZSpec = __importStar(require("../../../zspec/consts"));
39
41
  const events_1 = require("../../events");
40
42
  const math_1 = require("../utils/math");
41
43
  const ezsp_1 = require("../ezsp/ezsp");
42
44
  const consts_1 = require("../ezsp/consts");
43
- const enums_1 = require("../ezsp/enums");
45
+ const enums_2 = require("../ezsp/enums");
44
46
  const buffalo_1 = require("../ezsp/buffalo");
45
- const enums_2 = require("../enums");
47
+ const enums_3 = require("../enums");
46
48
  const zdo_1 = require("../zdo");
47
49
  const consts_2 = require("../consts");
48
50
  const requestQueue_1 = require("./requestQueue");
@@ -143,7 +145,7 @@ const DEFAULT_STACK_CONFIG = {
143
145
  *
144
146
  * Removing `ENABLE_ROUTE_DISCOVERY` leads to devices that won't reconnect/go offline, and various other issues. Keeping it for now.
145
147
  */
146
- const DEFAULT_APS_OPTIONS = (enums_2.EmberApsOption.RETRY | enums_2.EmberApsOption.ENABLE_ROUTE_DISCOVERY | enums_2.EmberApsOption.ENABLE_ADDRESS_DISCOVERY);
148
+ const DEFAULT_APS_OPTIONS = (enums_3.EmberApsOption.RETRY | enums_3.EmberApsOption.ENABLE_ROUTE_DISCOVERY | enums_3.EmberApsOption.ENABLE_ADDRESS_DISCOVERY);
147
149
  /**
148
150
  * Enabling this allows to immediately reject requests that won't be able to get to their destination.
149
151
  * However, it causes more NCP calls, notably to get the source route overhead.
@@ -196,6 +198,7 @@ class EmberAdapter extends __1.Adapter {
196
198
  * NOTE: Do not use directly, use getter functions for it that check if valid or need retrieval from NCP.
197
199
  */
198
200
  networkCache;
201
+ multicastTable;
199
202
  constructor(networkOptions, serialPortOptions, backupPath, adapterOptions) {
200
203
  super(networkOptions, serialPortOptions, backupPath, adapterOptions);
201
204
  this.stackConfig = this.loadStackConfig();
@@ -206,7 +209,7 @@ class EmberAdapter extends __1.Adapter {
206
209
  this.zdoRequestBuffalo = new buffalo_1.EzspBuffalo(Buffer.alloc(consts_1.EZSP_MAX_FRAME_LENGTH));
207
210
  this.ezsp = new ezsp_1.Ezsp(delay, serialPortOptions);
208
211
  this.ezsp.on(ezsp_1.EzspEvents.STACK_STATUS, this.onStackStatus.bind(this));
209
- this.ezsp.on(ezsp_1.EzspEvents.MESSAGE_SENT_DELIVERY_FAILED, this.onMessageSentDeliveryFailed.bind(this));
212
+ this.ezsp.on(ezsp_1.EzspEvents.MESSAGE_SENT, this.onMessageSent.bind(this));
210
213
  this.ezsp.on(ezsp_1.EzspEvents.ZDO_RESPONSE, this.onZDOResponse.bind(this));
211
214
  this.ezsp.on(ezsp_1.EzspEvents.END_DEVICE_ANNOUNCE, this.onEndDeviceAnnounce.bind(this));
212
215
  this.ezsp.on(ezsp_1.EzspEvents.INCOMING_MESSAGE, this.onIncomingMessage.bind(this));
@@ -318,27 +321,27 @@ class EmberAdapter extends __1.Adapter {
318
321
  // to be extra careful, should clear network cache upon receiving this.
319
322
  this.clearNetworkCache();
320
323
  switch (status) {
321
- case enums_2.EmberStatus.NETWORK_UP: {
324
+ case enums_3.EmberStatus.NETWORK_UP: {
322
325
  this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_UP);
323
326
  logger_1.logger.info(`[STACK STATUS] Network up.`, NS);
324
327
  break;
325
328
  }
326
- case enums_2.EmberStatus.NETWORK_DOWN: {
329
+ case enums_3.EmberStatus.NETWORK_DOWN: {
327
330
  this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_DOWN);
328
331
  logger_1.logger.info(`[STACK STATUS] Network down.`, NS);
329
332
  break;
330
333
  }
331
- case enums_2.EmberStatus.NETWORK_OPENED: {
334
+ case enums_3.EmberStatus.NETWORK_OPENED: {
332
335
  this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_OPENED);
333
336
  logger_1.logger.info(`[STACK STATUS] Network opened.`, NS);
334
337
  break;
335
338
  }
336
- case enums_2.EmberStatus.NETWORK_CLOSED: {
339
+ case enums_3.EmberStatus.NETWORK_CLOSED: {
337
340
  this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_CLOSED);
338
341
  logger_1.logger.info(`[STACK STATUS] Network closed.`, NS);
339
342
  break;
340
343
  }
341
- case enums_2.EmberStatus.CHANNEL_CHANGED: {
344
+ case enums_3.EmberStatus.CHANNEL_CHANGED: {
342
345
  this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_CHANNEL_CHANGED);
343
346
  // invalidate cache
344
347
  this.networkCache.parameters.radioChannel = consts_2.INVALID_RADIO_CHANNEL;
@@ -346,7 +349,7 @@ class EmberAdapter extends __1.Adapter {
346
349
  break;
347
350
  }
348
351
  default: {
349
- logger_1.logger.debug(`[STACK STATUS] ${enums_2.EmberStatus[status]}.`, NS);
352
+ logger_1.logger.debug(`[STACK STATUS] ${enums_3.EmberStatus[status]}.`, NS);
350
353
  break;
351
354
  }
352
355
  }
@@ -359,24 +362,59 @@ class EmberAdapter extends __1.Adapter {
359
362
  * @param indexOrDestination
360
363
  * @param apsFrame
361
364
  * @param messageTag
365
+ * @param status
362
366
  */
363
- async onMessageSentDeliveryFailed(type, indexOrDestination, apsFrame, messageTag) {
364
- switch (type) {
365
- case enums_2.EmberOutgoingMessageType.BROADCAST:
366
- case enums_2.EmberOutgoingMessageType.BROADCAST_WITH_ALIAS:
367
- case enums_2.EmberOutgoingMessageType.MULTICAST:
368
- case enums_2.EmberOutgoingMessageType.MULTICAST_WITH_ALIAS: {
369
- // BC/MC not checking for message sent, avoid unnecessary waitress lookups
370
- logger_1.logger.error(`Delivery of ${enums_2.EmberOutgoingMessageType[type]} failed for "${indexOrDestination}" `
371
- + `[apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
372
- break;
367
+ async onMessageSent(type, indexOrDestination, apsFrame, messageTag, status) {
368
+ if (status === enums_3.EmberStatus.DELIVERY_FAILED) {
369
+ // no ACK was received from the destination
370
+ switch (type) {
371
+ case enums_3.EmberOutgoingMessageType.BROADCAST:
372
+ case enums_3.EmberOutgoingMessageType.BROADCAST_WITH_ALIAS:
373
+ case enums_3.EmberOutgoingMessageType.MULTICAST:
374
+ case enums_3.EmberOutgoingMessageType.MULTICAST_WITH_ALIAS: {
375
+ // BC/MC not checking for message sent, avoid unnecessary waitress lookups
376
+ logger_1.logger.error(`Delivery of ${enums_3.EmberOutgoingMessageType[type]} failed for "${indexOrDestination}" `
377
+ + `[apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
378
+ break;
379
+ }
380
+ default: {
381
+ // reject any waitress early (don't wait for timeout if we know we're gonna get there eventually)
382
+ this.oneWaitress.deliveryFailedFor(indexOrDestination, apsFrame);
383
+ break;
384
+ }
373
385
  }
374
- default: {
375
- // reject any waitress early (don't wait for timeout if we know we're gonna get there eventually)
376
- this.oneWaitress.deliveryFailedFor(indexOrDestination, apsFrame);
377
- break;
386
+ }
387
+ else if (status === enums_3.EmberStatus.SUCCESS) {
388
+ if (type === enums_3.EmberOutgoingMessageType.MULTICAST && apsFrame.destinationEndpoint === 0xFF &&
389
+ apsFrame.groupId < consts_2.EMBER_MIN_BROADCAST_ADDRESS && !this.multicastTable.includes(apsFrame.groupId)) {
390
+ // workaround for devices using multicast for state update (coordinator passthrough)
391
+ const tableIdx = this.multicastTable.length;
392
+ const multicastEntry = {
393
+ multicastId: apsFrame.groupId,
394
+ endpoint: endpoints_1.FIXED_ENDPOINTS[0].endpoint,
395
+ networkIndex: endpoints_1.FIXED_ENDPOINTS[0].networkIndex,
396
+ };
397
+ // set immediately to avoid potential race
398
+ this.multicastTable.push(multicastEntry.multicastId);
399
+ await new Promise((resolve, reject) => {
400
+ this.requestQueue.enqueue(async () => {
401
+ const status = (await this.ezsp.ezspSetMulticastTableEntry(tableIdx, multicastEntry));
402
+ if (status !== enums_3.EmberStatus.SUCCESS) {
403
+ logger_1.logger.error(`Failed to register group "${multicastEntry.multicastId}" in multicast table with status=${enums_3.EmberStatus[status]}.`, NS);
404
+ return status;
405
+ }
406
+ logger_1.logger.debug(`Registered multicast table entry (${tableIdx}): ${JSON.stringify(multicastEntry)}.`, NS);
407
+ resolve();
408
+ return enums_3.EmberStatus.SUCCESS;
409
+ }, (reason) => {
410
+ // remove to allow retry on next occurrence
411
+ this.multicastTable.splice(tableIdx, 1);
412
+ reject(reason);
413
+ }, true);
414
+ });
378
415
  }
379
416
  }
417
+ // shouldn't be any other status
380
418
  }
381
419
  /**
382
420
  * Emitted from @see Ezsp.ezspIncomingMessageHandler
@@ -420,7 +458,7 @@ class EmberAdapter extends __1.Adapter {
420
458
  endpoint: apsFrame.sourceEndpoint,
421
459
  linkquality: lastHopLqi,
422
460
  groupID: apsFrame.groupId,
423
- wasBroadcast: ((type === enums_2.EmberIncomingMessageType.BROADCAST) || (type === enums_2.EmberIncomingMessageType.BROADCAST_LOOPBACK)),
461
+ wasBroadcast: ((type === enums_3.EmberIncomingMessageType.BROADCAST) || (type === enums_3.EmberIncomingMessageType.BROADCAST_LOOPBACK)),
424
462
  destinationEndpoint: apsFrame.destinationEndpoint,
425
463
  };
426
464
  this.oneWaitress.resolveZCL(payload);
@@ -480,11 +518,11 @@ class EmberAdapter extends __1.Adapter {
480
518
  data,
481
519
  clusterID: Zcl.Clusters.greenPower.ID,
482
520
  address: sourceId,
483
- endpoint: consts_2.GP_ENDPOINT,
521
+ endpoint: ZSpec.GP_ENDPOINT,
484
522
  linkquality: gpdLink,
485
523
  groupID: this.greenPowerGroup,
486
524
  wasBroadcast: true,
487
- destinationEndpoint: consts_2.GP_ENDPOINT,
525
+ destinationEndpoint: ZSpec.GP_ENDPOINT,
488
526
  };
489
527
  this.oneWaitress.resolveZCL(payload);
490
528
  this.emit(events_1.Events.zclPayload, payload);
@@ -505,7 +543,7 @@ class EmberAdapter extends __1.Adapter {
505
543
  * @param parentOfNewNodeId
506
544
  */
507
545
  async onTrustCenterJoin(newNodeId, newNodeEui64, status, policyDecision, parentOfNewNodeId) {
508
- if (status === enums_2.EmberDeviceUpdate.DEVICE_LEFT) {
546
+ if (status === enums_3.EmberDeviceUpdate.DEVICE_LEFT) {
509
547
  const payload = {
510
548
  networkAddress: newNodeId,
511
549
  ieeeAddr: newNodeEui64,
@@ -513,7 +551,7 @@ class EmberAdapter extends __1.Adapter {
513
551
  this.emit(events_1.Events.deviceLeave, payload);
514
552
  }
515
553
  else {
516
- if (policyDecision !== enums_2.EmberJoinDecision.DENY_JOIN) {
554
+ if (policyDecision !== enums_3.EmberJoinDecision.DENY_JOIN) {
517
555
  const payload = {
518
556
  networkAddress: newNodeId,
519
557
  ieeeAddr: newNodeEui64,
@@ -528,7 +566,7 @@ class EmberAdapter extends __1.Adapter {
528
566
  this.manufacturerCode = joinManufCode;
529
567
  this.emit(events_1.Events.deviceJoined, payload);
530
568
  resolve();
531
- return enums_2.EmberStatus.SUCCESS;
569
+ return enums_3.EmberStatus.SUCCESS;
532
570
  }, reject, true);
533
571
  });
534
572
  }
@@ -550,7 +588,7 @@ class EmberAdapter extends __1.Adapter {
550
588
  const ashCounters = this.ezsp.ash.readAndClearCounters();
551
589
  logger_1.logger.info(`[ASH COUNTERS] ${ashCounters.join(',')}`, NS);
552
590
  resolve();
553
- return enums_2.EmberStatus.SUCCESS;
591
+ return enums_3.EmberStatus.SUCCESS;
554
592
  }, reject);
555
593
  });
556
594
  }
@@ -563,6 +601,7 @@ class EmberAdapter extends __1.Adapter {
563
601
  this.interpanLock = false;
564
602
  this.networkCache = (0, initters_1.initNetworkCache)();
565
603
  this.manufacturerCode = DEFAULT_MANUFACTURER_CODE; // will be set in NCP in initEzsp
604
+ this.multicastTable = [];
566
605
  this.ezsp.once(ezsp_1.EzspEvents.NCP_NEEDS_RESET_AND_INIT, this.onNcpNeedsResetAndInit.bind(this));
567
606
  }
568
607
  /**
@@ -573,8 +612,8 @@ class EmberAdapter extends __1.Adapter {
573
612
  let result = "resumed";
574
613
  // NOTE: something deep in this call can throw too
575
614
  const startResult = (await this.ezsp.start());
576
- if (startResult !== enums_2.EzspStatus.SUCCESS) {
577
- throw new Error(`Failed to start EZSP layer with status=${enums_2.EzspStatus[startResult]}.`);
615
+ if (startResult !== enums_3.EzspStatus.SUCCESS) {
616
+ throw new Error(`Failed to start EZSP layer with status=${enums_3.EzspStatus[startResult]}.`);
578
617
  }
579
618
  // call before any other command, else fails
580
619
  await this.emberVersion();
@@ -590,8 +629,8 @@ class EmberAdapter extends __1.Adapter {
590
629
  // await (this.emberStartEnergyScan());// TODO: via config of some kind, better off waiting for UI supports though
591
630
  // populate network cache info
592
631
  const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
593
- if (status !== enums_2.EmberStatus.SUCCESS) {
594
- throw new Error(`Failed to get network parameters with status=${enums_2.EmberStatus[status]}.`);
632
+ if (status !== enums_3.EmberStatus.SUCCESS) {
633
+ throw new Error(`Failed to get network parameters with status=${enums_3.EmberStatus[status]}.`);
595
634
  }
596
635
  this.networkCache.parameters = parameters;
597
636
  this.networkCache.status = (await this.ezsp.ezspNetworkState());
@@ -607,28 +646,28 @@ class EmberAdapter extends __1.Adapter {
607
646
  */
608
647
  async initNCPPreConfiguration() {
609
648
  // this can only decrease, not increase, NCP-side value
610
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.ADDRESS_TABLE_SIZE, this.stackConfig.ADDRESS_TABLE_SIZE);
611
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.TRUST_CENTER_ADDRESS_CACHE_SIZE, this.stackConfig.TRUST_CENTER_ADDRESS_CACHE_SIZE);
649
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.ADDRESS_TABLE_SIZE, this.stackConfig.ADDRESS_TABLE_SIZE);
650
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.TRUST_CENTER_ADDRESS_CACHE_SIZE, this.stackConfig.TRUST_CENTER_ADDRESS_CACHE_SIZE);
612
651
  // BUG 14222: If stack profile is 2 (ZigBee Pro), we need to enforce
613
652
  // the standard stack configuration values for that feature set.
614
653
  /** MAC indirect timeout should be 7.68 secs */
615
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.INDIRECT_TRANSMISSION_TIMEOUT, 7680);
654
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.INDIRECT_TRANSMISSION_TIMEOUT, 7680);
616
655
  /** Max hops should be 2 * nwkMaxDepth, where nwkMaxDepth is 15 */
617
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.MAX_HOPS, 30);
618
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.TX_POWER_MODE, enums_2.EmberTXPowerMode.USE_TOKEN);
619
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.SUPPORTED_NETWORKS, 1);
620
- await this.emberSetEzspValue(enums_1.EzspValueId.END_DEVICE_KEEP_ALIVE_SUPPORT_MODE, 1, [enums_2.EmberKeepAliveMode.KEEP_ALIVE_SUPPORT_ALL]);
656
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.MAX_HOPS, 30);
657
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.TX_POWER_MODE, enums_3.EmberTXPowerMode.USE_TOKEN);
658
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.SUPPORTED_NETWORKS, 1);
659
+ await this.emberSetEzspValue(enums_2.EzspValueId.END_DEVICE_KEEP_ALIVE_SUPPORT_MODE, 1, [enums_3.EmberKeepAliveMode.KEEP_ALIVE_SUPPORT_ALL]);
621
660
  // allow other devices to modify the binding table
622
- await this.emberSetEzspPolicy(enums_1.EzspPolicyId.BINDING_MODIFICATION_POLICY, enums_1.EzspDecisionId.CHECK_BINDING_MODIFICATIONS_ARE_VALID_ENDPOINT_CLUSTERS);
661
+ await this.emberSetEzspPolicy(enums_2.EzspPolicyId.BINDING_MODIFICATION_POLICY, enums_2.EzspDecisionId.CHECK_BINDING_MODIFICATIONS_ARE_VALID_ENDPOINT_CLUSTERS);
623
662
  // return message tag and message contents in ezspMessageSentHandler()
624
- await this.emberSetEzspPolicy(enums_1.EzspPolicyId.MESSAGE_CONTENTS_IN_CALLBACK_POLICY, enums_1.EzspDecisionId.MESSAGE_TAG_AND_CONTENTS_IN_CALLBACK);
625
- await this.emberSetEzspValue(enums_1.EzspValueId.MAXIMUM_INCOMING_TRANSFER_SIZE, 2, (0, math_1.lowHighBytes)(consts_2.MAXIMUM_APS_PAYLOAD_LENGTH));
626
- await this.emberSetEzspValue(enums_1.EzspValueId.MAXIMUM_OUTGOING_TRANSFER_SIZE, 2, (0, math_1.lowHighBytes)(consts_2.MAXIMUM_APS_PAYLOAD_LENGTH));
627
- await this.emberSetEzspValue(enums_1.EzspValueId.TRANSIENT_DEVICE_TIMEOUT, 2, (0, math_1.lowHighBytes)(this.stackConfig.TRANSIENT_DEVICE_TIMEOUT));
663
+ await this.emberSetEzspPolicy(enums_2.EzspPolicyId.MESSAGE_CONTENTS_IN_CALLBACK_POLICY, enums_2.EzspDecisionId.MESSAGE_TAG_AND_CONTENTS_IN_CALLBACK);
664
+ await this.emberSetEzspValue(enums_2.EzspValueId.MAXIMUM_INCOMING_TRANSFER_SIZE, 2, (0, math_1.lowHighBytes)(consts_2.MAXIMUM_APS_PAYLOAD_LENGTH));
665
+ await this.emberSetEzspValue(enums_2.EzspValueId.MAXIMUM_OUTGOING_TRANSFER_SIZE, 2, (0, math_1.lowHighBytes)(consts_2.MAXIMUM_APS_PAYLOAD_LENGTH));
666
+ await this.emberSetEzspValue(enums_2.EzspValueId.TRANSIENT_DEVICE_TIMEOUT, 2, (0, math_1.lowHighBytes)(this.stackConfig.TRANSIENT_DEVICE_TIMEOUT));
628
667
  await this.ezsp.ezspSetManufacturerCode(this.manufacturerCode);
629
668
  // network security init
630
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.STACK_PROFILE, consts_2.STACK_PROFILE_ZIGBEE_PRO);
631
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.SECURITY_LEVEL, consts_2.SECURITY_LEVEL_Z3);
669
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.STACK_PROFILE, consts_2.STACK_PROFILE_ZIGBEE_PRO);
670
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.SECURITY_LEVEL, consts_2.SECURITY_LEVEL_Z3);
632
671
  }
633
672
  /**
634
673
  * NCP Address table init.
@@ -637,29 +676,29 @@ class EmberAdapter extends __1.Adapter {
637
676
  async initNCPAddressTable() {
638
677
  const desiredTableSize = this.stackConfig.ADDRESS_TABLE_SIZE;
639
678
  // If the host and the ncp disagree on the address table size, explode.
640
- const [status, addressTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_1.EzspConfigId.ADDRESS_TABLE_SIZE));
679
+ const [status, addressTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_2.EzspConfigId.ADDRESS_TABLE_SIZE));
641
680
  // After the change of ncp memory model in UC, we can not increase the default NCP table sizes anymore.
642
681
  // Therefore, checking for desiredTableSize == (ncp)addressTableSize might not be always true anymore
643
682
  // assert(desiredTableSize <= addressTableSize);
644
- if ((status !== enums_2.EzspStatus.SUCCESS) || (addressTableSize > desiredTableSize)) {
645
- throw new Error(`[INIT] NCP (${addressTableSize}) disagrees with Host (min ${desiredTableSize}) on table size. status=${enums_2.EzspStatus[status]}`);
683
+ if ((status !== enums_3.EzspStatus.SUCCESS) || (addressTableSize > desiredTableSize)) {
684
+ throw new Error(`[INIT] NCP (${addressTableSize}) disagrees with Host (min ${desiredTableSize}) on table size. status=${enums_3.EzspStatus[status]}`);
646
685
  }
647
686
  }
648
687
  /**
649
688
  * NCP configuration init
650
689
  */
651
690
  async initNCPConfiguration() {
652
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.BINDING_TABLE_SIZE, this.stackConfig.BINDING_TABLE_SIZE);
653
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.KEY_TABLE_SIZE, this.stackConfig.KEY_TABLE_SIZE);
654
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.MAX_END_DEVICE_CHILDREN, this.stackConfig.MAX_END_DEVICE_CHILDREN);
655
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.APS_UNICAST_MESSAGE_COUNT, this.stackConfig.APS_UNICAST_MESSAGE_COUNT);
656
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.BROADCAST_TABLE_SIZE, this.stackConfig.BROADCAST_TABLE_SIZE);
657
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.NEIGHBOR_TABLE_SIZE, this.stackConfig.NEIGHBOR_TABLE_SIZE);
658
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.END_DEVICE_POLL_TIMEOUT, this.stackConfig.END_DEVICE_POLL_TIMEOUT);
659
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.TRANSIENT_KEY_TIMEOUT_S, this.stackConfig.TRANSIENT_KEY_TIMEOUT_S);
660
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.RETRY_QUEUE_SIZE, this.stackConfig.RETRY_QUEUE_SIZE);
661
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.SOURCE_ROUTE_TABLE_SIZE, this.stackConfig.SOURCE_ROUTE_TABLE_SIZE);
662
- await this.emberSetEzspConfigValue(enums_1.EzspConfigId.MULTICAST_TABLE_SIZE, this.stackConfig.MULTICAST_TABLE_SIZE);
691
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.BINDING_TABLE_SIZE, this.stackConfig.BINDING_TABLE_SIZE);
692
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.KEY_TABLE_SIZE, this.stackConfig.KEY_TABLE_SIZE);
693
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.MAX_END_DEVICE_CHILDREN, this.stackConfig.MAX_END_DEVICE_CHILDREN);
694
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.APS_UNICAST_MESSAGE_COUNT, this.stackConfig.APS_UNICAST_MESSAGE_COUNT);
695
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.BROADCAST_TABLE_SIZE, this.stackConfig.BROADCAST_TABLE_SIZE);
696
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.NEIGHBOR_TABLE_SIZE, this.stackConfig.NEIGHBOR_TABLE_SIZE);
697
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.END_DEVICE_POLL_TIMEOUT, this.stackConfig.END_DEVICE_POLL_TIMEOUT);
698
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.TRANSIENT_KEY_TIMEOUT_S, this.stackConfig.TRANSIENT_KEY_TIMEOUT_S);
699
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.RETRY_QUEUE_SIZE, this.stackConfig.RETRY_QUEUE_SIZE);
700
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.SOURCE_ROUTE_TABLE_SIZE, this.stackConfig.SOURCE_ROUTE_TABLE_SIZE);
701
+ await this.emberSetEzspConfigValue(enums_2.EzspConfigId.MULTICAST_TABLE_SIZE, this.stackConfig.MULTICAST_TABLE_SIZE);
663
702
  }
664
703
  /**
665
704
  * NCP concentrator init. Also enables source route discovery mode with RESCHEDULE.
@@ -677,17 +716,16 @@ class EmberAdapter extends __1.Adapter {
677
716
  */
678
717
  async initNCPConcentrator() {
679
718
  const status = (await this.ezsp.ezspSetConcentrator(true, (this.stackConfig.CONCENTRATOR_RAM_TYPE === 'low') ? consts_2.EMBER_LOW_RAM_CONCENTRATOR : consts_2.EMBER_HIGH_RAM_CONCENTRATOR, this.stackConfig.CONCENTRATOR_MIN_TIME, this.stackConfig.CONCENTRATOR_MAX_TIME, this.stackConfig.CONCENTRATOR_ROUTE_ERROR_THRESHOLD, this.stackConfig.CONCENTRATOR_DELIVERY_FAILURE_THRESHOLD, this.stackConfig.CONCENTRATOR_MAX_HOPS));
680
- if (status !== enums_2.EmberStatus.SUCCESS) {
719
+ if (status !== enums_3.EmberStatus.SUCCESS) {
681
720
  throw new Error(`[CONCENTRATOR] Failed to set concentrator with status=${status}.`);
682
721
  }
683
- const remainTilMTORR = (await this.ezsp.ezspSetSourceRouteDiscoveryMode(enums_2.EmberSourceRouteDiscoveryMode.RESCHEDULE));
722
+ const remainTilMTORR = (await this.ezsp.ezspSetSourceRouteDiscoveryMode(enums_3.EmberSourceRouteDiscoveryMode.RESCHEDULE));
684
723
  logger_1.logger.info(`[CONCENTRATOR] Started source route discovery. ${remainTilMTORR}ms until next broadcast.`, NS);
685
724
  }
686
725
  /**
687
726
  * Register fixed endpoints and set any related multicast entries that need to be.
688
727
  */
689
728
  async registerFixedEndpoints() {
690
- let mcTableIdx = 0;
691
729
  for (const ep of endpoints_1.FIXED_ENDPOINTS) {
692
730
  if (ep.networkIndex !== 0x00) {
693
731
  logger_1.logger.debug(`Multi-network not currently supported. Skipping endpoint ${JSON.stringify(ep)}.`, NS);
@@ -695,16 +733,16 @@ class EmberAdapter extends __1.Adapter {
695
733
  }
696
734
  const [epStatus,] = (await this.ezsp.ezspGetEndpointFlags(ep.endpoint));
697
735
  // endpoint not already registered
698
- if (epStatus !== enums_2.EzspStatus.SUCCESS) {
736
+ if (epStatus !== enums_3.EzspStatus.SUCCESS) {
699
737
  // check to see if ezspAddEndpoint needs to be called
700
738
  // if ezspInit is called without NCP reset, ezspAddEndpoint is not necessary and will return an error
701
739
  const status = (await this.ezsp.ezspAddEndpoint(ep.endpoint, ep.profileId, ep.deviceId, ep.deviceVersion, ep.inClusterList.slice(), // copy
702
740
  ep.outClusterList.slice()));
703
- if (status === enums_2.EzspStatus.SUCCESS) {
704
- logger_1.logger.debug(`Registered endpoint "${ep.endpoint}" with status=${enums_2.EzspStatus[status]}.`, NS);
741
+ if (status === enums_3.EzspStatus.SUCCESS) {
742
+ logger_1.logger.debug(`Registered endpoint "${ep.endpoint}" with status=${enums_3.EzspStatus[status]}.`, NS);
705
743
  }
706
744
  else {
707
- throw new Error(`Failed to register endpoint "${ep.endpoint}" with status=${enums_2.EzspStatus[status]}.`);
745
+ throw new Error(`Failed to register endpoint "${ep.endpoint}" with status=${enums_3.EzspStatus[status]}.`);
708
746
  }
709
747
  }
710
748
  else {
@@ -716,11 +754,12 @@ class EmberAdapter extends __1.Adapter {
716
754
  endpoint: ep.endpoint,
717
755
  networkIndex: ep.networkIndex,
718
756
  };
719
- const status = (await this.ezsp.ezspSetMulticastTableEntry(mcTableIdx++, multicastEntry));
720
- if (status !== enums_2.EmberStatus.SUCCESS) {
721
- throw new Error(`Failed to register group "${multicastId}" in multicast table with status=${enums_2.EmberStatus[status]}.`);
757
+ const status = (await this.ezsp.ezspSetMulticastTableEntry(this.multicastTable.length, multicastEntry));
758
+ if (status !== enums_3.EmberStatus.SUCCESS) {
759
+ throw new Error(`Failed to register group "${multicastId}" in multicast table with status=${enums_3.EmberStatus[status]}.`);
722
760
  }
723
- logger_1.logger.debug(`Registered multicast table entry: ${JSON.stringify(multicastEntry)}.`, NS);
761
+ logger_1.logger.debug(`Registered multicast table entry (${this.multicastTable.length}): ${JSON.stringify(multicastEntry)}.`, NS);
762
+ this.multicastTable.push(multicastEntry.multicastId);
724
763
  }
725
764
  }
726
765
  }
@@ -731,47 +770,47 @@ class EmberAdapter extends __1.Adapter {
731
770
  async initTrustCenter() {
732
771
  // init TC policies
733
772
  {
734
- let status = (await this.emberSetEzspPolicy(enums_1.EzspPolicyId.TC_KEY_REQUEST_POLICY, enums_1.EzspDecisionId.ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY));
735
- if (status !== enums_2.EzspStatus.SUCCESS) {
773
+ let status = (await this.emberSetEzspPolicy(enums_2.EzspPolicyId.TC_KEY_REQUEST_POLICY, enums_2.EzspDecisionId.ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY));
774
+ if (status !== enums_3.EzspStatus.SUCCESS) {
736
775
  throw new Error(`[INIT TC] Failed to set EzspPolicyId TC_KEY_REQUEST_POLICY to ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY `
737
- + `with status=${enums_2.EzspStatus[status]}.`);
776
+ + `with status=${enums_3.EzspStatus[status]}.`);
738
777
  }
739
- const appKeyPolicy = this.stackConfig.KEY_TABLE_SIZE ? enums_1.EzspDecisionId.ALLOW_APP_KEY_REQUESTS : enums_1.EzspDecisionId.DENY_APP_KEY_REQUESTS;
740
- status = (await this.emberSetEzspPolicy(enums_1.EzspPolicyId.APP_KEY_REQUEST_POLICY, appKeyPolicy));
741
- if (status !== enums_2.EzspStatus.SUCCESS) {
742
- throw new Error(`[INIT TC] Failed to set EzspPolicyId APP_KEY_REQUEST_POLICY to ${enums_1.EzspDecisionId[appKeyPolicy]} `
743
- + `with status=${enums_2.EzspStatus[status]}.`);
778
+ const appKeyPolicy = this.stackConfig.KEY_TABLE_SIZE ? enums_2.EzspDecisionId.ALLOW_APP_KEY_REQUESTS : enums_2.EzspDecisionId.DENY_APP_KEY_REQUESTS;
779
+ status = (await this.emberSetEzspPolicy(enums_2.EzspPolicyId.APP_KEY_REQUEST_POLICY, appKeyPolicy));
780
+ if (status !== enums_3.EzspStatus.SUCCESS) {
781
+ throw new Error(`[INIT TC] Failed to set EzspPolicyId APP_KEY_REQUEST_POLICY to ${enums_2.EzspDecisionId[appKeyPolicy]} `
782
+ + `with status=${enums_3.EzspStatus[status]}.`);
744
783
  }
745
- status = (await this.emberSetJoinPolicy(enums_2.EmberJoinDecision.USE_PRECONFIGURED_KEY));
746
- if (status !== enums_2.EzspStatus.SUCCESS) {
747
- throw new Error(`[INIT TC] Failed to set join policy to USE_PRECONFIGURED_KEY with status=${enums_2.EzspStatus[status]}.`);
784
+ status = (await this.emberSetJoinPolicy(enums_3.EmberJoinDecision.USE_PRECONFIGURED_KEY));
785
+ if (status !== enums_3.EzspStatus.SUCCESS) {
786
+ throw new Error(`[INIT TC] Failed to set join policy to USE_PRECONFIGURED_KEY with status=${enums_3.EzspStatus[status]}.`);
748
787
  }
749
788
  }
750
789
  const configNetworkKey = Buffer.from(this.networkOptions.networkKey);
751
790
  const networkInitStruct = {
752
- bitmask: (enums_2.EmberNetworkInitBitmask.PARENT_INFO_IN_TOKEN | enums_2.EmberNetworkInitBitmask.END_DEVICE_REJOIN_ON_REBOOT)
791
+ bitmask: (enums_3.EmberNetworkInitBitmask.PARENT_INFO_IN_TOKEN | enums_3.EmberNetworkInitBitmask.END_DEVICE_REJOIN_ON_REBOOT)
753
792
  };
754
793
  const initStatus = (await this.ezsp.ezspNetworkInit(networkInitStruct));
755
- logger_1.logger.debug(`[INIT TC] Network init status=${enums_2.EmberStatus[initStatus]}.`, NS);
756
- if ((initStatus !== enums_2.EmberStatus.SUCCESS) && (initStatus !== enums_2.EmberStatus.NOT_JOINED)) {
757
- throw new Error(`[INIT TC] Failed network init request with status=${enums_2.EmberStatus[initStatus]}.`);
794
+ logger_1.logger.debug(`[INIT TC] Network init status=${enums_3.EmberStatus[initStatus]}.`, NS);
795
+ if ((initStatus !== enums_3.EmberStatus.SUCCESS) && (initStatus !== enums_3.EmberStatus.NOT_JOINED)) {
796
+ throw new Error(`[INIT TC] Failed network init request with status=${enums_3.EmberStatus[initStatus]}.`);
758
797
  }
759
798
  let action = NetworkInitAction.DONE;
760
- if (initStatus === enums_2.EmberStatus.SUCCESS) {
799
+ if (initStatus === enums_3.EmberStatus.SUCCESS) {
761
800
  // network
762
801
  await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_UP }, DEFAULT_NETWORK_REQUEST_TIMEOUT, '[INIT TC] Network init');
763
802
  const [npStatus, nodeType, netParams] = (await this.ezsp.ezspGetNetworkParameters());
764
803
  logger_1.logger.debug(`[INIT TC] Current network config=${JSON.stringify(this.networkOptions)}`, NS);
765
- logger_1.logger.debug(`[INIT TC] Current NCP network: nodeType=${enums_2.EmberNodeType[nodeType]} params=${JSON.stringify(netParams)}`, NS);
766
- if ((npStatus === enums_2.EmberStatus.SUCCESS) && (nodeType === enums_2.EmberNodeType.COORDINATOR) && (this.networkOptions.panID === netParams.panId)
804
+ logger_1.logger.debug(`[INIT TC] Current NCP network: nodeType=${enums_3.EmberNodeType[nodeType]} params=${JSON.stringify(netParams)}`, NS);
805
+ if ((npStatus === enums_3.EmberStatus.SUCCESS) && (nodeType === enums_3.EmberNodeType.COORDINATOR) && (this.networkOptions.panID === netParams.panId)
767
806
  && ((0, es6_1.default)(this.networkOptions.extendedPanID, netParams.extendedPanId))) {
768
807
  // config matches adapter so far, no error, we can check the network key
769
808
  const context = (0, initters_1.initSecurityManagerContext)();
770
- context.coreKeyType = enums_2.SecManKeyType.NETWORK;
809
+ context.coreKeyType = enums_3.SecManKeyType.NETWORK;
771
810
  context.keyIndex = 0;
772
811
  const [networkKey, nkStatus] = (await this.ezsp.ezspExportKey(context));
773
- if (nkStatus !== enums_2.SLStatus.OK) {
774
- throw new Error(`[BACKUP] Failed to export Network Key with status=${enums_2.SLStatus[nkStatus]}.`);
812
+ if (nkStatus !== enums_3.SLStatus.OK) {
813
+ throw new Error(`[BACKUP] Failed to export Network Key with status=${enums_3.SLStatus[nkStatus]}.`);
775
814
  }
776
815
  logger_1.logger.debug(`[INIT TC] Current NCP network: networkKey=${networkKey.contents.toString('hex')}`, NS);
777
816
  // config doesn't match adapter anymore
@@ -786,8 +825,8 @@ class EmberAdapter extends __1.Adapter {
786
825
  if (action === NetworkInitAction.LEAVE) {
787
826
  logger_1.logger.info(`[INIT TC] NCP network does not match config. Leaving network...`, NS);
788
827
  const leaveStatus = (await this.ezsp.ezspLeaveNetwork());
789
- if (leaveStatus !== enums_2.EmberStatus.SUCCESS) {
790
- throw new Error(`[INIT TC] Failed leave network request with status=${enums_2.EmberStatus[leaveStatus]}.`);
828
+ if (leaveStatus !== enums_3.EmberStatus.SUCCESS) {
829
+ throw new Error(`[INIT TC] Failed leave network request with status=${enums_3.EmberStatus[leaveStatus]}.`);
791
830
  }
792
831
  await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_DOWN }, DEFAULT_NETWORK_REQUEST_TIMEOUT, '[INIT TC] Leave network');
793
832
  await (0, utils_1.Wait)(200); // settle down
@@ -795,7 +834,7 @@ class EmberAdapter extends __1.Adapter {
795
834
  }
796
835
  }
797
836
  const backup = this.getStoredBackup();
798
- if ((initStatus === enums_2.EmberStatus.NOT_JOINED) || (action === NetworkInitAction.LEFT)) {
837
+ if ((initStatus === enums_3.EmberStatus.NOT_JOINED) || (action === NetworkInitAction.LEFT)) {
799
838
  // no network
800
839
  if (backup != null) {
801
840
  if ((this.networkOptions.panID === backup.networkOptions.panId)
@@ -877,30 +916,30 @@ class EmberAdapter extends __1.Adapter {
877
916
  */
878
917
  async formNetwork(fromBackup, networkKey, networkKeySequenceNumber, panId, extendedPanId, radioChannel, tcLinkKey) {
879
918
  const state = {
880
- bitmask: (enums_2.EmberInitialSecurityBitmask.TRUST_CENTER_GLOBAL_LINK_KEY | enums_2.EmberInitialSecurityBitmask.HAVE_PRECONFIGURED_KEY
881
- | enums_2.EmberInitialSecurityBitmask.HAVE_NETWORK_KEY | enums_2.EmberInitialSecurityBitmask.TRUST_CENTER_USES_HASHED_LINK_KEY
882
- | enums_2.EmberInitialSecurityBitmask.REQUIRE_ENCRYPTED_KEY),
919
+ bitmask: (enums_3.EmberInitialSecurityBitmask.TRUST_CENTER_GLOBAL_LINK_KEY | enums_3.EmberInitialSecurityBitmask.HAVE_PRECONFIGURED_KEY
920
+ | enums_3.EmberInitialSecurityBitmask.HAVE_NETWORK_KEY | enums_3.EmberInitialSecurityBitmask.TRUST_CENTER_USES_HASHED_LINK_KEY
921
+ | enums_3.EmberInitialSecurityBitmask.REQUIRE_ENCRYPTED_KEY),
883
922
  preconfiguredKey: { contents: tcLinkKey },
884
923
  networkKey: { contents: networkKey },
885
924
  networkKeySequenceNumber: networkKeySequenceNumber,
886
- preconfiguredTrustCenterEui64: consts_2.BLANK_EUI64,
925
+ preconfiguredTrustCenterEui64: ZSpec.BLANK_EUI64,
887
926
  };
888
927
  if (fromBackup) {
889
- state.bitmask |= enums_2.EmberInitialSecurityBitmask.NO_FRAME_COUNTER_RESET;
928
+ state.bitmask |= enums_3.EmberInitialSecurityBitmask.NO_FRAME_COUNTER_RESET;
890
929
  }
891
930
  let emberStatus = (await this.ezsp.ezspSetInitialSecurityState(state));
892
- if (emberStatus !== enums_2.EmberStatus.SUCCESS) {
893
- throw new Error(`[INIT FORM] Failed to set initial security state with status=${enums_2.EmberStatus[emberStatus]}.`);
931
+ if (emberStatus !== enums_3.EmberStatus.SUCCESS) {
932
+ throw new Error(`[INIT FORM] Failed to set initial security state with status=${enums_3.EmberStatus[emberStatus]}.`);
894
933
  }
895
- const extended = (enums_2.EmberExtendedSecurityBitmask.JOINER_GLOBAL_LINK_KEY | enums_2.EmberExtendedSecurityBitmask.NWK_LEAVE_REQUEST_NOT_ALLOWED);
934
+ const extended = (enums_3.EmberExtendedSecurityBitmask.JOINER_GLOBAL_LINK_KEY | enums_3.EmberExtendedSecurityBitmask.NWK_LEAVE_REQUEST_NOT_ALLOWED);
896
935
  const extSecStatus = (await this.ezsp.ezspSetExtendedSecurityBitmask(extended));
897
- if (extSecStatus !== enums_2.EzspStatus.SUCCESS) {
898
- throw new Error(`[INIT FORM] Failed to set extended security bitmask to ${extended} with status=${enums_2.EzspStatus[extSecStatus]}.`);
936
+ if (extSecStatus !== enums_3.EzspStatus.SUCCESS) {
937
+ throw new Error(`[INIT FORM] Failed to set extended security bitmask to ${extended} with status=${enums_3.EzspStatus[extSecStatus]}.`);
899
938
  }
900
939
  if (!fromBackup && this.stackConfig.KEY_TABLE_SIZE > 0) {
901
940
  emberStatus = await this.ezsp.ezspClearKeyTable();
902
- if (emberStatus !== enums_2.EmberStatus.SUCCESS) {
903
- throw new Error(`[INIT FORM] Failed to clear key table with status=${enums_2.EmberStatus[emberStatus]}.`);
941
+ if (emberStatus !== enums_3.EmberStatus.SUCCESS) {
942
+ throw new Error(`[INIT FORM] Failed to clear key table with status=${enums_3.EmberStatus[emberStatus]}.`);
904
943
  }
905
944
  }
906
945
  const netParams = {
@@ -908,19 +947,19 @@ class EmberAdapter extends __1.Adapter {
908
947
  extendedPanId,
909
948
  radioTxPower: 5,
910
949
  radioChannel,
911
- joinMethod: enums_2.EmberJoinMethod.MAC_ASSOCIATION,
912
- nwkManagerId: consts_2.ZIGBEE_COORDINATOR_ADDRESS,
950
+ joinMethod: enums_3.EmberJoinMethod.MAC_ASSOCIATION,
951
+ nwkManagerId: ZSpec.COORDINATOR_ADDRESS,
913
952
  nwkUpdateId: 0,
914
953
  channels: consts_2.EMBER_ALL_802_15_4_CHANNELS_MASK,
915
954
  };
916
955
  logger_1.logger.info(`[INIT FORM] Forming new network with: ${JSON.stringify(netParams)}`, NS);
917
956
  emberStatus = (await this.ezsp.ezspFormNetwork(netParams));
918
- if (emberStatus !== enums_2.EmberStatus.SUCCESS) {
919
- throw new Error(`[INIT FORM] Failed form network request with status=${enums_2.EmberStatus[emberStatus]}.`);
957
+ if (emberStatus !== enums_3.EmberStatus.SUCCESS) {
958
+ throw new Error(`[INIT FORM] Failed form network request with status=${enums_3.EmberStatus[emberStatus]}.`);
920
959
  }
921
960
  await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_UP }, DEFAULT_NETWORK_REQUEST_TIMEOUT, '[INIT FORM] Form network');
922
961
  const stStatus = await this.ezsp.ezspStartWritingStackTokens();
923
- logger_1.logger.debug(`[INIT FORM] Start writing stack tokens status=${enums_2.EzspStatus[stStatus]}.`, NS);
962
+ logger_1.logger.debug(`[INIT FORM] Start writing stack tokens status=${enums_3.EzspStatus[stStatus]}.`, NS);
924
963
  logger_1.logger.info(`[INIT FORM] New network formed!`, NS);
925
964
  }
926
965
  /**
@@ -945,7 +984,9 @@ class EmberAdapter extends __1.Adapter {
945
984
  throw new Error(`[BACKUP] Current backup file is not for EmberZNet stack.`);
946
985
  }
947
986
  if (data.metadata.internal.ezspVersion < BACKUP_OLDEST_SUPPORTED_EZSP_VERSION) {
948
- throw new Error(`[BACKUP] Current backup file is from an unsupported EZSP version (min: ${BACKUP_OLDEST_SUPPORTED_EZSP_VERSION}).`);
987
+ (0, fs_1.renameSync)(this.backupPath, `${this.backupPath}.old`);
988
+ logger_1.logger.warning(`[BACKUP] Current backup file is from an unsupported EZSP version. Renaming and ignoring.`, NS);
989
+ return null;
949
990
  }
950
991
  return utils_1.BackupUtils.fromUnifiedBackup(data);
951
992
  }
@@ -959,9 +1000,9 @@ class EmberAdapter extends __1.Adapter {
959
1000
  * @return List of keys data with AES hashed keys
960
1001
  */
961
1002
  async exportLinkKeys() {
962
- const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_1.EzspConfigId.KEY_TABLE_SIZE));
963
- if (confStatus !== enums_2.EzspStatus.SUCCESS) {
964
- throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${enums_2.EzspStatus[confStatus]}.`);
1003
+ const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_2.EzspConfigId.KEY_TABLE_SIZE));
1004
+ if (confStatus !== enums_3.EzspStatus.SUCCESS) {
1005
+ throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${enums_3.EzspStatus[confStatus]}.`);
965
1006
  }
966
1007
  let deviceEui64;
967
1008
  let plaintextKey;
@@ -970,14 +1011,14 @@ class EmberAdapter extends __1.Adapter {
970
1011
  const keyList = [];
971
1012
  for (let i = 0; i < keyTableSize; i++) {
972
1013
  [deviceEui64, plaintextKey, apsKeyMeta, status] = (await this.ezsp.ezspExportLinkKeyByIndex(i));
973
- logger_1.logger.debug(`[BACKUP] Export link key at index ${i}, status=${enums_2.SLStatus[status]}.`, NS);
1014
+ logger_1.logger.debug(`[BACKUP] Export link key at index ${i}, status=${enums_3.SLStatus[status]}.`, NS);
974
1015
  // only include key if we could retrieve one at index and hash it properly
975
- if (status === enums_2.SLStatus.OK) {
1016
+ if (status === enums_3.SLStatus.OK) {
976
1017
  // Rather than give the real link key, the backup contains a hashed version of the key.
977
1018
  // This is done to prevent a compromise of the backup data from compromising the current link keys.
978
1019
  // This is per the Smart Energy spec.
979
1020
  const [hashStatus, hashedKey] = (await this.emberAesHashSimple(plaintextKey.contents));
980
- if (hashStatus === enums_2.EmberStatus.SUCCESS) {
1021
+ if (hashStatus === enums_3.EmberStatus.SUCCESS) {
981
1022
  keyList.push({
982
1023
  deviceEui64,
983
1024
  key: { contents: hashedKey },
@@ -987,7 +1028,7 @@ class EmberAdapter extends __1.Adapter {
987
1028
  }
988
1029
  else {
989
1030
  // this should never happen?
990
- logger_1.logger.error(`[BACKUP] Failed to hash link key at index ${i} with status=${enums_2.EmberStatus[hashStatus]}. Omitting from backup.`, NS);
1031
+ logger_1.logger.error(`[BACKUP] Failed to hash link key at index ${i} with status=${enums_3.EmberStatus[hashStatus]}. Omitting from backup.`, NS);
991
1032
  }
992
1033
  }
993
1034
  }
@@ -1003,16 +1044,16 @@ class EmberAdapter extends __1.Adapter {
1003
1044
  if (!backupData?.length) {
1004
1045
  return;
1005
1046
  }
1006
- const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_1.EzspConfigId.KEY_TABLE_SIZE));
1007
- if (confStatus !== enums_2.EzspStatus.SUCCESS) {
1008
- throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${enums_2.EzspStatus[confStatus]}.`);
1047
+ const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_2.EzspConfigId.KEY_TABLE_SIZE));
1048
+ if (confStatus !== enums_3.EzspStatus.SUCCESS) {
1049
+ throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${enums_3.EzspStatus[confStatus]}.`);
1009
1050
  }
1010
1051
  if (backupData.length > keyTableSize) {
1011
1052
  throw new Error(`[BACKUP] Current key table of ${keyTableSize} is too small to import backup of ${backupData.length}!`);
1012
1053
  }
1013
1054
  const networkStatus = (await this.emberNetworkState());
1014
- if (networkStatus !== enums_2.EmberNetworkStatus.NO_NETWORK) {
1015
- throw new Error(`[BACKUP] Cannot import TC data while network is up, networkStatus=${enums_2.EmberNetworkStatus[networkStatus]}.`);
1055
+ if (networkStatus !== enums_3.EmberNetworkStatus.NO_NETWORK) {
1056
+ throw new Error(`[BACKUP] Cannot import TC data while network is up, networkStatus=${enums_3.EmberNetworkStatus[networkStatus]}.`);
1016
1057
  }
1017
1058
  let status;
1018
1059
  for (let i = 0; i < keyTableSize; i++) {
@@ -1022,11 +1063,11 @@ class EmberAdapter extends __1.Adapter {
1022
1063
  }
1023
1064
  else {
1024
1065
  const importStatus = (await this.ezsp.ezspImportLinkKey(i, backupData[i].deviceEui64, backupData[i].key));
1025
- status = ((importStatus === enums_2.SLStatus.OK) ? enums_2.EmberStatus.SUCCESS : enums_2.EmberStatus.KEY_TABLE_INVALID_ADDRESS);
1066
+ status = ((importStatus === enums_3.SLStatus.OK) ? enums_3.EmberStatus.SUCCESS : enums_3.EmberStatus.KEY_TABLE_INVALID_ADDRESS);
1026
1067
  }
1027
- if (status !== enums_2.EmberStatus.SUCCESS) {
1068
+ if (status !== enums_3.EmberStatus.SUCCESS) {
1028
1069
  throw new Error(`[BACKUP] Failed to ${((i >= backupData.length) ? "erase" : "set")} key table entry at index ${i} `
1029
- + `with status=${enums_2.EmberStatus[status]}`);
1070
+ + `with status=${enums_3.EmberStatus[status]}`);
1030
1071
  }
1031
1072
  }
1032
1073
  logger_1.logger.info(`[BACKUP] Imported ${backupData.length} keys.`, NS);
@@ -1043,17 +1084,17 @@ class EmberAdapter extends __1.Adapter {
1043
1084
  logger_1.logger.warning(`[TRUST CENTER] Performing a network key update. This might take a while and disrupt normal operation.`, NS);
1044
1085
  // zero-filled = let stack generate new random network key
1045
1086
  let status = await this.ezsp.ezspBroadcastNextNetworkKey({ contents: Buffer.alloc(consts_1.EMBER_ENCRYPTION_KEY_SIZE) });
1046
- if (status !== enums_2.EmberStatus.SUCCESS) {
1047
- logger_1.logger.error(`[TRUST CENTER] Failed to broadcast next network key with status=${enums_2.EmberStatus[status]}.`, NS);
1087
+ if (status !== enums_3.EmberStatus.SUCCESS) {
1088
+ logger_1.logger.error(`[TRUST CENTER] Failed to broadcast next network key with status=${enums_3.EmberStatus[status]}.`, NS);
1048
1089
  return status;
1049
1090
  }
1050
1091
  // XXX: this will block other requests for a while, but should ensure the key propagates without interference?
1051
1092
  // could also stop dispatching entirely and do this outside the queue if necessary/better
1052
1093
  await (0, utils_1.Wait)(BROADCAST_NETWORK_KEY_SWITCH_WAIT_TIME);
1053
1094
  status = (await this.ezsp.ezspBroadcastNetworkKeySwitch());
1054
- if (status !== enums_2.EmberStatus.SUCCESS) {
1095
+ if (status !== enums_3.EmberStatus.SUCCESS) {
1055
1096
  // XXX: Not sure how likely this is, but this is bad, probably should hard fail?
1056
- logger_1.logger.error(`[TRUST CENTER] Failed to broadcast network key switch with status=${enums_2.EmberStatus[status]}.`, NS);
1097
+ logger_1.logger.error(`[TRUST CENTER] Failed to broadcast network key switch with status=${enums_3.EmberStatus[status]}.`, NS);
1057
1098
  return status;
1058
1099
  }
1059
1100
  resolve();
@@ -1066,7 +1107,7 @@ class EmberAdapter extends __1.Adapter {
1066
1107
  * @param status
1067
1108
  */
1068
1109
  async onNcpNeedsResetAndInit(status) {
1069
- logger_1.logger.error(`!!! NCP FATAL ERROR reason=${enums_2.EzspStatus[status]}. ATTEMPTING RESET... !!!`, NS);
1110
+ logger_1.logger.error(`!!! NCP FATAL ERROR reason=${enums_3.EzspStatus[status]}. ATTEMPTING RESET... !!!`, NS);
1070
1111
  try {
1071
1112
  await this.stop();
1072
1113
  await (0, utils_1.Wait)(500); // just because
@@ -1104,7 +1145,7 @@ class EmberAdapter extends __1.Adapter {
1104
1145
  * Check against BLANK_EUI64 for validity.
1105
1146
  */
1106
1147
  async emberGetEui64() {
1107
- if (this.networkCache.eui64 === consts_2.BLANK_EUI64) {
1148
+ if (this.networkCache.eui64 === ZSpec.BLANK_EUI64) {
1108
1149
  this.networkCache.eui64 = (await this.ezsp.ezspGetEui64());
1109
1150
  }
1110
1151
  return this.networkCache.eui64;
@@ -1115,13 +1156,13 @@ class EmberAdapter extends __1.Adapter {
1115
1156
  * Check against INVALID_PAN_ID for validity.
1116
1157
  */
1117
1158
  async emberGetPanId() {
1118
- if (this.networkCache.parameters.panId === consts_2.INVALID_PAN_ID) {
1159
+ if (this.networkCache.parameters.panId === ZSpec.INVALID_PAN_ID) {
1119
1160
  const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
1120
- if (status === enums_2.EmberStatus.SUCCESS) {
1161
+ if (status === enums_3.EmberStatus.SUCCESS) {
1121
1162
  this.networkCache.parameters = parameters;
1122
1163
  }
1123
1164
  else {
1124
- logger_1.logger.error(`Failed to get PAN ID (via network parameters) with status=${enums_2.EmberStatus[status]}.`, NS);
1165
+ logger_1.logger.error(`Failed to get PAN ID (via network parameters) with status=${enums_3.EmberStatus[status]}.`, NS);
1125
1166
  }
1126
1167
  }
1127
1168
  return this.networkCache.parameters.panId;
@@ -1132,13 +1173,13 @@ class EmberAdapter extends __1.Adapter {
1132
1173
  * Check against BLANK_EXTENDED_PAN_ID for validity.
1133
1174
  */
1134
1175
  async emberGetExtendedPanId() {
1135
- if ((0, es6_1.default)(this.networkCache.parameters.extendedPanId, consts_2.BLANK_EXTENDED_PAN_ID)) {
1176
+ if ((0, es6_1.default)(this.networkCache.parameters.extendedPanId, ZSpec.BLANK_EXTENDED_PAN_ID)) {
1136
1177
  const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
1137
- if (status === enums_2.EmberStatus.SUCCESS) {
1178
+ if (status === enums_3.EmberStatus.SUCCESS) {
1138
1179
  this.networkCache.parameters = parameters;
1139
1180
  }
1140
1181
  else {
1141
- logger_1.logger.error(`Failed to get Extended PAN ID (via network parameters) with status=${enums_2.EmberStatus[status]}.`, NS);
1182
+ logger_1.logger.error(`Failed to get Extended PAN ID (via network parameters) with status=${enums_3.EmberStatus[status]}.`, NS);
1142
1183
  }
1143
1184
  }
1144
1185
  return this.networkCache.parameters.extendedPanId;
@@ -1151,11 +1192,11 @@ class EmberAdapter extends __1.Adapter {
1151
1192
  async emberGetRadioChannel() {
1152
1193
  if (this.networkCache.parameters.radioChannel === consts_2.INVALID_RADIO_CHANNEL) {
1153
1194
  const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
1154
- if (status === enums_2.EmberStatus.SUCCESS) {
1195
+ if (status === enums_3.EmberStatus.SUCCESS) {
1155
1196
  this.networkCache.parameters = parameters;
1156
1197
  }
1157
1198
  else {
1158
- logger_1.logger.error(`Failed to get radio channel (via network parameters) with status=${enums_2.EmberStatus[status]}.`, NS);
1199
+ logger_1.logger.error(`Failed to get radio channel (via network parameters) with status=${enums_3.EmberStatus[status]}.`, NS);
1159
1200
  }
1160
1201
  }
1161
1202
  return this.networkCache.parameters.radioChannel;
@@ -1164,14 +1205,14 @@ class EmberAdapter extends __1.Adapter {
1164
1205
  async emberStartEnergyScan() {
1165
1206
  return new Promise((resolve, reject) => {
1166
1207
  this.requestQueue.enqueue(async () => {
1167
- const status = (await this.ezsp.ezspStartScan(enums_2.EzspNetworkScanType.ENERGY_SCAN, consts_2.EMBER_ALL_802_15_4_CHANNELS_MASK, ENERGY_SCAN_DURATION));
1168
- if (status !== enums_2.SLStatus.OK) {
1169
- logger_1.logger.error(`Failed energy scan request with status=${enums_2.SLStatus[status]}.`, NS);
1170
- return enums_2.EmberStatus.ERR_FATAL;
1208
+ const status = (await this.ezsp.ezspStartScan(enums_3.EzspNetworkScanType.ENERGY_SCAN, consts_2.EMBER_ALL_802_15_4_CHANNELS_MASK, ENERGY_SCAN_DURATION));
1209
+ if (status !== enums_3.SLStatus.OK) {
1210
+ logger_1.logger.error(`Failed energy scan request with status=${enums_3.SLStatus[status]}.`, NS);
1211
+ return enums_3.EmberStatus.ERR_FATAL;
1171
1212
  }
1172
1213
  // TODO: result in logs only atm, since UI doesn't support it
1173
1214
  resolve();
1174
- return enums_2.EmberStatus.SUCCESS;
1215
+ return enums_3.EmberStatus.SUCCESS;
1175
1216
  }, reject);
1176
1217
  });
1177
1218
  }
@@ -1202,17 +1243,17 @@ class EmberAdapter extends __1.Adapter {
1202
1243
  }
1203
1244
  logger_1.logger.debug(`NCP info: EZSPVersion=${ncpEzspProtocolVer} StackType=${ncpStackType} StackVersion=${ncpStackVer}`, NS);
1204
1245
  const [status, versionStruct] = (await this.ezsp.ezspGetVersionStruct());
1205
- if (status !== enums_2.EzspStatus.SUCCESS) {
1246
+ if (status !== enums_3.EzspStatus.SUCCESS) {
1206
1247
  // Should never happen with support of only EZSP v13+
1207
1248
  throw new Error(`NCP has old-style version number. Not supported.`);
1208
1249
  }
1209
1250
  this.version = {
1210
1251
  ezsp: ncpEzspProtocolVer,
1211
- revision: `${versionStruct.major}.${versionStruct.minor}.${versionStruct.patch} [${enums_2.EmberVersionType[versionStruct.type]}]`,
1252
+ revision: `${versionStruct.major}.${versionStruct.minor}.${versionStruct.patch} [${enums_3.EmberVersionType[versionStruct.type]}]`,
1212
1253
  ...versionStruct,
1213
1254
  };
1214
- if (versionStruct.type !== enums_2.EmberVersionType.GA) {
1215
- logger_1.logger.warning(`NCP is running a non-GA version (${enums_2.EmberVersionType[versionStruct.type]}).`, NS);
1255
+ if (versionStruct.type !== enums_3.EmberVersionType.GA) {
1256
+ logger_1.logger.warning(`NCP is running a non-GA version (${enums_3.EmberVersionType[versionStruct.type]}).`, NS);
1216
1257
  }
1217
1258
  logger_1.logger.debug(`NCP version info: ${JSON.stringify(this.version)}`, NS);
1218
1259
  }
@@ -1226,13 +1267,13 @@ class EmberAdapter extends __1.Adapter {
1226
1267
  */
1227
1268
  async emberSetEzspConfigValue(configId, value) {
1228
1269
  const status = (await this.ezsp.ezspSetConfigurationValue(configId, value));
1229
- logger_1.logger.debug(`[EzspConfigId] SET "${enums_1.EzspConfigId[configId]}" TO "${value}" with status=${enums_2.EzspStatus[status]}.`, NS);
1230
- if (status === enums_2.EzspStatus.ERROR_INVALID_ID) {
1270
+ logger_1.logger.debug(`[EzspConfigId] SET "${enums_2.EzspConfigId[configId]}" TO "${value}" with status=${enums_3.EzspStatus[status]}.`, NS);
1271
+ if (status === enums_3.EzspStatus.ERROR_INVALID_ID) {
1231
1272
  // can be ZLL where not all NCPs need or support it.
1232
- logger_1.logger.warning(`[EzspConfigId] Unsupported configuration ID ${enums_1.EzspConfigId[configId]} by NCP.`, NS);
1273
+ logger_1.logger.warning(`[EzspConfigId] Unsupported configuration ID ${enums_2.EzspConfigId[configId]} by NCP.`, NS);
1233
1274
  }
1234
- else if (status !== enums_2.EzspStatus.SUCCESS) {
1235
- logger_1.logger.warning(`[EzspConfigId] Failed to SET "${enums_1.EzspConfigId[configId]}" TO "${value}" with status=${enums_2.EzspStatus[status]}. `
1275
+ else if (status !== enums_3.EzspStatus.SUCCESS) {
1276
+ logger_1.logger.warning(`[EzspConfigId] Failed to SET "${enums_2.EzspConfigId[configId]}" TO "${value}" with status=${enums_3.EzspStatus[status]}. `
1236
1277
  + `Firmware value will be used instead.`, NS);
1237
1278
  }
1238
1279
  return status;
@@ -1246,7 +1287,7 @@ class EmberAdapter extends __1.Adapter {
1246
1287
  */
1247
1288
  async emberSetEzspValue(valueId, valueLength, value) {
1248
1289
  const status = (await this.ezsp.ezspSetValue(valueId, valueLength, value));
1249
- logger_1.logger.debug(`[EzspValueId] SET "${enums_1.EzspValueId[valueId]}" TO "${value}" with status=${enums_2.EzspStatus[status]}.`, NS);
1290
+ logger_1.logger.debug(`[EzspValueId] SET "${enums_2.EzspValueId[valueId]}" TO "${value}" with status=${enums_3.EzspStatus[status]}.`, NS);
1250
1291
  return status;
1251
1292
  }
1252
1293
  /**
@@ -1257,7 +1298,7 @@ class EmberAdapter extends __1.Adapter {
1257
1298
  */
1258
1299
  async emberSetEzspPolicy(policyId, decisionId) {
1259
1300
  const status = (await this.ezsp.ezspSetPolicy(policyId, decisionId));
1260
- logger_1.logger.debug(`[EzspPolicyId] SET "${enums_1.EzspPolicyId[policyId]}" TO "${decisionId}" with status=${enums_2.EzspStatus[status]}.`, NS);
1301
+ logger_1.logger.debug(`[EzspPolicyId] SET "${enums_2.EzspPolicyId[policyId]}" TO "${decisionId}" with status=${enums_3.EzspStatus[status]}.`, NS);
1261
1302
  return status;
1262
1303
  }
1263
1304
  /**
@@ -1273,7 +1314,7 @@ class EmberAdapter extends __1.Adapter {
1273
1314
  */
1274
1315
  async aesMmoHash(context, finalize, data) {
1275
1316
  if (data.length > 255) {
1276
- throw new Error(enums_2.EzspStatus[enums_2.EzspStatus.ERROR_INVALID_CALL]);
1317
+ throw new Error(enums_3.EzspStatus[enums_3.EzspStatus.ERROR_INVALID_CALL]);
1277
1318
  }
1278
1319
  const [status, reContext] = (await this.ezsp.ezspAesMmoHash(context, finalize, data));
1279
1320
  return [status, reContext];
@@ -1352,7 +1393,7 @@ class EmberAdapter extends __1.Adapter {
1352
1393
  logger_1.logger.debug(`Permit joining for ${duration} sec. status=${[status]}`, NS);
1353
1394
  if (broadcastMgmtPermitJoin) {
1354
1395
  // `authentication`: TC significance always 1 (zb specs)
1355
- [status, apsFrame, messageTag] = (await this.emberPermitJoiningRequest(consts_2.EMBER_BROADCAST_ADDRESS, duration, 1, DEFAULT_APS_OPTIONS));
1396
+ [status, apsFrame, messageTag] = (await this.emberPermitJoiningRequest(enums_1.BroadcastAddress.DEFAULT, duration, 1, DEFAULT_APS_OPTIONS));
1356
1397
  }
1357
1398
  return [status, apsFrame, messageTag];
1358
1399
  }
@@ -1362,17 +1403,17 @@ class EmberAdapter extends __1.Adapter {
1362
1403
  * @returns
1363
1404
  */
1364
1405
  async emberSetJoinPolicy(decision) {
1365
- let policy = enums_1.EzspDecisionBitmask.DEFAULT_CONFIGURATION;
1366
- if (decision == enums_2.EmberJoinDecision.USE_PRECONFIGURED_KEY) {
1367
- policy = (enums_1.EzspDecisionBitmask.ALLOW_JOINS | enums_1.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS);
1406
+ let policy = enums_2.EzspDecisionBitmask.DEFAULT_CONFIGURATION;
1407
+ if (decision == enums_3.EmberJoinDecision.USE_PRECONFIGURED_KEY) {
1408
+ policy = (enums_2.EzspDecisionBitmask.ALLOW_JOINS | enums_2.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS);
1368
1409
  }
1369
- else if (decision == enums_2.EmberJoinDecision.SEND_KEY_IN_THE_CLEAR) {
1370
- policy = (enums_1.EzspDecisionBitmask.ALLOW_JOINS | enums_1.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS | enums_1.EzspDecisionBitmask.SEND_KEY_IN_CLEAR);
1410
+ else if (decision == enums_3.EmberJoinDecision.SEND_KEY_IN_THE_CLEAR) {
1411
+ policy = (enums_2.EzspDecisionBitmask.ALLOW_JOINS | enums_2.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS | enums_2.EzspDecisionBitmask.SEND_KEY_IN_CLEAR);
1371
1412
  }
1372
- else if (decision == enums_2.EmberJoinDecision.ALLOW_REJOINS_ONLY) {
1373
- policy = enums_1.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS;
1413
+ else if (decision == enums_3.EmberJoinDecision.ALLOW_REJOINS_ONLY) {
1414
+ policy = enums_2.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS;
1374
1415
  }
1375
- return this.emberSetEzspPolicy(enums_1.EzspPolicyId.TRUST_CENTER_POLICY, policy);
1416
+ return this.emberSetEzspPolicy(enums_2.EzspPolicyId.TRUST_CENTER_POLICY, policy);
1376
1417
  }
1377
1418
  /**
1378
1419
  * Get Source Route Overhead
@@ -1389,11 +1430,11 @@ class EmberAdapter extends __1.Adapter {
1389
1430
  */
1390
1431
  async emberGetSourceRouteOverhead(destination) {
1391
1432
  const [status, value] = (await this.ezsp.ezspGetSourceRouteOverhead(destination));
1392
- if (status === enums_2.EzspStatus.SUCCESS) {
1433
+ if (status === enums_3.EzspStatus.SUCCESS) {
1393
1434
  return value;
1394
1435
  }
1395
1436
  else {
1396
- logger_1.logger.debug(`Failed to get source route overhead (via extended value), status=${enums_2.EzspStatus[status]}.`, NS);
1437
+ logger_1.logger.debug(`Failed to get source route overhead (via extended value), status=${enums_3.EzspStatus[status]}.`, NS);
1397
1438
  }
1398
1439
  return 0;
1399
1440
  }
@@ -1414,34 +1455,34 @@ class EmberAdapter extends __1.Adapter {
1414
1455
  async maximumApsPayloadLength(type, indexOrDestination, apsFrame) {
1415
1456
  let destination = consts_2.EMBER_UNKNOWN_NODE_ID;
1416
1457
  let max = consts_2.MAXIMUM_APS_PAYLOAD_LENGTH; // uint8_t
1417
- if ((apsFrame.options & enums_2.EmberApsOption.ENCRYPTION) !== 0) {
1458
+ if ((apsFrame.options & enums_3.EmberApsOption.ENCRYPTION) !== 0) {
1418
1459
  max -= consts_2.APS_ENCRYPTION_OVERHEAD;
1419
1460
  }
1420
- if ((apsFrame.options & enums_2.EmberApsOption.SOURCE_EUI64) !== 0) {
1461
+ if ((apsFrame.options & enums_3.EmberApsOption.SOURCE_EUI64) !== 0) {
1421
1462
  max -= consts_1.EUI64_SIZE;
1422
1463
  }
1423
- if ((apsFrame.options & enums_2.EmberApsOption.DESTINATION_EUI64) !== 0) {
1464
+ if ((apsFrame.options & enums_3.EmberApsOption.DESTINATION_EUI64) !== 0) {
1424
1465
  max -= consts_1.EUI64_SIZE;
1425
1466
  }
1426
- if ((apsFrame.options & enums_2.EmberApsOption.FRAGMENT) !== 0) {
1467
+ if ((apsFrame.options & enums_3.EmberApsOption.FRAGMENT) !== 0) {
1427
1468
  max -= consts_2.APS_FRAGMENTATION_OVERHEAD;
1428
1469
  }
1429
1470
  switch (type) {
1430
- case enums_2.EmberOutgoingMessageType.DIRECT:
1471
+ case enums_3.EmberOutgoingMessageType.DIRECT:
1431
1472
  destination = indexOrDestination;
1432
1473
  break;
1433
- case enums_2.EmberOutgoingMessageType.VIA_ADDRESS_TABLE:
1474
+ case enums_3.EmberOutgoingMessageType.VIA_ADDRESS_TABLE:
1434
1475
  destination = (await this.ezsp.ezspGetAddressTableRemoteNodeId(indexOrDestination));
1435
1476
  break;
1436
- case enums_2.EmberOutgoingMessageType.VIA_BINDING:
1477
+ case enums_3.EmberOutgoingMessageType.VIA_BINDING:
1437
1478
  destination = (await this.ezsp.ezspGetBindingRemoteNodeId(indexOrDestination));
1438
1479
  break;
1439
- case enums_2.EmberOutgoingMessageType.MULTICAST:
1480
+ case enums_3.EmberOutgoingMessageType.MULTICAST:
1440
1481
  // APS multicast messages include the two-byte group id and exclude the one-byte destination endpoint,
1441
1482
  // for a net loss of an extra byte.
1442
1483
  max--;
1443
1484
  break;
1444
- case enums_2.EmberOutgoingMessageType.BROADCAST:
1485
+ case enums_3.EmberOutgoingMessageType.BROADCAST:
1445
1486
  break;
1446
1487
  default:
1447
1488
  break;
@@ -1495,7 +1536,7 @@ class EmberAdapter extends __1.Adapter {
1495
1536
  */
1496
1537
  async sendZDORequestBuffer(destination, clusterId, options) {
1497
1538
  if (this.zdoRequestBuffalo.getPosition() > consts_1.EZSP_MAX_FRAME_LENGTH) {
1498
- return [enums_2.EmberStatus.MESSAGE_TOO_LONG, null, null];
1539
+ return [enums_3.EmberStatus.MESSAGE_TOO_LONG, null, null];
1499
1540
  }
1500
1541
  const messageTag = this.nextZDORequestSequence();
1501
1542
  this.zdoRequestBuffalo.setCommandByte(0, messageTag);
@@ -1509,19 +1550,19 @@ class EmberAdapter extends __1.Adapter {
1509
1550
  sequence: 0, // set by stack
1510
1551
  };
1511
1552
  const messageContents = this.zdoRequestBuffalo.getWritten();
1512
- if (destination === consts_2.EMBER_BROADCAST_ADDRESS || destination === consts_2.EMBER_RX_ON_WHEN_IDLE_BROADCAST_ADDRESS
1513
- || destination === consts_2.EMBER_SLEEPY_BROADCAST_ADDRESS) {
1553
+ if (destination === enums_1.BroadcastAddress.DEFAULT || destination === enums_1.BroadcastAddress.RX_ON_WHEN_IDLE
1554
+ || destination === enums_1.BroadcastAddress.SLEEPY) {
1514
1555
  logger_1.logger.debug(`~~~> [ZDO BROADCAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
1515
1556
  const [status, apsSequence] = (await this.ezsp.ezspSendBroadcast(destination, apsFrame, this.getZDORequestRadius(), messageTag, messageContents));
1516
1557
  apsFrame.sequence = apsSequence;
1517
- logger_1.logger.debug(`~~~> [SENT ZDO type=BROADCAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${enums_2.EmberStatus[status]}]`, NS);
1558
+ logger_1.logger.debug(`~~~> [SENT ZDO type=BROADCAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${enums_3.EmberStatus[status]}]`, NS);
1518
1559
  return [status, apsFrame, messageTag];
1519
1560
  }
1520
1561
  else {
1521
1562
  logger_1.logger.debug(`~~~> [ZDO UNICAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
1522
- const [status, apsSequence] = (await this.ezsp.ezspSendUnicast(enums_2.EmberOutgoingMessageType.DIRECT, destination, apsFrame, messageTag, messageContents));
1563
+ const [status, apsSequence] = (await this.ezsp.ezspSendUnicast(enums_3.EmberOutgoingMessageType.DIRECT, destination, apsFrame, messageTag, messageContents));
1523
1564
  apsFrame.sequence = apsSequence;
1524
- logger_1.logger.debug(`~~~> [SENT ZDO type=DIRECT apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${enums_2.EmberStatus[status]}]`, NS);
1565
+ logger_1.logger.debug(`~~~> [SENT ZDO type=DIRECT apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${enums_3.EmberStatus[status]}]`, NS);
1525
1566
  return [status, apsFrame, messageTag];
1526
1567
  }
1527
1568
  }
@@ -1554,7 +1595,7 @@ class EmberAdapter extends __1.Adapter {
1554
1595
  const length = (zdo_1.ZDO_MESSAGE_OVERHEAD + 2 + 2 + 1 + (inClusters.length * 2) + 1 + (outClusters.length * 2));
1555
1596
  // sanity check
1556
1597
  if (length > consts_1.EZSP_MAX_FRAME_LENGTH) {
1557
- return [enums_2.EmberStatus.MESSAGE_TOO_LONG, null, null];
1598
+ return [enums_3.EmberStatus.MESSAGE_TOO_LONG, null, null];
1558
1599
  }
1559
1600
  this.zdoRequestBuffalo.setPosition(zdo_1.ZDO_MESSAGE_OVERHEAD);
1560
1601
  this.zdoRequestBuffalo.writeUInt16(target);
@@ -1589,7 +1630,7 @@ class EmberAdapter extends __1.Adapter {
1589
1630
  this.zdoRequestBuffalo.writeUInt8(reportKids ? 1 : 0);
1590
1631
  this.zdoRequestBuffalo.writeUInt8(childStartIndex);
1591
1632
  logger_1.logger.debug(`~~~> [ZDO NETWORK_ADDRESS_REQUEST target=${target} reportKids=${reportKids} childStartIndex=${childStartIndex}]`, NS);
1592
- return this.sendZDORequestBuffer(consts_2.EMBER_RX_ON_WHEN_IDLE_BROADCAST_ADDRESS, zdo_1.NETWORK_ADDRESS_REQUEST, enums_2.EmberApsOption.SOURCE_EUI64);
1633
+ return this.sendZDORequestBuffer(enums_1.BroadcastAddress.RX_ON_WHEN_IDLE, zdo_1.NETWORK_ADDRESS_REQUEST, enums_3.EmberApsOption.SOURCE_EUI64);
1593
1634
  }
1594
1635
  /**
1595
1636
  * ZDO
@@ -1711,7 +1752,7 @@ class EmberAdapter extends __1.Adapter {
1711
1752
  this.zdoRequestBuffalo.writeUInt16(groupAddress);
1712
1753
  break;
1713
1754
  default:
1714
- return [enums_2.EmberStatus.ERR_FATAL, null, null];
1755
+ return [enums_3.EmberStatus.ERR_FATAL, null, null];
1715
1756
  }
1716
1757
  return this.sendZDORequestBuffer(target, bindClusterId, options);
1717
1758
  }
@@ -2040,7 +2081,7 @@ class EmberAdapter extends __1.Adapter {
2040
2081
  const ieeeAddr = (await this.emberGetEui64());
2041
2082
  resolve({
2042
2083
  ieeeAddr,
2043
- networkAddress: consts_2.ZIGBEE_COORDINATOR_ADDRESS,
2084
+ networkAddress: ZSpec.COORDINATOR_ADDRESS,
2044
2085
  manufacturerID: DEFAULT_MANUFACTURER_CODE,
2045
2086
  endpoints: endpoints_1.FIXED_ENDPOINTS.map((ep) => {
2046
2087
  return {
@@ -2052,7 +2093,7 @@ class EmberAdapter extends __1.Adapter {
2052
2093
  };
2053
2094
  }),
2054
2095
  });
2055
- return enums_2.EmberStatus.SUCCESS;
2096
+ return enums_3.EmberStatus.SUCCESS;
2056
2097
  }, reject);
2057
2098
  });
2058
2099
  }
@@ -2077,7 +2118,7 @@ class EmberAdapter extends __1.Adapter {
2077
2118
  this.requestQueue.enqueue(async () => {
2078
2119
  // grab fresh version here, bypass cache
2079
2120
  const [netStatus, , netParams] = (await this.ezsp.ezspGetNetworkParameters());
2080
- if (netStatus !== enums_2.EmberStatus.SUCCESS) {
2121
+ if (netStatus !== enums_3.EmberStatus.SUCCESS) {
2081
2122
  logger_1.logger.error(`[BACKUP] Failed to get network parameters.`, NS);
2082
2123
  return netStatus;
2083
2124
  }
@@ -2085,10 +2126,10 @@ class EmberAdapter extends __1.Adapter {
2085
2126
  this.networkCache.parameters = netParams;
2086
2127
  this.networkCache.eui64 = (await this.ezsp.ezspGetEui64());
2087
2128
  const [netKeyStatus, netKeyInfo] = (await this.ezsp.ezspGetNetworkKeyInfo());
2088
- if (netKeyStatus !== enums_2.SLStatus.OK) {
2129
+ if (netKeyStatus !== enums_3.SLStatus.OK) {
2089
2130
  logger_1.logger.error(`[BACKUP] Failed to get network keys info.`, NS);
2090
- return ((netKeyStatus === enums_2.SLStatus.BUSY) || (netKeyStatus === enums_2.SLStatus.NOT_READY))
2091
- ? enums_2.EmberStatus.NETWORK_BUSY : enums_2.EmberStatus.ERR_FATAL; // allow retry on statuses that should be temporary
2131
+ return ((netKeyStatus === enums_3.SLStatus.BUSY) || (netKeyStatus === enums_3.SLStatus.NOT_READY))
2132
+ ? enums_3.EmberStatus.NETWORK_BUSY : enums_3.EmberStatus.ERR_FATAL; // allow retry on statuses that should be temporary
2092
2133
  }
2093
2134
  if (!netKeyInfo.networkKeySet) {
2094
2135
  throw new Error(`[BACKUP] No network key set.`);
@@ -2103,17 +2144,17 @@ class EmberAdapter extends __1.Adapter {
2103
2144
  // Buffer.from(this.networkCache.eui64.substring(2/*0x*/), 'hex').reverse()
2104
2145
  // ));
2105
2146
  let context = (0, initters_1.initSecurityManagerContext)();
2106
- context.coreKeyType = enums_2.SecManKeyType.TC_LINK;
2147
+ context.coreKeyType = enums_3.SecManKeyType.TC_LINK;
2107
2148
  const [tcLinkKey, tclkStatus] = (await this.ezsp.ezspExportKey(context));
2108
- if (tclkStatus !== enums_2.SLStatus.OK) {
2109
- throw new Error(`[BACKUP] Failed to export TC Link Key with status=${enums_2.SLStatus[tclkStatus]}.`);
2149
+ if (tclkStatus !== enums_3.SLStatus.OK) {
2150
+ throw new Error(`[BACKUP] Failed to export TC Link Key with status=${enums_3.SLStatus[tclkStatus]}.`);
2110
2151
  }
2111
2152
  context = (0, initters_1.initSecurityManagerContext)(); // make sure it's back to zeroes
2112
- context.coreKeyType = enums_2.SecManKeyType.NETWORK;
2153
+ context.coreKeyType = enums_3.SecManKeyType.NETWORK;
2113
2154
  context.keyIndex = 0;
2114
2155
  const [networkKey, nkStatus] = (await this.ezsp.ezspExportKey(context));
2115
- if (nkStatus !== enums_2.SLStatus.OK) {
2116
- throw new Error(`[BACKUP] Failed to export Network Key with status=${enums_2.SLStatus[nkStatus]}.`);
2156
+ if (nkStatus !== enums_3.SLStatus.OK) {
2157
+ throw new Error(`[BACKUP] Failed to export Network Key with status=${enums_3.SLStatus[nkStatus]}.`);
2117
2158
  }
2118
2159
  const zbChannels = Array.from(Array(consts_2.EMBER_NUM_802_15_4_CHANNELS), (e, i) => i + consts_2.EMBER_MIN_802_15_4_CHANNEL_NUMBER);
2119
2160
  resolve({
@@ -2149,7 +2190,7 @@ class EmberAdapter extends __1.Adapter {
2149
2190
  // altNetworkKey: altNetworkKey.contents,
2150
2191
  }
2151
2192
  });
2152
- return enums_2.EmberStatus.SUCCESS;
2193
+ return enums_3.EmberStatus.SUCCESS;
2153
2194
  }, reject, true);
2154
2195
  });
2155
2196
  }
@@ -2168,7 +2209,7 @@ class EmberAdapter extends __1.Adapter {
2168
2209
  extendedPanID: parseInt(Buffer.from(extendedPanID).toString('hex'), 16),
2169
2210
  channel,
2170
2211
  });
2171
- return enums_2.EmberStatus.SUCCESS;
2212
+ return enums_3.EmberStatus.SUCCESS;
2172
2213
  }, reject);
2173
2214
  });
2174
2215
  }
@@ -2181,15 +2222,15 @@ class EmberAdapter extends __1.Adapter {
2181
2222
  this.requestQueue.enqueue(async () => {
2182
2223
  this.checkInterpanLock();
2183
2224
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2184
- const [status, apsFrame, messageTag] = (await this.emberChannelChangeRequest(consts_2.EMBER_SLEEPY_BROADCAST_ADDRESS, newChannel, DEFAULT_APS_OPTIONS));
2185
- if (status !== enums_2.EmberStatus.SUCCESS) {
2186
- logger_1.logger.error(`[ZDO] Failed broadcast channel change to "${newChannel}" with status=${enums_2.EmberStatus[status]}.`, NS);
2225
+ const [status, apsFrame, messageTag] = (await this.emberChannelChangeRequest(enums_1.BroadcastAddress.SLEEPY, newChannel, DEFAULT_APS_OPTIONS));
2226
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2227
+ logger_1.logger.error(`[ZDO] Failed broadcast channel change to "${newChannel}" with status=${enums_3.EmberStatus[status]}.`, NS);
2187
2228
  return status;
2188
2229
  }
2189
2230
  await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_CHANNEL_CHANGED }, DEFAULT_NETWORK_REQUEST_TIMEOUT * 2, // observed to ~9sec
2190
2231
  '[ZDO] Change Channel');
2191
2232
  resolve();
2192
- return enums_2.EmberStatus.SUCCESS;
2233
+ return enums_3.EmberStatus.SUCCESS;
2193
2234
  }, reject);
2194
2235
  });
2195
2236
  }
@@ -2202,12 +2243,12 @@ class EmberAdapter extends __1.Adapter {
2202
2243
  return new Promise((resolve, reject) => {
2203
2244
  this.requestQueue.enqueue(async () => {
2204
2245
  const status = await this.ezsp.ezspSetRadioPower(value);
2205
- if (status !== enums_2.EmberStatus.SUCCESS) {
2206
- logger_1.logger.error(`Failed to set transmit power to ${value} status=${enums_2.EmberStatus[status]}.`, NS);
2246
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2247
+ logger_1.logger.error(`Failed to set transmit power to ${value} status=${enums_3.EmberStatus[status]}.`, NS);
2207
2248
  return status;
2208
2249
  }
2209
2250
  resolve();
2210
- return enums_2.EmberStatus.SUCCESS;
2251
+ return enums_3.EmberStatus.SUCCESS;
2211
2252
  }, reject);
2212
2253
  });
2213
2254
  }
@@ -2241,22 +2282,22 @@ class EmberAdapter extends __1.Adapter {
2241
2282
  this.requestQueue.enqueue(async () => {
2242
2283
  // Compute the key from the install code and CRC.
2243
2284
  const [aesStatus, keyContents] = (await this.emberAesHashSimple(key));
2244
- if (aesStatus !== enums_2.EmberStatus.SUCCESS) {
2245
- logger_1.logger.error(`[ADD INSTALL CODE] Failed AES hash for '${ieeeAddress}' with status=${enums_2.EmberStatus[aesStatus]}.`, NS);
2285
+ if (aesStatus !== enums_3.EmberStatus.SUCCESS) {
2286
+ logger_1.logger.error(`[ADD INSTALL CODE] Failed AES hash for '${ieeeAddress}' with status=${enums_3.EmberStatus[aesStatus]}.`, NS);
2246
2287
  return aesStatus;
2247
2288
  }
2248
2289
  // Add the key to the transient key table.
2249
2290
  // This will be used while the DUT joins.
2250
- const impStatus = (await this.ezsp.ezspImportTransientKey(ieeeAddress, { contents: keyContents }, enums_2.SecManFlag.NONE));
2251
- if (impStatus == enums_2.SLStatus.OK) {
2291
+ const impStatus = (await this.ezsp.ezspImportTransientKey(ieeeAddress, { contents: keyContents }, enums_3.SecManFlag.NONE));
2292
+ if (impStatus == enums_3.SLStatus.OK) {
2252
2293
  logger_1.logger.debug(`[ADD INSTALL CODE] Success for '${ieeeAddress}'.`, NS);
2253
2294
  }
2254
2295
  else {
2255
- logger_1.logger.error(`[ADD INSTALL CODE] Failed for '${ieeeAddress}' with status=${enums_2.SLStatus[impStatus]}.`, NS);
2256
- return enums_2.EmberStatus.ERR_FATAL;
2296
+ logger_1.logger.error(`[ADD INSTALL CODE] Failed for '${ieeeAddress}' with status=${enums_3.SLStatus[impStatus]}.`, NS);
2297
+ return enums_3.EmberStatus.ERR_FATAL;
2257
2298
  }
2258
2299
  resolve();
2259
- return enums_2.EmberStatus.SUCCESS;
2300
+ return enums_3.EmberStatus.SUCCESS;
2260
2301
  }, reject);
2261
2302
  });
2262
2303
  }
@@ -2272,7 +2313,7 @@ class EmberAdapter extends __1.Adapter {
2272
2313
  sourceEndpoint: sourceEndpointInfo.endpoint,
2273
2314
  destinationEndpoint: endpoint,
2274
2315
  groupId: 0,
2275
- options: enums_2.EmberApsOption.NONE,
2316
+ options: enums_3.EmberApsOption.NONE,
2276
2317
  },
2277
2318
  zclSequence: transactionSequenceNumber,
2278
2319
  commandIdentifier,
@@ -2288,17 +2329,17 @@ class EmberAdapter extends __1.Adapter {
2288
2329
  const preJoining = async () => {
2289
2330
  if (seconds) {
2290
2331
  const plaintextKey = { contents: Buffer.from(consts_2.ZIGBEE_PROFILE_INTEROPERABILITY_LINK_KEY) };
2291
- const impKeyStatus = (await this.ezsp.ezspImportTransientKey(consts_2.BLANK_EUI64, plaintextKey, enums_2.SecManFlag.NONE));
2292
- if (impKeyStatus !== enums_2.SLStatus.OK) {
2293
- logger_1.logger.error(`[ZDO] Failed import transient key with status=${enums_2.SLStatus[impKeyStatus]}.`, NS);
2294
- return enums_2.EmberStatus.ERR_FATAL;
2332
+ const impKeyStatus = (await this.ezsp.ezspImportTransientKey(ZSpec.BLANK_EUI64, plaintextKey, enums_3.SecManFlag.NONE));
2333
+ if (impKeyStatus !== enums_3.SLStatus.OK) {
2334
+ logger_1.logger.error(`[ZDO] Failed import transient key with status=${enums_3.SLStatus[impKeyStatus]}.`, NS);
2335
+ return enums_3.EmberStatus.ERR_FATAL;
2295
2336
  }
2296
- const setJPstatus = (await this.emberSetJoinPolicy(enums_2.EmberJoinDecision.USE_PRECONFIGURED_KEY));
2297
- if (setJPstatus !== enums_2.EzspStatus.SUCCESS) {
2298
- logger_1.logger.error(`[ZDO] Failed set join policy with status=${enums_2.EzspStatus[setJPstatus]}.`, NS);
2299
- return enums_2.EmberStatus.ERR_FATAL;
2337
+ const setJPstatus = (await this.emberSetJoinPolicy(enums_3.EmberJoinDecision.USE_PRECONFIGURED_KEY));
2338
+ if (setJPstatus !== enums_3.EzspStatus.SUCCESS) {
2339
+ logger_1.logger.error(`[ZDO] Failed set join policy with status=${enums_3.EzspStatus[setJPstatus]}.`, NS);
2340
+ return enums_3.EmberStatus.ERR_FATAL;
2300
2341
  }
2301
- return enums_2.EmberStatus.SUCCESS;
2342
+ return enums_3.EmberStatus.SUCCESS;
2302
2343
  }
2303
2344
  else {
2304
2345
  if (this.manufacturerCode !== DEFAULT_MANUFACTURER_CODE) {
@@ -2307,12 +2348,12 @@ class EmberAdapter extends __1.Adapter {
2307
2348
  this.manufacturerCode = DEFAULT_MANUFACTURER_CODE;
2308
2349
  }
2309
2350
  await this.ezsp.ezspClearTransientLinkKeys();
2310
- const setJPstatus = (await this.emberSetJoinPolicy(enums_2.EmberJoinDecision.ALLOW_REJOINS_ONLY));
2311
- if (setJPstatus !== enums_2.EzspStatus.SUCCESS) {
2312
- logger_1.logger.error(`[ZDO] Failed set join policy for with status=${enums_2.EzspStatus[setJPstatus]}.`, NS);
2313
- return enums_2.EmberStatus.ERR_FATAL;
2351
+ const setJPstatus = (await this.emberSetJoinPolicy(enums_3.EmberJoinDecision.ALLOW_REJOINS_ONLY));
2352
+ if (setJPstatus !== enums_3.EzspStatus.SUCCESS) {
2353
+ logger_1.logger.error(`[ZDO] Failed set join policy for with status=${enums_3.EzspStatus[setJPstatus]}.`, NS);
2354
+ return enums_3.EmberStatus.ERR_FATAL;
2314
2355
  }
2315
- return enums_2.EmberStatus.SUCCESS;
2356
+ return enums_3.EmberStatus.SUCCESS;
2316
2357
  }
2317
2358
  };
2318
2359
  if (networkAddress) {
@@ -2321,15 +2362,15 @@ class EmberAdapter extends __1.Adapter {
2321
2362
  this.requestQueue.enqueue(async () => {
2322
2363
  this.checkInterpanLock();
2323
2364
  const pjStatus = (await preJoining());
2324
- if (pjStatus !== enums_2.EmberStatus.SUCCESS) {
2325
- logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${enums_2.EmberStatus[pjStatus]}.`, NS);
2365
+ if (pjStatus !== enums_3.EmberStatus.SUCCESS) {
2366
+ logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${enums_3.EmberStatus[pjStatus]}.`, NS);
2326
2367
  return pjStatus;
2327
2368
  }
2328
2369
  // `authentication`: TC significance always 1 (zb specs)
2329
2370
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2330
2371
  const [status, apsFrame, messageTag] = (await this.emberPermitJoiningRequest(networkAddress, seconds, 1, 0));
2331
- if (status !== enums_2.EmberStatus.SUCCESS) {
2332
- logger_1.logger.error(`[ZDO] Failed permit joining request for "${networkAddress}" with status=${enums_2.EmberStatus[status]}.`, NS);
2372
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2373
+ logger_1.logger.error(`[ZDO] Failed permit joining request for "${networkAddress}" with status=${enums_3.EmberStatus[status]}.`, NS);
2333
2374
  return status;
2334
2375
  }
2335
2376
  (await this.oneWaitress.startWaitingFor({
@@ -2338,7 +2379,7 @@ class EmberAdapter extends __1.Adapter {
2338
2379
  responseClusterId: zdo_1.PERMIT_JOINING_RESPONSE,
2339
2380
  }, DEFAULT_ZDO_REQUEST_TIMEOUT));
2340
2381
  resolve();
2341
- return enums_2.EmberStatus.SUCCESS;
2382
+ return enums_3.EmberStatus.SUCCESS;
2342
2383
  }, reject);
2343
2384
  });
2344
2385
  }
@@ -2348,15 +2389,15 @@ class EmberAdapter extends __1.Adapter {
2348
2389
  this.requestQueue.enqueue(async () => {
2349
2390
  this.checkInterpanLock();
2350
2391
  const pjStatus = (await preJoining());
2351
- if (pjStatus !== enums_2.EmberStatus.SUCCESS) {
2352
- logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${enums_2.EmberStatus[pjStatus]}.`, NS);
2392
+ if (pjStatus !== enums_3.EmberStatus.SUCCESS) {
2393
+ logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${enums_3.EmberStatus[pjStatus]}.`, NS);
2353
2394
  return pjStatus;
2354
2395
  }
2355
2396
  // local permit join if `Coordinator`-only requested, else local + broadcast
2356
2397
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2357
- const [status, apsFrame, messageTag] = (await this.emberPermitJoining(seconds, (networkAddress === consts_2.ZIGBEE_COORDINATOR_ADDRESS) ? false : true));
2358
- if (status !== enums_2.EmberStatus.SUCCESS) {
2359
- logger_1.logger.error(`[ZDO] Failed permit joining request with status=${enums_2.EmberStatus[status]}.`, NS);
2398
+ const [status, apsFrame, messageTag] = (await this.emberPermitJoining(seconds, (networkAddress === ZSpec.COORDINATOR_ADDRESS) ? false : true));
2399
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2400
+ logger_1.logger.error(`[ZDO] Failed permit joining request with status=${enums_3.EmberStatus[status]}.`, NS);
2360
2401
  return status;
2361
2402
  }
2362
2403
  // NOTE: because Z2M is refreshing the permit join duration early to prevent it from closing
@@ -2377,7 +2418,7 @@ class EmberAdapter extends __1.Adapter {
2377
2418
  // // same kind of problem as described above (upstream always tries to close after start, but EZSP already is)
2378
2419
  // }
2379
2420
  resolve();
2380
- return enums_2.EmberStatus.SUCCESS;
2421
+ return enums_3.EmberStatus.SUCCESS;
2381
2422
  }, reject);
2382
2423
  });
2383
2424
  }
@@ -2388,8 +2429,8 @@ class EmberAdapter extends __1.Adapter {
2388
2429
  const request = async (startIndex) => {
2389
2430
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2390
2431
  const [reqStatus, apsFrame, messageTag] = (await this.emberLqiTableRequest(networkAddress, startIndex, DEFAULT_APS_OPTIONS));
2391
- if (reqStatus !== enums_2.EmberStatus.SUCCESS) {
2392
- logger_1.logger.error(`[ZDO] Failed LQI request for "${networkAddress}" (index "${startIndex}") with status=${enums_2.EmberStatus[reqStatus]}.`, NS);
2432
+ if (reqStatus !== enums_3.EmberStatus.SUCCESS) {
2433
+ logger_1.logger.error(`[ZDO] Failed LQI request for "${networkAddress}" (index "${startIndex}") with status=${enums_3.EmberStatus[reqStatus]}.`, NS);
2393
2434
  return [reqStatus, null, null];
2394
2435
  }
2395
2436
  const result = (await this.oneWaitress.startWaitingFor({
@@ -2406,20 +2447,20 @@ class EmberAdapter extends __1.Adapter {
2406
2447
  depth: entry.depth,
2407
2448
  });
2408
2449
  }
2409
- return [enums_2.EmberStatus.SUCCESS, result.neighborTableEntries, result.entryList.length];
2450
+ return [enums_3.EmberStatus.SUCCESS, result.neighborTableEntries, result.entryList.length];
2410
2451
  };
2411
2452
  return new Promise((resolve, reject) => {
2412
2453
  this.requestQueue.enqueue(async () => {
2413
2454
  this.checkInterpanLock();
2414
2455
  let [status, tableEntries, entryCount] = (await request(0));
2415
- if (status !== enums_2.EmberStatus.SUCCESS) {
2456
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2416
2457
  return status;
2417
2458
  }
2418
2459
  const size = tableEntries;
2419
2460
  let nextStartIndex = entryCount;
2420
2461
  while (neighbors.length < size) {
2421
2462
  [status, tableEntries, entryCount] = (await request(nextStartIndex));
2422
- if (status !== enums_2.EmberStatus.SUCCESS) {
2463
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2423
2464
  return status;
2424
2465
  }
2425
2466
  nextStartIndex += entryCount;
@@ -2435,8 +2476,8 @@ class EmberAdapter extends __1.Adapter {
2435
2476
  const request = async (startIndex) => {
2436
2477
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2437
2478
  const [reqStatus, apsFrame, messageTag] = (await this.emberRoutingTableRequest(networkAddress, startIndex, DEFAULT_APS_OPTIONS));
2438
- if (reqStatus !== enums_2.EmberStatus.SUCCESS) {
2439
- logger_1.logger.error(`[ZDO] Failed routing table request for "${networkAddress}" (index "${startIndex}") with status=${enums_2.EmberStatus[reqStatus]}.`, NS);
2479
+ if (reqStatus !== enums_3.EmberStatus.SUCCESS) {
2480
+ logger_1.logger.error(`[ZDO] Failed routing table request for "${networkAddress}" (index "${startIndex}") with status=${enums_3.EmberStatus[reqStatus]}.`, NS);
2440
2481
  return [reqStatus, null, null];
2441
2482
  }
2442
2483
  const result = (await this.oneWaitress.startWaitingFor({
@@ -2451,26 +2492,26 @@ class EmberAdapter extends __1.Adapter {
2451
2492
  nextHop: entry.nextHopAddress,
2452
2493
  });
2453
2494
  }
2454
- return [enums_2.EmberStatus.SUCCESS, result.routingTableEntries, result.entryList.length];
2495
+ return [enums_3.EmberStatus.SUCCESS, result.routingTableEntries, result.entryList.length];
2455
2496
  };
2456
2497
  return new Promise((resolve, reject) => {
2457
2498
  this.requestQueue.enqueue(async () => {
2458
2499
  this.checkInterpanLock();
2459
2500
  let [status, tableEntries, entryCount] = (await request(0));
2460
- if (status !== enums_2.EmberStatus.SUCCESS) {
2501
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2461
2502
  return status;
2462
2503
  }
2463
2504
  const size = tableEntries;
2464
2505
  let nextStartIndex = entryCount;
2465
2506
  while (table.length < size) {
2466
2507
  [status, tableEntries, entryCount] = (await request(nextStartIndex));
2467
- if (status !== enums_2.EmberStatus.SUCCESS) {
2508
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2468
2509
  return status;
2469
2510
  }
2470
2511
  nextStartIndex += entryCount;
2471
2512
  }
2472
2513
  resolve({ table });
2473
- return enums_2.EmberStatus.SUCCESS;
2514
+ return enums_3.EmberStatus.SUCCESS;
2474
2515
  }, reject);
2475
2516
  });
2476
2517
  }
@@ -2481,8 +2522,8 @@ class EmberAdapter extends __1.Adapter {
2481
2522
  this.checkInterpanLock();
2482
2523
  /* eslint-disable @typescript-eslint/no-unused-vars */
2483
2524
  const [status, apsFrame, messageTag] = (await this.emberNodeDescriptorRequest(networkAddress, DEFAULT_APS_OPTIONS));
2484
- if (status !== enums_2.EmberStatus.SUCCESS) {
2485
- logger_1.logger.error(`[ZDO] Failed node descriptor for "${networkAddress}" with status=${enums_2.EmberStatus[status]}.`, NS);
2525
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2526
+ logger_1.logger.error(`[ZDO] Failed node descriptor for "${networkAddress}" with status=${enums_3.EmberStatus[status]}.`, NS);
2486
2527
  return status;
2487
2528
  }
2488
2529
  const result = (await this.oneWaitress.startWaitingFor({
@@ -2509,7 +2550,7 @@ class EmberAdapter extends __1.Adapter {
2509
2550
  + `(current revision: ${CURRENT_ZIGBEE_SPEC_REVISION}).`, NS);
2510
2551
  }
2511
2552
  resolve({ type, manufacturerCode: result.manufacturerCode });
2512
- return enums_2.EmberStatus.SUCCESS;
2553
+ return enums_3.EmberStatus.SUCCESS;
2513
2554
  }, reject);
2514
2555
  });
2515
2556
  }
@@ -2520,8 +2561,8 @@ class EmberAdapter extends __1.Adapter {
2520
2561
  this.checkInterpanLock();
2521
2562
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2522
2563
  const [status, apsFrame, messageTag] = (await this.emberActiveEndpointsRequest(networkAddress, DEFAULT_APS_OPTIONS));
2523
- if (status !== enums_2.EmberStatus.SUCCESS) {
2524
- logger_1.logger.error(`[ZDO] Failed active endpoints request for "${networkAddress}" with status=${enums_2.EmberStatus[status]}.`, NS);
2564
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2565
+ logger_1.logger.error(`[ZDO] Failed active endpoints request for "${networkAddress}" with status=${enums_3.EmberStatus[status]}.`, NS);
2525
2566
  return status;
2526
2567
  }
2527
2568
  const result = (await this.oneWaitress.startWaitingFor({
@@ -2530,7 +2571,7 @@ class EmberAdapter extends __1.Adapter {
2530
2571
  responseClusterId: zdo_1.ACTIVE_ENDPOINTS_RESPONSE,
2531
2572
  }, DEFAULT_ZDO_REQUEST_TIMEOUT));
2532
2573
  resolve({ endpoints: result.endpointList });
2533
- return enums_2.EmberStatus.SUCCESS;
2574
+ return enums_3.EmberStatus.SUCCESS;
2534
2575
  }, reject);
2535
2576
  });
2536
2577
  }
@@ -2541,9 +2582,9 @@ class EmberAdapter extends __1.Adapter {
2541
2582
  this.checkInterpanLock();
2542
2583
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2543
2584
  const [status, apsFrame, messageTag] = (await this.emberSimpleDescriptorRequest(networkAddress, endpointID, DEFAULT_APS_OPTIONS));
2544
- if (status !== enums_2.EmberStatus.SUCCESS) {
2585
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2545
2586
  logger_1.logger.error(`[ZDO] Failed simple descriptor request for "${networkAddress}" endpoint "${endpointID}" `
2546
- + `with status=${enums_2.EmberStatus[status]}.`, NS);
2587
+ + `with status=${enums_3.EmberStatus[status]}.`, NS);
2547
2588
  return status;
2548
2589
  }
2549
2590
  const result = (await this.oneWaitress.startWaitingFor({
@@ -2558,7 +2599,7 @@ class EmberAdapter extends __1.Adapter {
2558
2599
  inputClusters: result.inClusterList,
2559
2600
  outputClusters: result.outClusterList,
2560
2601
  });
2561
- return enums_2.EmberStatus.SUCCESS;
2602
+ return enums_3.EmberStatus.SUCCESS;
2562
2603
  }, reject);
2563
2604
  });
2564
2605
  }
@@ -2572,9 +2613,9 @@ class EmberAdapter extends __1.Adapter {
2572
2613
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2573
2614
  const [status, apsFrame, messageTag] = (await this.emberBindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.UNICAST_BINDING, destinationAddressOrGroup, null, // doesn't matter
2574
2615
  destinationEndpoint, DEFAULT_APS_OPTIONS));
2575
- if (status !== enums_2.EmberStatus.SUCCESS) {
2616
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2576
2617
  logger_1.logger.error(`[ZDO] Failed bind request for "${destinationNetworkAddress}" destination "${destinationAddressOrGroup}" `
2577
- + `endpoint "${destinationEndpoint}" with status=${enums_2.EmberStatus[status]}.`, NS);
2618
+ + `endpoint "${destinationEndpoint}" with status=${enums_3.EmberStatus[status]}.`, NS);
2578
2619
  return status;
2579
2620
  }
2580
2621
  await this.oneWaitress.startWaitingFor({
@@ -2583,7 +2624,7 @@ class EmberAdapter extends __1.Adapter {
2583
2624
  responseClusterId: zdo_1.BIND_RESPONSE,
2584
2625
  }, DEFAULT_ZDO_REQUEST_TIMEOUT);
2585
2626
  resolve();
2586
- return enums_2.EmberStatus.SUCCESS;
2627
+ return enums_3.EmberStatus.SUCCESS;
2587
2628
  }, reject);
2588
2629
  });
2589
2630
  }
@@ -2596,9 +2637,9 @@ class EmberAdapter extends __1.Adapter {
2596
2637
  const [status, apsFrame, messageTag] = (await this.emberBindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.MULTICAST_BINDING, null, // doesn't matter
2597
2638
  destinationAddressOrGroup, destinationEndpoint, // doesn't matter
2598
2639
  DEFAULT_APS_OPTIONS));
2599
- if (status !== enums_2.EmberStatus.SUCCESS) {
2640
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2600
2641
  logger_1.logger.error(`[ZDO] Failed bind request for "${destinationNetworkAddress}" group "${destinationAddressOrGroup}" `
2601
- + `with status=${enums_2.EmberStatus[status]}.`, NS);
2642
+ + `with status=${enums_3.EmberStatus[status]}.`, NS);
2602
2643
  return status;
2603
2644
  }
2604
2645
  await this.oneWaitress.startWaitingFor({
@@ -2607,7 +2648,7 @@ class EmberAdapter extends __1.Adapter {
2607
2648
  responseClusterId: zdo_1.BIND_RESPONSE,
2608
2649
  }, DEFAULT_ZDO_REQUEST_TIMEOUT);
2609
2650
  resolve();
2610
- return enums_2.EmberStatus.SUCCESS;
2651
+ return enums_3.EmberStatus.SUCCESS;
2611
2652
  }, reject);
2612
2653
  });
2613
2654
  }
@@ -2622,9 +2663,9 @@ class EmberAdapter extends __1.Adapter {
2622
2663
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2623
2664
  const [status, apsFrame, messageTag] = (await this.emberUnbindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.UNICAST_BINDING, destinationAddressOrGroup, null, // doesn't matter
2624
2665
  destinationEndpoint, DEFAULT_APS_OPTIONS));
2625
- if (status !== enums_2.EmberStatus.SUCCESS) {
2666
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2626
2667
  logger_1.logger.error(`[ZDO] Failed unbind request for "${destinationNetworkAddress}" destination "${destinationAddressOrGroup}" `
2627
- + `endpoint "${destinationEndpoint}" with status=${enums_2.EmberStatus[status]}.`, NS);
2668
+ + `endpoint "${destinationEndpoint}" with status=${enums_3.EmberStatus[status]}.`, NS);
2628
2669
  return status;
2629
2670
  }
2630
2671
  await this.oneWaitress.startWaitingFor({
@@ -2633,7 +2674,7 @@ class EmberAdapter extends __1.Adapter {
2633
2674
  responseClusterId: zdo_1.UNBIND_RESPONSE,
2634
2675
  }, DEFAULT_ZDO_REQUEST_TIMEOUT);
2635
2676
  resolve();
2636
- return enums_2.EmberStatus.SUCCESS;
2677
+ return enums_3.EmberStatus.SUCCESS;
2637
2678
  }, reject);
2638
2679
  });
2639
2680
  }
@@ -2646,9 +2687,9 @@ class EmberAdapter extends __1.Adapter {
2646
2687
  const [status, apsFrame, messageTag] = (await this.emberUnbindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.MULTICAST_BINDING, null, // doesn't matter
2647
2688
  destinationAddressOrGroup, destinationEndpoint, // doesn't matter
2648
2689
  DEFAULT_APS_OPTIONS));
2649
- if (status !== enums_2.EmberStatus.SUCCESS) {
2690
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2650
2691
  logger_1.logger.error(`[ZDO] Failed unbind request for "${destinationNetworkAddress}" group "${destinationAddressOrGroup}" `
2651
- + `with status=${enums_2.EmberStatus[status]}.`, NS);
2692
+ + `with status=${enums_3.EmberStatus[status]}.`, NS);
2652
2693
  return status;
2653
2694
  }
2654
2695
  await this.oneWaitress.startWaitingFor({
@@ -2657,7 +2698,7 @@ class EmberAdapter extends __1.Adapter {
2657
2698
  responseClusterId: zdo_1.UNBIND_RESPONSE,
2658
2699
  }, DEFAULT_ZDO_REQUEST_TIMEOUT);
2659
2700
  resolve();
2660
- return enums_2.EmberStatus.SUCCESS;
2701
+ return enums_3.EmberStatus.SUCCESS;
2661
2702
  }, reject);
2662
2703
  });
2663
2704
  }
@@ -2668,10 +2709,10 @@ class EmberAdapter extends __1.Adapter {
2668
2709
  this.requestQueue.enqueue(async () => {
2669
2710
  this.checkInterpanLock();
2670
2711
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2671
- const [status, apsFrame, messageTag] = (await this.emberLeaveRequest(networkAddress, ieeeAddr, enums_2.EmberLeaveRequestFlags.WITHOUT_REJOIN, DEFAULT_APS_OPTIONS));
2672
- if (status !== enums_2.EmberStatus.SUCCESS) {
2712
+ const [status, apsFrame, messageTag] = (await this.emberLeaveRequest(networkAddress, ieeeAddr, enums_3.EmberLeaveRequestFlags.WITHOUT_REJOIN, DEFAULT_APS_OPTIONS));
2713
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2673
2714
  logger_1.logger.error(`[ZDO] Failed remove device request for "${networkAddress}" target "${ieeeAddr}" `
2674
- + `with status=${enums_2.EmberStatus[status]}.`, NS);
2715
+ + `with status=${enums_3.EmberStatus[status]}.`, NS);
2675
2716
  return status;
2676
2717
  }
2677
2718
  await this.oneWaitress.startWaitingFor({
@@ -2680,7 +2721,7 @@ class EmberAdapter extends __1.Adapter {
2680
2721
  responseClusterId: zdo_1.LEAVE_RESPONSE,
2681
2722
  }, DEFAULT_ZDO_REQUEST_TIMEOUT);
2682
2723
  resolve();
2683
- return enums_2.EmberStatus.SUCCESS;
2724
+ return enums_3.EmberStatus.SUCCESS;
2684
2725
  }, reject);
2685
2726
  });
2686
2727
  }
@@ -2708,24 +2749,24 @@ class EmberAdapter extends __1.Adapter {
2708
2749
  };
2709
2750
  // don't RETRY if no response expected
2710
2751
  if (commandResponseId == null) {
2711
- apsFrame.options &= ~enums_2.EmberApsOption.RETRY;
2752
+ apsFrame.options &= ~enums_3.EmberApsOption.RETRY;
2712
2753
  }
2713
2754
  const data = zclFrame.toBuffer();
2714
2755
  return new Promise((resolve, reject) => {
2715
2756
  this.requestQueue.enqueue(async () => {
2716
2757
  this.checkInterpanLock();
2717
2758
  if (CHECK_APS_PAYLOAD_LENGTH) {
2718
- const maxPayloadLength = (await this.maximumApsPayloadLength(enums_2.EmberOutgoingMessageType.DIRECT, networkAddress, apsFrame));
2759
+ const maxPayloadLength = (await this.maximumApsPayloadLength(enums_3.EmberOutgoingMessageType.DIRECT, networkAddress, apsFrame));
2719
2760
  if (data.length > maxPayloadLength) {
2720
- return enums_2.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
2761
+ return enums_3.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
2721
2762
  }
2722
2763
  }
2723
2764
  logger_1.logger.debug(`~~~> [ZCL to=${networkAddress} apsFrame=${JSON.stringify(apsFrame)} header=${JSON.stringify(zclFrame.header)}]`, NS);
2724
2765
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2725
- const [status, messageTag] = (await this.ezsp.send(enums_2.EmberOutgoingMessageType.DIRECT, networkAddress, apsFrame, data, 0, // alias
2766
+ const [status, messageTag] = (await this.ezsp.send(enums_3.EmberOutgoingMessageType.DIRECT, networkAddress, apsFrame, data, 0, // alias
2726
2767
  0));
2727
- if (status !== enums_2.EmberStatus.SUCCESS) {
2728
- logger_1.logger.error(`~x~> [ZCL to=${networkAddress}] Failed to send request with status=${enums_2.EmberStatus[status]}.`, NS);
2768
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2769
+ logger_1.logger.error(`~x~> [ZCL to=${networkAddress}] Failed to send request with status=${enums_3.EmberStatus[status]}.`, NS);
2729
2770
  return status; // let queue handle retry based on status
2730
2771
  }
2731
2772
  if (commandResponseId != null) {
@@ -2740,7 +2781,7 @@ class EmberAdapter extends __1.Adapter {
2740
2781
  }
2741
2782
  else {
2742
2783
  resolve(null); // don't expect a response
2743
- return enums_2.EmberStatus.SUCCESS;
2784
+ return enums_3.EmberStatus.SUCCESS;
2744
2785
  }
2745
2786
  }, reject);
2746
2787
  });
@@ -2763,23 +2804,23 @@ class EmberAdapter extends __1.Adapter {
2763
2804
  this.requestQueue.enqueue(async () => {
2764
2805
  this.checkInterpanLock();
2765
2806
  if (CHECK_APS_PAYLOAD_LENGTH) {
2766
- const maxPayloadLength = (await this.maximumApsPayloadLength(enums_2.EmberOutgoingMessageType.MULTICAST, groupID, apsFrame));
2807
+ const maxPayloadLength = (await this.maximumApsPayloadLength(enums_3.EmberOutgoingMessageType.MULTICAST, groupID, apsFrame));
2767
2808
  if (data.length > maxPayloadLength) {
2768
- return enums_2.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
2809
+ return enums_3.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
2769
2810
  }
2770
2811
  }
2771
2812
  logger_1.logger.debug(`~~~> [ZCL GROUP apsFrame=${JSON.stringify(apsFrame)} header=${JSON.stringify(zclFrame.header)}]`, NS);
2772
2813
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2773
- const [status, messageTag] = (await this.ezsp.send(enums_2.EmberOutgoingMessageType.MULTICAST, apsFrame.groupId, // not used for MC
2814
+ const [status, messageTag] = (await this.ezsp.send(enums_3.EmberOutgoingMessageType.MULTICAST, apsFrame.groupId, // not used for MC
2774
2815
  apsFrame, data, 0, // alias
2775
2816
  0));
2776
- if (status !== enums_2.EmberStatus.SUCCESS) {
2777
- logger_1.logger.error(`~x~> [ZCL GROUP] Failed to send with status=${enums_2.EmberStatus[status]}.`, NS);
2817
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2818
+ logger_1.logger.error(`~x~> [ZCL GROUP] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
2778
2819
  return status; // let queue handle retry based on status
2779
2820
  }
2780
2821
  // NOTE: since ezspMessageSentHandler could take a while here, we don't block, it'll just be logged if the delivery failed
2781
2822
  resolve();
2782
- return enums_2.EmberStatus.SUCCESS;
2823
+ return enums_3.EmberStatus.SUCCESS;
2783
2824
  }, reject);
2784
2825
  });
2785
2826
  }
@@ -2801,22 +2842,22 @@ class EmberAdapter extends __1.Adapter {
2801
2842
  this.requestQueue.enqueue(async () => {
2802
2843
  this.checkInterpanLock();
2803
2844
  if (CHECK_APS_PAYLOAD_LENGTH) {
2804
- const maxPayloadLength = (await this.maximumApsPayloadLength(enums_2.EmberOutgoingMessageType.BROADCAST, destination, apsFrame));
2845
+ const maxPayloadLength = (await this.maximumApsPayloadLength(enums_3.EmberOutgoingMessageType.BROADCAST, destination, apsFrame));
2805
2846
  if (data.length > maxPayloadLength) {
2806
- return enums_2.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
2847
+ return enums_3.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
2807
2848
  }
2808
2849
  }
2809
2850
  logger_1.logger.debug(`~~~> [ZCL BROADCAST apsFrame=${JSON.stringify(apsFrame)} header=${JSON.stringify(zclFrame.header)}]`, NS);
2810
2851
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2811
- const [status, messageTag] = (await this.ezsp.send(enums_2.EmberOutgoingMessageType.BROADCAST, destination, apsFrame, data, 0, // alias
2852
+ const [status, messageTag] = (await this.ezsp.send(enums_3.EmberOutgoingMessageType.BROADCAST, destination, apsFrame, data, 0, // alias
2812
2853
  0));
2813
- if (status !== enums_2.EmberStatus.SUCCESS) {
2814
- logger_1.logger.error(`~x~> [ZCL BROADCAST] Failed to send with status=${enums_2.EmberStatus[status]}.`, NS);
2854
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2855
+ logger_1.logger.error(`~x~> [ZCL BROADCAST] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
2815
2856
  return status; // let queue handle retry based on status
2816
2857
  }
2817
2858
  // NOTE: since ezspMessageSentHandler could take a while here, we don't block, it'll just be logged if the delivery failed
2818
2859
  resolve();
2819
- return enums_2.EmberStatus.SUCCESS;
2860
+ return enums_3.EmberStatus.SUCCESS;
2820
2861
  }, reject);
2821
2862
  });
2822
2863
  }
@@ -2833,9 +2874,9 @@ class EmberAdapter extends __1.Adapter {
2833
2874
  this.requestQueue.enqueue(async () => {
2834
2875
  this.interpanLock = true;
2835
2876
  const status = (await this.ezsp.ezspSetLogicalAndRadioChannel(channel));
2836
- if (status !== enums_2.EmberStatus.SUCCESS) {
2877
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2837
2878
  this.interpanLock = false; // XXX: ok?
2838
- logger_1.logger.error(`Failed to set InterPAN channel to ${channel} with status=${enums_2.EmberStatus[status]}.`, NS);
2879
+ logger_1.logger.error(`Failed to set InterPAN channel to ${channel} with status=${enums_3.EmberStatus[status]}.`, NS);
2839
2880
  return status;
2840
2881
  }
2841
2882
  resolve();
@@ -2853,18 +2894,18 @@ class EmberAdapter extends __1.Adapter {
2853
2894
  const sourceEui64 = (await this.emberGetEui64());
2854
2895
  msgBuffalo.writeUInt16((consts_2.LONG_DEST_FRAME_CONTROL | consts_2.MAC_ACK_REQUIRED)); // macFrameControl
2855
2896
  msgBuffalo.writeUInt8(0); // sequence Skip Sequence number, stack sets the sequence number.
2856
- msgBuffalo.writeUInt16(consts_2.INVALID_PAN_ID); // destPanId
2897
+ msgBuffalo.writeUInt16(ZSpec.INVALID_PAN_ID); // destPanId
2857
2898
  msgBuffalo.writeIeeeAddr(ieeeAddress); // destAddress (longAddress)
2858
2899
  msgBuffalo.writeUInt16(sourcePanId); // sourcePanId
2859
2900
  msgBuffalo.writeIeeeAddr(sourceEui64); // sourceAddress
2860
2901
  msgBuffalo.writeUInt16(consts_2.STUB_NWK_FRAME_CONTROL); // nwkFrameControl
2861
- msgBuffalo.writeUInt8((enums_2.EmberInterpanMessageType.UNICAST | consts_2.INTERPAN_APS_FRAME_TYPE)); // apsFrameControl
2902
+ msgBuffalo.writeUInt8((enums_3.EmberInterpanMessageType.UNICAST | consts_2.INTERPAN_APS_FRAME_TYPE)); // apsFrameControl
2862
2903
  msgBuffalo.writeUInt16(zclFrame.cluster.ID);
2863
- msgBuffalo.writeUInt16(consts_2.TOUCHLINK_PROFILE_ID);
2904
+ msgBuffalo.writeUInt16(ZSpec.TOUCHLINK_PROFILE_ID);
2864
2905
  logger_1.logger.debug(`~~~> [ZCL TOUCHLINK to=${ieeeAddress} header=${JSON.stringify(zclFrame.header)}]`, NS);
2865
2906
  const status = (await this.ezsp.ezspSendRawMessage(Buffer.concat([msgBuffalo.getWritten(), zclFrame.toBuffer()])));
2866
- if (status !== enums_2.EmberStatus.SUCCESS) {
2867
- logger_1.logger.error(`~x~> [ZCL TOUCHLINK to=${ieeeAddress}] Failed to send with status=${enums_2.EmberStatus[status]}.`, NS);
2907
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2908
+ logger_1.logger.error(`~x~> [ZCL TOUCHLINK to=${ieeeAddress}] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
2868
2909
  return status;
2869
2910
  }
2870
2911
  // NOTE: can use ezspRawTransmitCompleteHandler if needed here
@@ -2881,12 +2922,12 @@ class EmberAdapter extends __1.Adapter {
2881
2922
  }
2882
2923
  // just for waitress
2883
2924
  const apsFrame = {
2884
- profileId: consts_2.TOUCHLINK_PROFILE_ID,
2925
+ profileId: ZSpec.TOUCHLINK_PROFILE_ID,
2885
2926
  clusterId: zclFrame.cluster.ID,
2886
2927
  sourceEndpoint: 0,
2887
2928
  destinationEndpoint: 0,
2888
- options: enums_2.EmberApsOption.NONE,
2889
- groupId: consts_2.EMBER_SLEEPY_BROADCAST_ADDRESS,
2929
+ options: enums_3.EmberApsOption.NONE,
2930
+ groupId: enums_1.BroadcastAddress.SLEEPY,
2890
2931
  sequence: 0, // set by stack
2891
2932
  };
2892
2933
  return new Promise((resolve, reject) => {
@@ -2897,19 +2938,19 @@ class EmberAdapter extends __1.Adapter {
2897
2938
  const sourceEui64 = (await this.emberGetEui64());
2898
2939
  msgBuffalo.writeUInt16(consts_2.SHORT_DEST_FRAME_CONTROL); // macFrameControl
2899
2940
  msgBuffalo.writeUInt8(0); // sequence Skip Sequence number, stack sets the sequence number.
2900
- msgBuffalo.writeUInt16(consts_2.INVALID_PAN_ID); // destPanId
2941
+ msgBuffalo.writeUInt16(ZSpec.INVALID_PAN_ID); // destPanId
2901
2942
  msgBuffalo.writeUInt16(apsFrame.groupId); // destAddress (longAddress)
2902
2943
  msgBuffalo.writeUInt16(sourcePanId); // sourcePanId
2903
2944
  msgBuffalo.writeIeeeAddr(sourceEui64); // sourceAddress
2904
2945
  msgBuffalo.writeUInt16(consts_2.STUB_NWK_FRAME_CONTROL); // nwkFrameControl
2905
- msgBuffalo.writeUInt8((enums_2.EmberInterpanMessageType.BROADCAST | consts_2.INTERPAN_APS_FRAME_TYPE)); // apsFrameControl
2946
+ msgBuffalo.writeUInt8((enums_3.EmberInterpanMessageType.BROADCAST | consts_2.INTERPAN_APS_FRAME_TYPE)); // apsFrameControl
2906
2947
  msgBuffalo.writeUInt16(apsFrame.clusterId);
2907
2948
  msgBuffalo.writeUInt16(apsFrame.profileId);
2908
2949
  const data = Buffer.concat([msgBuffalo.getWritten(), zclFrame.toBuffer()]);
2909
2950
  logger_1.logger.debug(`~~~> [ZCL TOUCHLINK BROADCAST header=${JSON.stringify(zclFrame.header)}]`, NS);
2910
2951
  const status = (await this.ezsp.ezspSendRawMessage(data));
2911
- if (status !== enums_2.EmberStatus.SUCCESS) {
2912
- logger_1.logger.error(`~x~> [ZCL TOUCHLINK BROADCAST] Failed to send with status=${enums_2.EmberStatus[status]}.`, NS);
2952
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2953
+ logger_1.logger.error(`~x~> [ZCL TOUCHLINK BROADCAST] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
2913
2954
  return status;
2914
2955
  }
2915
2956
  // NOTE: can use ezspRawTransmitCompleteHandler if needed here
@@ -2920,7 +2961,7 @@ class EmberAdapter extends __1.Adapter {
2920
2961
  commandIdentifier: command.response,
2921
2962
  }, timeout || DEFAULT_ZCL_REQUEST_TIMEOUT * 2)); // XXX: touchlink timeout?
2922
2963
  resolve(result);
2923
- return enums_2.EmberStatus.SUCCESS;
2964
+ return enums_3.EmberStatus.SUCCESS;
2924
2965
  }, reject);
2925
2966
  });
2926
2967
  }
@@ -2929,8 +2970,8 @@ class EmberAdapter extends __1.Adapter {
2929
2970
  return new Promise((resolve, reject) => {
2930
2971
  this.requestQueue.enqueue(async () => {
2931
2972
  const status = (await this.ezsp.ezspSetLogicalAndRadioChannel(this.networkOptions.channelList[0]));
2932
- if (status !== enums_2.EmberStatus.SUCCESS) {
2933
- logger_1.logger.error(`Failed to restore InterPAN channel to ${this.networkOptions.channelList[0]} with status=${enums_2.EmberStatus[status]}.`, NS);
2973
+ if (status !== enums_3.EmberStatus.SUCCESS) {
2974
+ logger_1.logger.error(`Failed to restore InterPAN channel to ${this.networkOptions.channelList[0]} with status=${enums_3.EmberStatus[status]}.`, NS);
2934
2975
  return status;
2935
2976
  }
2936
2977
  // let adapter settle down
@@ -2946,7 +2987,7 @@ class EmberAdapter extends __1.Adapter {
2946
2987
  if (this.interpanLock) {
2947
2988
  logger_1.logger.error(`[INTERPAN MODE] Cannot execute non-InterPAN commands.`, NS);
2948
2989
  // will be caught by request queue and rejected internally.
2949
- throw new Error(enums_2.EzspStatus[enums_2.EzspStatus.ERROR_INVALID_CALL]);
2990
+ throw new Error(enums_3.EzspStatus[enums_3.EzspStatus.ERROR_INVALID_CALL]);
2950
2991
  }
2951
2992
  }
2952
2993
  }