zigbee-herdsman 4.5.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/dist/controller/helpers/zclFrameConverter.d.ts.map +1 -1
  4. package/dist/controller/helpers/zclFrameConverter.js +2 -14
  5. package/dist/controller/helpers/zclFrameConverter.js.map +1 -1
  6. package/dist/controller/model/device.js +3 -5
  7. package/dist/controller/model/device.js.map +1 -1
  8. package/dist/controller/model/endpoint.d.ts +1 -1
  9. package/dist/controller/model/endpoint.d.ts.map +1 -1
  10. package/dist/controller/model/endpoint.js +67 -43
  11. package/dist/controller/model/endpoint.js.map +1 -1
  12. package/dist/controller/model/group.d.ts.map +1 -1
  13. package/dist/controller/model/group.js +28 -17
  14. package/dist/controller/model/group.js.map +1 -1
  15. package/dist/zspec/zcl/buffaloZcl.d.ts.map +1 -1
  16. package/dist/zspec/zcl/buffaloZcl.js +5 -5
  17. package/dist/zspec/zcl/buffaloZcl.js.map +1 -1
  18. package/dist/zspec/zcl/definition/tstype.d.ts +1 -2
  19. package/dist/zspec/zcl/definition/tstype.d.ts.map +1 -1
  20. package/dist/zspec/zcl/utils.d.ts.map +1 -1
  21. package/dist/zspec/zcl/utils.js +8 -30
  22. package/dist/zspec/zcl/utils.js.map +1 -1
  23. package/dist/zspec/zcl/zclFrame.d.ts +1 -1
  24. package/dist/zspec/zcl/zclFrame.d.ts.map +1 -1
  25. package/dist/zspec/zcl/zclFrame.js +8 -6
  26. package/dist/zspec/zcl/zclFrame.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/controller/helpers/zclFrameConverter.ts +4 -12
  29. package/src/controller/model/device.ts +5 -5
  30. package/src/controller/model/endpoint.ts +86 -49
  31. package/src/controller/model/group.ts +33 -18
  32. package/src/zspec/zcl/buffaloZcl.ts +6 -4
  33. package/src/zspec/zcl/definition/tstype.ts +1 -2
  34. package/src/zspec/zcl/utils.ts +8 -35
  35. package/src/zspec/zcl/zclFrame.ts +10 -8
  36. package/test/controller.test.ts +352 -1360
  37. package/test/requests.bench.ts +5 -0
  38. package/test/zcl.test.ts +11 -15
  39. package/test/zspec/zcl/frame.test.ts +25 -25
  40. package/test/zspec/zcl/utils.test.ts +6 -14
@@ -548,13 +548,15 @@ export class BuffaloZcl extends Buffalo {
548
548
  while (this.position - start < options.payload.payloadSize) {
549
549
  const attributeID = this.readUInt16();
550
550
  const type = this.readUInt8();
551
+ /* v8 ignore next */
552
+ let attribute: string | undefined | number = cluster.getAttribute(attributeID)?.name;
551
553
 
552
- let attribute: number | string = attributeID;
553
- try {
554
- attribute = cluster.getAttribute(attributeID).name;
555
- } catch {
554
+ // number type is only used when going into this if
555
+ if (!attribute) {
556
556
  // this is spammy because of the many manufacturer-specific attributes not currently used
557
557
  logger.debug(`Unknown attribute ${attributeID} in cluster ${cluster.name}`, NS);
558
+
559
+ attribute = attributeID;
558
560
  }
559
561
 
560
562
  frame.attributes[attribute] = this.read(type, options);
@@ -86,8 +86,7 @@ export interface Cluster {
86
86
  commandsResponse: {
87
87
  [s: string]: Command;
88
88
  };
89
- getAttribute: (key: number | string) => Attribute;
90
- hasAttribute: (key: number | string) => boolean;
89
+ getAttribute: (key: number | string) => Attribute | undefined;
91
90
  getCommand: (key: number | string) => Command;
92
91
  getCommandResponse: (key: number | string) => Command;
93
92
  }
@@ -187,7 +187,7 @@ function createCluster(name: string, cluster: ClusterDefinition, manufacturerCod
187
187
  const commands: Record<string, Command> = cloneClusterEntriesWithName(cluster.commands);
188
188
  const commandsResponse: Record<string, Command> = cloneClusterEntriesWithName(cluster.commandsResponse);
189
189
 
190
- const getAttributeInternal = (key: number | string): Attribute | undefined => {
190
+ const getAttribute = (key: number | string): Attribute | undefined => {
191
191
  if (typeof key === "number") {
192
192
  let partialMatchAttr: Attribute | undefined;
193
193
 
@@ -208,29 +208,7 @@ function createCluster(name: string, cluster: ClusterDefinition, manufacturerCod
208
208
  return partialMatchAttr;
209
209
  }
210
210
 
211
- for (const attrKey in attributes) {
212
- const attr = attributes[attrKey];
213
-
214
- if (attr.name === key) {
215
- return attr;
216
- }
217
- }
218
-
219
- return undefined;
220
- };
221
-
222
- const getAttribute = (key: number | string): Attribute => {
223
- const result = getAttributeInternal(key);
224
- if (!result) {
225
- throw new Error(`Cluster '${name}' has no attribute '${key}'`);
226
- }
227
-
228
- return result;
229
- };
230
-
231
- const hasAttribute = (key: number | string): boolean => {
232
- const result = getAttributeInternal(key);
233
- return !!result;
211
+ return attributes[key];
234
212
  };
235
213
 
236
214
  const getCommand = (key: number | string): Command => {
@@ -243,12 +221,10 @@ function createCluster(name: string, cluster: ClusterDefinition, manufacturerCod
243
221
  }
244
222
  }
245
223
  } else {
246
- for (const cmdKey in commands) {
247
- const cmd = commands[cmdKey];
224
+ const cmd = commands[key];
248
225
 
249
- if (cmd.name === key) {
250
- return cmd;
251
- }
226
+ if (cmd) {
227
+ return cmd;
252
228
  }
253
229
  }
254
230
 
@@ -265,12 +241,10 @@ function createCluster(name: string, cluster: ClusterDefinition, manufacturerCod
265
241
  }
266
242
  }
267
243
  } else {
268
- for (const cmdKey in commandsResponse) {
269
- const cmd = commandsResponse[cmdKey];
244
+ const cmd = commandsResponse[key];
270
245
 
271
- if (cmd.name === key) {
272
- return cmd;
273
- }
246
+ if (cmd) {
247
+ return cmd;
274
248
  }
275
249
  }
276
250
 
@@ -285,7 +259,6 @@ function createCluster(name: string, cluster: ClusterDefinition, manufacturerCod
285
259
  commands,
286
260
  commandsResponse,
287
261
  getAttribute,
288
- hasAttribute,
289
262
  getCommand,
290
263
  getCommandResponse,
291
264
  };
@@ -45,19 +45,21 @@ export class ZclFrame {
45
45
  disableDefaultResponse: boolean,
46
46
  manufacturerCode: number | undefined,
47
47
  transactionSequenceNumber: number,
48
- commandKey: number | string,
49
- clusterKey: number | string,
48
+ commandKey: number | string | Command,
49
+ clusterKey: number | string | Cluster,
50
50
  payload: ZclPayload,
51
51
  customClusters: CustomClusters,
52
52
  reservedBits = 0,
53
53
  ): ZclFrame {
54
- const cluster = Utils.getCluster(clusterKey, manufacturerCode, customClusters);
54
+ const cluster = typeof clusterKey === "object" ? clusterKey : Utils.getCluster(clusterKey, manufacturerCode, customClusters);
55
55
  const command: Command =
56
- frameType === FrameType.GLOBAL
57
- ? Utils.getGlobalCommand(commandKey)
58
- : direction === Direction.CLIENT_TO_SERVER
59
- ? cluster.getCommand(commandKey)
60
- : cluster.getCommandResponse(commandKey);
56
+ typeof commandKey === "object"
57
+ ? commandKey
58
+ : frameType === FrameType.GLOBAL
59
+ ? Utils.getGlobalCommand(commandKey)
60
+ : direction === Direction.CLIENT_TO_SERVER
61
+ ? cluster.getCommand(commandKey)
62
+ : cluster.getCommandResponse(commandKey);
61
63
 
62
64
  const header = new ZclHeader(
63
65
  {reservedBits, frameType, direction, disableDefaultResponse, manufacturerSpecific: manufacturerCode != null},