@zwave-js/cc 15.23.1 → 15.23.5

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 (31) hide show
  1. package/build/cjs/cc/NotificationCC.js +4 -0
  2. package/build/cjs/cc/NotificationCC.js.map +2 -2
  3. package/build/cjs/cc/UserCredentialCC._validateArgs.js +4 -4
  4. package/build/cjs/cc/UserCredentialCC._validateArgs.js.map +2 -2
  5. package/build/cjs/cc/UserCredentialCC.d.ts +75 -37
  6. package/build/cjs/cc/UserCredentialCC.js +212 -156
  7. package/build/cjs/cc/UserCredentialCC.js.map +3 -3
  8. package/build/cjs/cc/_CCValues.generated.d.ts +62 -6
  9. package/build/cjs/cc/_CCValues.generated.js +38 -6
  10. package/build/cjs/cc/_CCValues.generated.js.map +2 -2
  11. package/build/cjs/cc/index.d.ts +3 -3
  12. package/build/cjs/cc/index.js +6 -6
  13. package/build/cjs/cc/index.js.map +1 -1
  14. package/build/esm/cc/NotificationCC.d.ts.map +1 -1
  15. package/build/esm/cc/NotificationCC.js +6 -1
  16. package/build/esm/cc/NotificationCC.js.map +1 -1
  17. package/build/esm/cc/UserCredentialCC._validateArgs.js +4 -4
  18. package/build/esm/cc/UserCredentialCC._validateArgs.js.map +1 -1
  19. package/build/esm/cc/UserCredentialCC.d.ts +75 -37
  20. package/build/esm/cc/UserCredentialCC.d.ts.map +1 -1
  21. package/build/esm/cc/UserCredentialCC.js +247 -152
  22. package/build/esm/cc/UserCredentialCC.js.map +1 -1
  23. package/build/esm/cc/_CCValues.generated.d.ts +62 -6
  24. package/build/esm/cc/_CCValues.generated.d.ts.map +1 -1
  25. package/build/esm/cc/_CCValues.generated.js +41 -6
  26. package/build/esm/cc/_CCValues.generated.js.map +1 -1
  27. package/build/esm/cc/index.d.ts +3 -3
  28. package/build/esm/cc/index.d.ts.map +1 -1
  29. package/build/esm/cc/index.js +4 -4
  30. package/build/esm/cc/index.js.map +1 -1
  31. package/package.json +2 -2
@@ -36,6 +36,8 @@ __export(UserCredentialCC_exports, {
36
36
  UserCredentialCCAdminPinCodeSet: () => UserCredentialCCAdminPinCodeSet,
37
37
  UserCredentialCCAllUsersChecksumGet: () => UserCredentialCCAllUsersChecksumGet,
38
38
  UserCredentialCCAllUsersChecksumReport: () => UserCredentialCCAllUsersChecksumReport,
39
+ UserCredentialCCAssociationReport: () => UserCredentialCCAssociationReport,
40
+ UserCredentialCCAssociationSet: () => UserCredentialCCAssociationSet,
39
41
  UserCredentialCCCredentialCapabilitiesGet: () => UserCredentialCCCredentialCapabilitiesGet,
40
42
  UserCredentialCCCredentialCapabilitiesReport: () => UserCredentialCCCredentialCapabilitiesReport,
41
43
  UserCredentialCCCredentialChecksumGet: () => UserCredentialCCCredentialChecksumGet,
@@ -55,12 +57,11 @@ __export(UserCredentialCC_exports, {
55
57
  UserCredentialCCUserCapabilitiesReport: () => UserCredentialCCUserCapabilitiesReport,
56
58
  UserCredentialCCUserChecksumGet: () => UserCredentialCCUserChecksumGet,
57
59
  UserCredentialCCUserChecksumReport: () => UserCredentialCCUserChecksumReport,
58
- UserCredentialCCUserCredentialAssociationReport: () => UserCredentialCCUserCredentialAssociationReport,
59
- UserCredentialCCUserCredentialAssociationSet: () => UserCredentialCCUserCredentialAssociationSet,
60
60
  UserCredentialCCUserGet: () => UserCredentialCCUserGet,
61
61
  UserCredentialCCUserReport: () => UserCredentialCCUserReport,
62
62
  UserCredentialCCUserSet: () => UserCredentialCCUserSet,
63
- UserCredentialCCValues: () => import_CCValues_generated.UserCredentialCCValues
63
+ UserCredentialCCValues: () => import_CCValues_generated.UserCredentialCCValues,
64
+ normalizeCredentialData: () => normalizeCredentialData
64
65
  });
65
66
  module.exports = __toCommonJS(UserCredentialCC_exports);
66
67
  var import_tslib = require("tslib");
@@ -79,6 +80,13 @@ function credentialToLogString(credential) {
79
80
  return "*".repeat(credential.length);
80
81
  }
81
82
  __name(credentialToLogString, "credentialToLogString");
83
+ function normalizeCredentialData(credentialType, credentialData) {
84
+ if (credentialType === import_Types.UserCredentialType.PINCode || credentialType === import_Types.UserCredentialType.Password) {
85
+ return credentialData.toString("utf8");
86
+ }
87
+ return credentialData;
88
+ }
89
+ __name(normalizeCredentialData, "normalizeCredentialData");
82
90
  let UserCredentialCCAPI = (() => {
83
91
  let _classDecorators = [(0, import_CommandClassDecorators.API)(import_core.CommandClasses["User Credential"])];
84
92
  let _classDescriptor;
@@ -264,6 +272,10 @@ let UserCredentialCCAPI = (() => {
264
272
  return response?.keyLockerCapabilities;
265
273
  }
266
274
  // User Management
275
+ /**
276
+ * Applications should not use this method directly. Prefer the
277
+ * `endpoint.accessControl` API for managing users.
278
+ */
267
279
  async setUser(options) {
268
280
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.UserSet);
269
281
  const cc = new UserCredentialCCUserSet({
@@ -273,6 +285,10 @@ let UserCredentialCCAPI = (() => {
273
285
  });
274
286
  return this.host.sendCommand(cc, this.commandOptions);
275
287
  }
288
+ /**
289
+ * Applications should not use this method directly. Prefer the
290
+ * `endpoint.accessControl` API for querying users.
291
+ */
276
292
  async getUser(userId) {
277
293
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.UserGet);
278
294
  const cc = new UserCredentialCCUserGet({
@@ -280,23 +296,13 @@ let UserCredentialCCAPI = (() => {
280
296
  endpointIndex: this.endpoint.index,
281
297
  userId
282
298
  });
283
- const response = await this.host.sendCommand(cc, this.commandOptions);
284
- if (response) {
285
- return (0, import_shared.pick)(response, [
286
- "nextUserId",
287
- "modifierType",
288
- "modifierNodeId",
289
- "userId",
290
- "userType",
291
- "active",
292
- "credentialRule",
293
- "expiringTimeoutMinutes",
294
- "nameEncoding",
295
- "userName"
296
- ]);
297
- }
299
+ return this.host.sendCommand(cc, this.commandOptions);
298
300
  }
299
301
  // Credential Management
302
+ /**
303
+ * Applications should not use this method directly. Prefer the
304
+ * `endpoint.accessControl` API for managing credentials.
305
+ */
300
306
  async setCredential(options) {
301
307
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.CredentialSet);
302
308
  const cc = new UserCredentialCCCredentialSet({
@@ -306,6 +312,10 @@ let UserCredentialCCAPI = (() => {
306
312
  });
307
313
  return this.host.sendCommand(cc, this.commandOptions);
308
314
  }
315
+ /**
316
+ * Applications should not use this method directly. Prefer the
317
+ * `endpoint.accessControl` API for querying credentials.
318
+ */
309
319
  async getCredential(userId, credentialType, credentialSlot) {
310
320
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.CredentialGet);
311
321
  const cc = new UserCredentialCCCredentialGet({
@@ -315,24 +325,7 @@ let UserCredentialCCAPI = (() => {
315
325
  credentialType,
316
326
  credentialSlot
317
327
  });
318
- const response = await this.host.sendCommand(cc, this.commandOptions);
319
- if (response) {
320
- return (0, import_shared.pick)(response, [
321
- // UserId, credential type and slot can be zero in the
322
- // request to return the first credential, so we cannot
323
- // simply omit them here
324
- "userId",
325
- "credentialType",
326
- "credentialSlot",
327
- "credentialReadBack",
328
- "credentialLength",
329
- "credentialData",
330
- "modifierType",
331
- "modifierNodeId",
332
- "nextCredentialType",
333
- "nextCredentialSlot"
334
- ]);
335
- }
328
+ return this.host.sendCommand(cc, this.commandOptions);
336
329
  }
337
330
  async startCredentialLearn(options) {
338
331
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.CredentialLearnStart);
@@ -355,9 +348,13 @@ let UserCredentialCCAPI = (() => {
355
348
  });
356
349
  return this.host.sendCommand(cc, this.commandOptions);
357
350
  }
351
+ /**
352
+ * Applications should not use this method directly. Prefer the
353
+ * `endpoint.accessControl` API for reassigning credentials between users.
354
+ */
358
355
  async setUserCredentialAssociation(options) {
359
356
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.UserCredentialAssociationSet);
360
- const cc = new UserCredentialCCUserCredentialAssociationSet({
357
+ const cc = new UserCredentialCCAssociationSet({
361
358
  nodeId: this.endpoint.nodeId,
362
359
  endpointIndex: this.endpoint.index,
363
360
  ...options
@@ -501,7 +498,7 @@ let UserCredentialCCAPI = (() => {
501
498
  }
502
499
  async sendUserCredentialAssociationReport(options) {
503
500
  this.assertSupportsCommand(import_Types.UserCredentialCommand, import_Types.UserCredentialCommand.UserCredentialAssociationReport);
504
- const cc = new UserCredentialCCUserCredentialAssociationReport({
501
+ const cc = new UserCredentialCCAssociationReport({
505
502
  nodeId: this.endpoint.nodeId,
506
503
  endpointIndex: this.endpoint.index,
507
504
  ...options
@@ -686,7 +683,7 @@ let UserCredentialCC = (() => {
686
683
  }
687
684
  }
688
685
  previousUserId = currentUserId;
689
- nextUserId = user.nextUserId;
686
+ nextUserId = user.nextUserId ?? 0;
690
687
  } while (nextUserId > 0);
691
688
  }
692
689
  if (allUsersChecksum != void 0) {
@@ -726,14 +723,17 @@ let UserCredentialCC = (() => {
726
723
  this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.userModifierNodeId(userId));
727
724
  this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.userChecksum(userId));
728
725
  const valueDB = this.getValueDB(ctx);
729
- const credentialValues = valueDB.findValues((vid) => (import_CCValues_generated.UserCredentialCCValues.credential.is(vid) || import_CCValues_generated.UserCredentialCCValues.credentialModifierType.is(vid) || import_CCValues_generated.UserCredentialCCValues.credentialModifierNodeId.is(vid)) && vid.propertyKey >> 24 === userId);
730
- for (const { commandClass: commandClass2, endpoint, property, propertyKey } of credentialValues) {
731
- valueDB.removeValue({
732
- commandClass: commandClass2,
733
- endpoint,
734
- property,
735
- propertyKey
736
- });
726
+ const credentialOwners = valueDB.findValues((vid) => import_CCValues_generated.UserCredentialCCValues.credentialOwner.is(vid) && vid.endpoint === this.endpointIndex);
727
+ for (const { endpoint, propertyKey, value } of credentialOwners) {
728
+ if (value !== userId)
729
+ continue;
730
+ const key = propertyKey;
731
+ const credentialType = key >>> 16;
732
+ const credentialSlot = key & 65535;
733
+ valueDB.removeValue(import_CCValues_generated.UserCredentialCCValues.credential(credentialType, credentialSlot).endpoint(endpoint));
734
+ valueDB.removeValue(import_CCValues_generated.UserCredentialCCValues.credentialOwner(credentialType, credentialSlot).endpoint(endpoint));
735
+ valueDB.removeValue(import_CCValues_generated.UserCredentialCCValues.credentialModifierType(credentialType, credentialSlot).endpoint(endpoint));
736
+ valueDB.removeValue(import_CCValues_generated.UserCredentialCCValues.credentialModifierNodeId(credentialType, credentialSlot).endpoint(endpoint));
737
737
  }
738
738
  }
739
739
  async queryCredentialsForUser(ctx, api, nodeId, userId) {
@@ -748,8 +748,8 @@ let UserCredentialCC = (() => {
748
748
  const cred = await api.getCredential(userId, nextCredType, nextCredSlot);
749
749
  if (!cred?.credentialSlot)
750
750
  break;
751
- nextCredType = cred.nextCredentialType;
752
- nextCredSlot = cred.nextCredentialSlot;
751
+ nextCredType = cred.nextCredentialType ?? import_Types.UserCredentialType.None;
752
+ nextCredSlot = cred.nextCredentialSlot ?? 0;
753
753
  } while (nextCredType !== import_Types.UserCredentialType.None || nextCredSlot !== 0);
754
754
  }
755
755
  static getSupportedUsersCached(ctx, endpoint) {
@@ -1180,8 +1180,12 @@ let UserCredentialCCKeyLockerCapabilitiesGet = (() => {
1180
1180
  };
1181
1181
  return UserCredentialCCKeyLockerCapabilitiesGet2 = _classThis;
1182
1182
  })();
1183
+ function testResponseForUserCredentialUserSet(sent, received) {
1184
+ return received.reportType !== import_Types.UserCredentialUserReportType.ResponseToGet && received.userId === sent.userId;
1185
+ }
1186
+ __name(testResponseForUserCredentialUserSet, "testResponseForUserCredentialUserSet");
1183
1187
  let UserCredentialCCUserSet = (() => {
1184
- let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.UserSet), (0, import_CommandClassDecorators.useSupervision)()];
1188
+ let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.UserSet), (0, import_CommandClassDecorators.expectedCCResponse)(() => UserCredentialCCUserReport, testResponseForUserCredentialUserSet)];
1185
1189
  let _classDescriptor;
1186
1190
  let _classExtraInitializers = [];
1187
1191
  let _classThis;
@@ -1372,7 +1376,9 @@ let UserCredentialCCUserReport = (() => {
1372
1376
  constructor(options) {
1373
1377
  super(options);
1374
1378
  this.reportType = options.reportType;
1375
- this.nextUserId = options.nextUserId;
1379
+ if (options.reportType === import_Types.UserCredentialUserReportType.ResponseToGet) {
1380
+ this.nextUserId = options.nextUserId;
1381
+ }
1376
1382
  this.modifierType = options.modifierType;
1377
1383
  this.modifierNodeId = options.modifierNodeId;
1378
1384
  this.userId = options.userId;
@@ -1404,10 +1410,8 @@ let UserCredentialCCUserReport = (() => {
1404
1410
  } else {
1405
1411
  userName = raw.payload.subarray(15, 15 + nameLength).toString("ascii");
1406
1412
  }
1407
- return new this({
1413
+ const common = {
1408
1414
  nodeId: ctx.sourceNodeId,
1409
- reportType,
1410
- nextUserId,
1411
1415
  modifierType,
1412
1416
  modifierNodeId,
1413
1417
  userId,
@@ -1417,7 +1421,11 @@ let UserCredentialCCUserReport = (() => {
1417
1421
  expiringTimeoutMinutes,
1418
1422
  nameEncoding,
1419
1423
  userName
1420
- });
1424
+ };
1425
+ if (reportType === import_Types.UserCredentialUserReportType.ResponseToGet) {
1426
+ return new this({ ...common, reportType, nextUserId });
1427
+ }
1428
+ return new this({ ...common, reportType });
1421
1429
  }
1422
1430
  reportType;
1423
1431
  nextUserId;
@@ -1439,7 +1447,7 @@ let UserCredentialCCUserReport = (() => {
1439
1447
  }
1440
1448
  this.payload = import_shared.Bytes.alloc(15 + nameBuffer.length);
1441
1449
  this.payload[0] = this.reportType;
1442
- this.payload.writeUInt16BE(this.nextUserId, 1);
1450
+ this.payload.writeUInt16BE(this.nextUserId ?? 0, 1);
1443
1451
  this.payload[3] = this.modifierType;
1444
1452
  this.payload.writeUInt16BE(this.modifierNodeId, 4);
1445
1453
  this.payload.writeUInt16BE(this.userId, 6);
@@ -1459,7 +1467,7 @@ let UserCredentialCCUserReport = (() => {
1459
1467
  return false;
1460
1468
  if (this.userId === 0)
1461
1469
  return true;
1462
- if (this.reportType === import_Types.UserCredentialUserReportType.UserDeleted) {
1470
+ if (this.reportType === import_Types.UserCredentialUserReportType.UserDeleted || this.reportType === import_Types.UserCredentialUserReportType.UserModifyRejectedLocationEmpty) {
1463
1471
  const userId2 = this.userId;
1464
1472
  this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.userType(userId2));
1465
1473
  this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.userActive(userId2));
@@ -1470,7 +1478,7 @@ let UserCredentialCCUserReport = (() => {
1470
1478
  this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.userModifierNodeId(userId2));
1471
1479
  return true;
1472
1480
  }
1473
- if (this.reportType !== import_Types.UserCredentialUserReportType.ResponseToGet && this.reportType !== import_Types.UserCredentialUserReportType.UserAdded && this.reportType !== import_Types.UserCredentialUserReportType.UserModified) {
1481
+ if (this.reportType !== import_Types.UserCredentialUserReportType.ResponseToGet && this.reportType !== import_Types.UserCredentialUserReportType.UserAdded && this.reportType !== import_Types.UserCredentialUserReportType.UserModified && this.reportType !== import_Types.UserCredentialUserReportType.UserAddRejectedLocationOccupied) {
1474
1482
  return true;
1475
1483
  }
1476
1484
  const userId = this.userId;
@@ -1489,22 +1497,22 @@ let UserCredentialCCUserReport = (() => {
1489
1497
  return true;
1490
1498
  }
1491
1499
  toLogEntry(ctx) {
1492
- return {
1493
- ...super.toLogEntry(ctx),
1494
- message: {
1495
- "report type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialUserReportType, this.reportType),
1496
- "next user ID": this.nextUserId,
1497
- "modifier type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialModifierType, this.modifierType),
1498
- "modifier node id": this.modifierNodeId,
1499
- "user ID": this.userId,
1500
- "user type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialUserType, this.userType),
1501
- active: this.active,
1502
- "credential rule": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialRule, this.credentialRule),
1503
- "expiring timeout (minutes)": this.expiringTimeoutMinutes,
1504
- "name encoding": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialNameEncoding, this.nameEncoding),
1505
- "user name": this.userName
1506
- }
1500
+ const message = {
1501
+ "report type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialUserReportType, this.reportType)
1507
1502
  };
1503
+ if (this.nextUserId != void 0) {
1504
+ message["next user ID"] = this.nextUserId;
1505
+ }
1506
+ message["modifier type"] = (0, import_shared.getEnumMemberName)(import_Types.UserCredentialModifierType, this.modifierType);
1507
+ message["modifier node id"] = this.modifierNodeId;
1508
+ message["user ID"] = this.userId;
1509
+ message["user type"] = (0, import_shared.getEnumMemberName)(import_Types.UserCredentialUserType, this.userType);
1510
+ message.active = this.active;
1511
+ message["credential rule"] = (0, import_shared.getEnumMemberName)(import_Types.UserCredentialRule, this.credentialRule);
1512
+ message["expiring timeout (minutes)"] = this.expiringTimeoutMinutes;
1513
+ message["name encoding"] = (0, import_shared.getEnumMemberName)(import_Types.UserCredentialNameEncoding, this.nameEncoding);
1514
+ message["user name"] = this.userName;
1515
+ return { ...super.toLogEntry(ctx), message };
1508
1516
  }
1509
1517
  };
1510
1518
  return UserCredentialCCUserReport2 = _classThis;
@@ -1562,8 +1570,21 @@ let UserCredentialCCUserGet = (() => {
1562
1570
  };
1563
1571
  return UserCredentialCCUserGet2 = _classThis;
1564
1572
  })();
1573
+ function testResponseForUserCredentialCredentialSet(sent, received) {
1574
+ if (received.reportType === import_Types.UserCredentialCredentialReportType.ResponseToGet) {
1575
+ return false;
1576
+ }
1577
+ if (received.credentialType !== sent.credentialType) {
1578
+ return false;
1579
+ }
1580
+ if (received.reportType === import_Types.UserCredentialCredentialReportType.DuplicateCredential || received.reportType === import_Types.UserCredentialCredentialReportType.DuplicateAdminPINCode) {
1581
+ return true;
1582
+ }
1583
+ return received.credentialSlot === sent.credentialSlot;
1584
+ }
1585
+ __name(testResponseForUserCredentialCredentialSet, "testResponseForUserCredentialCredentialSet");
1565
1586
  let UserCredentialCCCredentialSet = (() => {
1566
- let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.CredentialSet), (0, import_CommandClassDecorators.useSupervision)()];
1587
+ let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.CredentialSet), (0, import_CommandClassDecorators.expectedCCResponse)(() => UserCredentialCCCredentialReport, testResponseForUserCredentialCredentialSet)];
1567
1588
  let _classDescriptor;
1568
1589
  let _classExtraInitializers = [];
1569
1590
  let _classThis;
@@ -1692,12 +1713,15 @@ let UserCredentialCCCredentialReport = (() => {
1692
1713
  this.credentialType = options.credentialType;
1693
1714
  this.credentialSlot = options.credentialSlot;
1694
1715
  this.credentialReadBack = options.credentialReadBack;
1695
- this.credentialLength = options.credentialLength;
1696
- this.credentialData = options.credentialData;
1716
+ if (options.credentialReadBack) {
1717
+ this.credentialData = options.credentialData;
1718
+ }
1697
1719
  this.modifierType = options.modifierType;
1698
1720
  this.modifierNodeId = options.modifierNodeId;
1699
- this.nextCredentialType = options.nextCredentialType;
1700
- this.nextCredentialSlot = options.nextCredentialSlot;
1721
+ if (options.reportType === import_Types.UserCredentialCredentialReportType.ResponseToGet) {
1722
+ this.nextCredentialType = options.nextCredentialType;
1723
+ this.nextCredentialSlot = options.nextCredentialSlot;
1724
+ }
1701
1725
  }
1702
1726
  static from(raw, ctx) {
1703
1727
  (0, import_core.validatePayload)(raw.payload.length >= 8);
@@ -1708,25 +1732,34 @@ let UserCredentialCCCredentialReport = (() => {
1708
1732
  const credentialReadBack = !!(raw.payload[6] & 128);
1709
1733
  const credentialLength = raw.payload[7];
1710
1734
  (0, import_core.validatePayload)(raw.payload.length >= 8 + credentialLength + 6);
1711
- const credentialData = import_shared.Bytes.from(raw.payload.subarray(8, 8 + credentialLength));
1712
- let offset = 8 + credentialLength;
1735
+ const offset = 8 + credentialLength;
1713
1736
  const modifierType = raw.payload[offset];
1714
1737
  const modifierNodeId = raw.payload.readUInt16BE(offset + 1);
1715
- const nextCredentialType = raw.payload[offset + 3];
1716
- const nextCredentialSlot = raw.payload.readUInt16BE(offset + 4);
1717
- return new this({
1738
+ const common = {
1718
1739
  nodeId: ctx.sourceNodeId,
1719
- reportType,
1720
1740
  userId,
1721
1741
  credentialType,
1722
1742
  credentialSlot,
1723
- credentialReadBack,
1724
- credentialLength,
1725
- credentialData,
1726
1743
  modifierType,
1727
- modifierNodeId,
1728
- nextCredentialType,
1729
- nextCredentialSlot
1744
+ modifierNodeId
1745
+ };
1746
+ const dataOptions = credentialReadBack ? {
1747
+ credentialReadBack: true,
1748
+ credentialData: import_shared.Bytes.from(raw.payload.subarray(8, 8 + credentialLength))
1749
+ } : { credentialReadBack: false };
1750
+ if (reportType === import_Types.UserCredentialCredentialReportType.ResponseToGet) {
1751
+ return new this({
1752
+ ...common,
1753
+ ...dataOptions,
1754
+ reportType,
1755
+ nextCredentialType: raw.payload[offset + 3],
1756
+ nextCredentialSlot: raw.payload.readUInt16BE(offset + 4)
1757
+ });
1758
+ }
1759
+ return new this({
1760
+ ...common,
1761
+ ...dataOptions,
1762
+ reportType
1730
1763
  });
1731
1764
  }
1732
1765
  reportType;
@@ -1734,28 +1767,28 @@ let UserCredentialCCCredentialReport = (() => {
1734
1767
  credentialType;
1735
1768
  credentialSlot;
1736
1769
  credentialReadBack;
1737
- credentialLength;
1738
1770
  credentialData;
1739
1771
  modifierType;
1740
1772
  modifierNodeId;
1741
1773
  nextCredentialType;
1742
1774
  nextCredentialSlot;
1743
1775
  serialize(ctx) {
1744
- this.payload = import_shared.Bytes.alloc(14 + this.credentialData.length);
1776
+ const credentialData = this.credentialData ?? new import_shared.Bytes();
1777
+ this.payload = import_shared.Bytes.alloc(14 + credentialData.length);
1745
1778
  this.payload[0] = this.reportType;
1746
1779
  this.payload.writeUInt16BE(this.userId, 1);
1747
1780
  this.payload[3] = this.credentialType;
1748
1781
  this.payload.writeUInt16BE(this.credentialSlot, 4);
1749
1782
  this.payload[6] = this.credentialReadBack ? 128 : 0;
1750
- this.payload[7] = this.credentialData.length;
1751
- if (this.credentialData.length > 0) {
1752
- this.payload.set(this.credentialData, 8);
1783
+ this.payload[7] = credentialData.length;
1784
+ if (credentialData.length > 0) {
1785
+ this.payload.set(credentialData, 8);
1753
1786
  }
1754
- let offset = 8 + this.credentialData.length;
1787
+ const offset = 8 + credentialData.length;
1755
1788
  this.payload[offset] = this.modifierType;
1756
1789
  this.payload.writeUInt16BE(this.modifierNodeId, offset + 1);
1757
- this.payload[offset + 3] = this.nextCredentialType;
1758
- this.payload.writeUInt16BE(this.nextCredentialSlot, offset + 4);
1790
+ this.payload[offset + 3] = this.nextCredentialType ?? import_Types.UserCredentialType.None;
1791
+ this.payload.writeUInt16BE(this.nextCredentialSlot ?? 0, offset + 4);
1759
1792
  return super.serialize(ctx);
1760
1793
  }
1761
1794
  persistValues(ctx) {
@@ -1764,37 +1797,46 @@ let UserCredentialCCCredentialReport = (() => {
1764
1797
  if (this.credentialType === import_Types.UserCredentialType.None || this.credentialSlot === 0) {
1765
1798
  return true;
1766
1799
  }
1767
- if (this.reportType === import_Types.UserCredentialCredentialReportType.CredentialDeleted) {
1768
- this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credential(this.userId, this.credentialType, this.credentialSlot));
1769
- this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierType(this.userId, this.credentialType, this.credentialSlot));
1770
- this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierNodeId(this.userId, this.credentialType, this.credentialSlot));
1800
+ if (this.reportType === import_Types.UserCredentialCredentialReportType.CredentialDeleted || this.reportType === import_Types.UserCredentialCredentialReportType.CredentialModifyRejectedLocationEmpty) {
1801
+ this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credential(this.credentialType, this.credentialSlot));
1802
+ this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialOwner(this.credentialType, this.credentialSlot));
1803
+ this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierType(this.credentialType, this.credentialSlot));
1804
+ this.removeValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierNodeId(this.credentialType, this.credentialSlot));
1771
1805
  return true;
1772
1806
  }
1773
- if (this.reportType !== import_Types.UserCredentialCredentialReportType.ResponseToGet && this.reportType !== import_Types.UserCredentialCredentialReportType.CredentialAdded && this.reportType !== import_Types.UserCredentialCredentialReportType.CredentialModified) {
1807
+ const isRejectionWithReadback = this.reportType === import_Types.UserCredentialCredentialReportType.CredentialAddRejectedLocationOccupied && this.credentialReadBack;
1808
+ if (this.reportType !== import_Types.UserCredentialCredentialReportType.ResponseToGet && this.reportType !== import_Types.UserCredentialCredentialReportType.CredentialAdded && this.reportType !== import_Types.UserCredentialCredentialReportType.CredentialModified && !isRejectionWithReadback) {
1774
1809
  return true;
1775
1810
  }
1776
- this.ensureMetadata(ctx, import_CCValues_generated.UserCredentialCCValues.credential(this.userId, this.credentialType, this.credentialSlot));
1777
- this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credential(this.userId, this.credentialType, this.credentialSlot), this.credentialData);
1778
- this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierType(this.userId, this.credentialType, this.credentialSlot), this.modifierType);
1779
- this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierNodeId(this.userId, this.credentialType, this.credentialSlot), this.modifierNodeId);
1811
+ if (this.credentialData != void 0) {
1812
+ this.ensureMetadata(ctx, import_CCValues_generated.UserCredentialCCValues.credential(this.credentialType, this.credentialSlot));
1813
+ this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credential(this.credentialType, this.credentialSlot), normalizeCredentialData(this.credentialType, this.credentialData));
1814
+ }
1815
+ this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialOwner(this.credentialType, this.credentialSlot), this.userId);
1816
+ this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierType(this.credentialType, this.credentialSlot), this.modifierType);
1817
+ this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialModifierNodeId(this.credentialType, this.credentialSlot), this.modifierNodeId);
1780
1818
  return true;
1781
1819
  }
1782
1820
  toLogEntry(ctx) {
1783
- return {
1784
- ...super.toLogEntry(ctx),
1785
- message: {
1786
- "report type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialCredentialReportType, this.reportType),
1787
- "user ID": this.userId,
1788
- "credential type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialType, this.credentialType),
1789
- "credential slot": this.credentialSlot,
1790
- "credential read-back": this.credentialReadBack,
1791
- "credential data": credentialToLogString(this.credentialData),
1792
- "modifier type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialModifierType, this.modifierType),
1793
- "modifier node id": this.modifierNodeId,
1794
- "next credential type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialType, this.nextCredentialType),
1795
- "next credential slot": this.nextCredentialSlot
1796
- }
1821
+ const message = {
1822
+ "report type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialCredentialReportType, this.reportType),
1823
+ "user ID": this.userId,
1824
+ "credential type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialType, this.credentialType),
1825
+ "credential slot": this.credentialSlot,
1826
+ "credential read-back": this.credentialReadBack
1797
1827
  };
1828
+ if (this.credentialData != void 0) {
1829
+ message["credential data"] = credentialToLogString(this.credentialData);
1830
+ }
1831
+ message["modifier type"] = (0, import_shared.getEnumMemberName)(import_Types.UserCredentialModifierType, this.modifierType);
1832
+ message["modifier node id"] = this.modifierNodeId;
1833
+ if (this.nextCredentialType != void 0) {
1834
+ message["next credential type"] = (0, import_shared.getEnumMemberName)(import_Types.UserCredentialType, this.nextCredentialType);
1835
+ }
1836
+ if (this.nextCredentialSlot != void 0) {
1837
+ message["next credential slot"] = this.nextCredentialSlot;
1838
+ }
1839
+ return { ...super.toLogEntry(ctx), message };
1798
1840
  }
1799
1841
  };
1800
1842
  return UserCredentialCCCredentialReport2 = _classThis;
@@ -2033,15 +2075,15 @@ let UserCredentialCCCredentialLearnReport = (() => {
2033
2075
  };
2034
2076
  return UserCredentialCCCredentialLearnReport2 = _classThis;
2035
2077
  })();
2036
- let UserCredentialCCUserCredentialAssociationSet = (() => {
2037
- let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.UserCredentialAssociationSet), (0, import_CommandClassDecorators.useSupervision)()];
2078
+ let UserCredentialCCAssociationReport = (() => {
2079
+ let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.UserCredentialAssociationReport)];
2038
2080
  let _classDescriptor;
2039
2081
  let _classExtraInitializers = [];
2040
2082
  let _classThis;
2041
2083
  let _classSuper = UserCredentialCC;
2042
- var UserCredentialCCUserCredentialAssociationSet2 = class extends _classSuper {
2084
+ var UserCredentialCCAssociationReport2 = class extends _classSuper {
2043
2085
  static {
2044
- __name(this, "UserCredentialCCUserCredentialAssociationSet");
2086
+ __name(this, "UserCredentialCCAssociationReport");
2045
2087
  }
2046
2088
  static {
2047
2089
  _classThis = this;
@@ -2049,7 +2091,7 @@ let UserCredentialCCUserCredentialAssociationSet = (() => {
2049
2091
  static {
2050
2092
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
2051
2093
  (0, import_tslib.__esDecorate)(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
2052
- UserCredentialCCUserCredentialAssociationSet2 = _classThis = _classDescriptor.value;
2094
+ UserCredentialCCAssociationReport2 = _classThis = _classDescriptor.value;
2053
2095
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
2054
2096
  (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
2055
2097
  }
@@ -2058,51 +2100,70 @@ let UserCredentialCCUserCredentialAssociationSet = (() => {
2058
2100
  this.credentialType = options.credentialType;
2059
2101
  this.credentialSlot = options.credentialSlot;
2060
2102
  this.destinationUserId = options.destinationUserId;
2103
+ this.status = options.status;
2061
2104
  }
2062
- credentialType;
2063
- credentialSlot;
2064
- destinationUserId;
2065
2105
  static from(raw, ctx) {
2066
- (0, import_core.validatePayload)(raw.payload.length >= 5);
2106
+ (0, import_core.validatePayload)(raw.payload.length >= 6);
2067
2107
  const credentialType = raw.payload[0];
2068
2108
  const credentialSlot = raw.payload.readUInt16BE(1);
2069
2109
  const destinationUserId = raw.payload.readUInt16BE(3);
2110
+ const status = raw.payload[5];
2070
2111
  return new this({
2071
2112
  nodeId: ctx.sourceNodeId,
2072
2113
  credentialType,
2073
2114
  credentialSlot,
2074
- destinationUserId
2115
+ destinationUserId,
2116
+ status
2075
2117
  });
2076
2118
  }
2119
+ credentialType;
2120
+ credentialSlot;
2121
+ destinationUserId;
2122
+ status;
2077
2123
  serialize(ctx) {
2078
- this.payload = import_shared.Bytes.alloc(5);
2124
+ this.payload = import_shared.Bytes.alloc(6);
2079
2125
  this.payload[0] = this.credentialType;
2080
2126
  this.payload.writeUInt16BE(this.credentialSlot, 1);
2081
2127
  this.payload.writeUInt16BE(this.destinationUserId, 3);
2128
+ this.payload[5] = this.status;
2082
2129
  return super.serialize(ctx);
2083
2130
  }
2131
+ persistValues(ctx) {
2132
+ if (!super.persistValues(ctx))
2133
+ return false;
2134
+ if (this.status !== 0 || this.credentialType === import_Types.UserCredentialType.None || this.credentialSlot === 0) {
2135
+ return true;
2136
+ }
2137
+ this.setValue(ctx, import_CCValues_generated.UserCredentialCCValues.credentialOwner(this.credentialType, this.credentialSlot), this.destinationUserId);
2138
+ return true;
2139
+ }
2084
2140
  toLogEntry(ctx) {
2085
2141
  return {
2086
2142
  ...super.toLogEntry(ctx),
2087
2143
  message: {
2088
2144
  "credential type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialType, this.credentialType),
2089
2145
  "credential slot": this.credentialSlot,
2090
- "destination user ID": this.destinationUserId
2146
+ "destination user ID": this.destinationUserId,
2147
+ status: this.status
2091
2148
  }
2092
2149
  };
2093
2150
  }
2094
2151
  };
2095
- return UserCredentialCCUserCredentialAssociationSet2 = _classThis;
2152
+ return UserCredentialCCAssociationReport2 = _classThis;
2096
2153
  })();
2097
- let UserCredentialCCUserCredentialAssociationReport = (() => {
2098
- let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.UserCredentialAssociationReport)];
2154
+ function testResponseForUserCredentialAssociationSet(sent, received) {
2155
+ return sent.credentialType === received.credentialType && sent.credentialSlot === received.credentialSlot;
2156
+ }
2157
+ __name(testResponseForUserCredentialAssociationSet, "testResponseForUserCredentialAssociationSet");
2158
+ let UserCredentialCCAssociationSet = (() => {
2159
+ let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.UserCredentialAssociationSet), (0, import_CommandClassDecorators.expectedCCResponse)(UserCredentialCCAssociationReport, testResponseForUserCredentialAssociationSet)];
2099
2160
  let _classDescriptor;
2100
2161
  let _classExtraInitializers = [];
2101
2162
  let _classThis;
2102
2163
  let _classSuper = UserCredentialCC;
2103
- var UserCredentialCCUserCredentialAssociationReport2 = class extends _classSuper {
2164
+ var UserCredentialCCAssociationSet2 = class extends _classSuper {
2104
2165
  static {
2105
- __name(this, "UserCredentialCCUserCredentialAssociationReport");
2166
+ __name(this, "UserCredentialCCAssociationSet");
2106
2167
  }
2107
2168
  static {
2108
2169
  _classThis = this;
@@ -2110,7 +2171,7 @@ let UserCredentialCCUserCredentialAssociationReport = (() => {
2110
2171
  static {
2111
2172
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
2112
2173
  (0, import_tslib.__esDecorate)(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
2113
- UserCredentialCCUserCredentialAssociationReport2 = _classThis = _classDescriptor.value;
2174
+ UserCredentialCCAssociationSet2 = _classThis = _classDescriptor.value;
2114
2175
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
2115
2176
  (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
2116
2177
  }
@@ -2119,32 +2180,27 @@ let UserCredentialCCUserCredentialAssociationReport = (() => {
2119
2180
  this.credentialType = options.credentialType;
2120
2181
  this.credentialSlot = options.credentialSlot;
2121
2182
  this.destinationUserId = options.destinationUserId;
2122
- this.status = options.status;
2123
2183
  }
2184
+ credentialType;
2185
+ credentialSlot;
2186
+ destinationUserId;
2124
2187
  static from(raw, ctx) {
2125
- (0, import_core.validatePayload)(raw.payload.length >= 6);
2188
+ (0, import_core.validatePayload)(raw.payload.length >= 5);
2126
2189
  const credentialType = raw.payload[0];
2127
2190
  const credentialSlot = raw.payload.readUInt16BE(1);
2128
2191
  const destinationUserId = raw.payload.readUInt16BE(3);
2129
- const status = raw.payload[5];
2130
2192
  return new this({
2131
2193
  nodeId: ctx.sourceNodeId,
2132
2194
  credentialType,
2133
2195
  credentialSlot,
2134
- destinationUserId,
2135
- status
2196
+ destinationUserId
2136
2197
  });
2137
2198
  }
2138
- credentialType;
2139
- credentialSlot;
2140
- destinationUserId;
2141
- status;
2142
2199
  serialize(ctx) {
2143
- this.payload = import_shared.Bytes.alloc(6);
2200
+ this.payload = import_shared.Bytes.alloc(5);
2144
2201
  this.payload[0] = this.credentialType;
2145
2202
  this.payload.writeUInt16BE(this.credentialSlot, 1);
2146
2203
  this.payload.writeUInt16BE(this.destinationUserId, 3);
2147
- this.payload[5] = this.status;
2148
2204
  return super.serialize(ctx);
2149
2205
  }
2150
2206
  toLogEntry(ctx) {
@@ -2153,13 +2209,12 @@ let UserCredentialCCUserCredentialAssociationReport = (() => {
2153
2209
  message: {
2154
2210
  "credential type": (0, import_shared.getEnumMemberName)(import_Types.UserCredentialType, this.credentialType),
2155
2211
  "credential slot": this.credentialSlot,
2156
- "destination user ID": this.destinationUserId,
2157
- status: this.status
2212
+ "destination user ID": this.destinationUserId
2158
2213
  }
2159
2214
  };
2160
2215
  }
2161
2216
  };
2162
- return UserCredentialCCUserCredentialAssociationReport2 = _classThis;
2217
+ return UserCredentialCCAssociationSet2 = _classThis;
2163
2218
  })();
2164
2219
  let UserCredentialCCAllUsersChecksumReport = (() => {
2165
2220
  let _classDecorators = [(0, import_CommandClassDecorators.CCCommand)(import_Types.UserCredentialCommand.AllUsersChecksumReport)];
@@ -2826,6 +2881,8 @@ let UserCredentialCCKeyLockerEntryGet = (() => {
2826
2881
  UserCredentialCCAdminPinCodeSet,
2827
2882
  UserCredentialCCAllUsersChecksumGet,
2828
2883
  UserCredentialCCAllUsersChecksumReport,
2884
+ UserCredentialCCAssociationReport,
2885
+ UserCredentialCCAssociationSet,
2829
2886
  UserCredentialCCCredentialCapabilitiesGet,
2830
2887
  UserCredentialCCCredentialCapabilitiesReport,
2831
2888
  UserCredentialCCCredentialChecksumGet,
@@ -2845,11 +2902,10 @@ let UserCredentialCCKeyLockerEntryGet = (() => {
2845
2902
  UserCredentialCCUserCapabilitiesReport,
2846
2903
  UserCredentialCCUserChecksumGet,
2847
2904
  UserCredentialCCUserChecksumReport,
2848
- UserCredentialCCUserCredentialAssociationReport,
2849
- UserCredentialCCUserCredentialAssociationSet,
2850
2905
  UserCredentialCCUserGet,
2851
2906
  UserCredentialCCUserReport,
2852
2907
  UserCredentialCCUserSet,
2853
- UserCredentialCCValues
2908
+ UserCredentialCCValues,
2909
+ normalizeCredentialData
2854
2910
  });
2855
2911
  //# sourceMappingURL=UserCredentialCC.js.map