Skip to content

Commit 142c350

Browse files
committed
fix: implement attr/param meta checking
1 parent 1480861 commit 142c350

File tree

12 files changed

+742
-456
lines changed

12 files changed

+742
-456
lines changed

src/controller/helpers/zclFrameConverter.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ function attributeKeyValue<Cl extends number | string, Custom extends TCustomClu
2626

2727
// TODO: remove this type once Zcl.Frame is typed
2828
for (const item of frame.payload as TFoundation["report" | "write" | "readRsp"]) {
29-
payload[cluster.getAttribute(item.attrId)?.name ?? item.attrId] = item.attrData;
29+
const attribute = cluster.getAttribute(item.attrId);
30+
31+
if (attribute) {
32+
// XXX: refs that are "after this item" won't be populated (pre-loop?)
33+
const attrData = Zcl.Utils.processAttributePostRead(attribute, item.attrData, payload);
34+
35+
payload[attribute.name] = attrData;
36+
} else {
37+
payload[item.attrId] = item.attrData;
38+
}
3039
}
3140

3241
return payload as ClusterOrRawWriteAttributes<Cl, Custom>;
@@ -38,7 +47,9 @@ function attributeList(frame: Zcl.Frame, deviceManufacturerID: number | undefine
3847

3948
// TODO: remove this type once Zcl.Frame is typed
4049
for (const item of frame.payload as TFoundation["read"]) {
41-
payload.push(cluster.getAttribute(item.attrId)?.name ?? item.attrId);
50+
const attribute = cluster.getAttribute(item.attrId);
51+
52+
payload.push(attribute?.name ?? item.attrId);
4253
}
4354

4455
return payload;

src/controller/model/endpoint.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ export class Endpoint extends ZigbeeEntity {
393393
const cluster = this.getCluster(clusterKey, undefined, options?.manufacturerCode);
394394
const payload: TFoundation["report"] = [];
395395

396+
// TODO: handle `attr.reportRequired !== true`
397+
396398
for (const nameOrID in attributes) {
397399
const attribute = cluster.getAttribute(nameOrID);
398400

@@ -429,7 +431,11 @@ export class Endpoint extends ZigbeeEntity {
429431
const attribute = cluster.getAttribute(nameOrID);
430432

431433
if (attribute) {
432-
payload.push({attrId: attribute.ID, attrData: attributes[nameOrID], dataType: attribute.type});
434+
// TODO: refs are not processed (pre-loop?)
435+
// TODO: handle `attr.writeOptional !== true`
436+
const attrData = Zcl.Utils.processAttributeWrite(attribute, attributes[nameOrID], attributes);
437+
438+
payload.push({attrId: attribute.ID, attrData, dataType: attribute.type});
433439
} else if (!Number.isNaN(Number(nameOrID))) {
434440
const value = attributes[nameOrID];
435441

@@ -498,13 +504,17 @@ export class Endpoint extends ZigbeeEntity {
498504
);
499505
const payload: TFoundation["read"] = [];
500506

507+
// TODO: handle `attr.required !== true` => should not throw
508+
501509
for (const attribute of attributes) {
502510
if (typeof attribute === "number") {
503511
payload.push({attrId: attribute});
504512
} else {
505513
const attr = cluster.getAttribute(attribute);
506514

507515
if (attr) {
516+
// TODO: force to also read *Ref if attribute has any and not already present in array for PostRead refs?
517+
Zcl.Utils.processAttributePreRead(attr);
508518
payload.push({attrId: attr.ID});
509519
} else {
510520
logger.warning(`Ignoring unknown attribute ${attribute} in cluster ${cluster.name}`, NS);

src/controller/model/group.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ export class Group extends ZigbeeEntity {
271271
const attribute = cluster.getAttribute(nameOrID);
272272

273273
if (attribute) {
274-
payload.push({attrId: attribute.ID, attrData: attributes[nameOrID], dataType: attribute.type});
274+
// TODO: refs are not processed (pre-loop?)
275+
const attrData = Zcl.Utils.processAttributeWrite(attribute, attributes[nameOrID], attributes);
276+
277+
payload.push({attrId: attribute.ID, attrData, dataType: attribute.type});
275278
} else if (!Number.isNaN(Number(nameOrID))) {
276279
const value = attributes[nameOrID];
277280

@@ -320,13 +323,16 @@ export class Group extends ZigbeeEntity {
320323
const optionsWithDefaults = this.getOptionsWithDefaults(options, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
321324
const payload: TFoundation["read"] = [];
322325

326+
// TODO: handle `attr.required !== true` => should not throw
327+
323328
for (const attribute of attributes) {
324329
if (typeof attribute === "number") {
325330
payload.push({attrId: attribute});
326331
} else {
327332
const attr = cluster.getAttribute(attribute);
328333

329334
if (attr) {
335+
Zcl.Utils.processAttributePreRead(attr);
330336
payload.push({attrId: attr.ID});
331337
} else {
332338
logger.warning(`Ignoring unknown attribute ${attribute} in cluster ${cluster.name}`, NS);

0 commit comments

Comments
 (0)