Skip to content

Commit

Permalink
fix: AttributeReport: Erroneous attribute names
Browse files Browse the repository at this point in the history
Reparse cluster attributes names using the target device's manufacturer ID,
as certain devices fail to set the manufacturerSpecific and customerCode
data in the ZCL Frame header.
  • Loading branch information
FabianMangold committed Oct 26, 2023
1 parent d12e037 commit 5aedb3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,13 @@ class Controller extends events.EventEmitter {
if (frame.isGlobal()) {
if (frame.isCommand('report')) {
type = 'attributeReport';
data = ZclFrameConverter.attributeKeyValue(dataPayload.frame);
// Certain devices (e.g. Legrand/4129) fail to set the manufacturerSpecific flag and
// manufacturerCode in the header, despite using specific attributes.
// This leads to incorrect reported attribute names.
// Reparse the payload and resolve the attributes using the target device's manufacturer ID.
data = meta.manufacturerCode ?
ZclFrameConverter.attributeKeyValue(dataPayload.frame):
ZclFrameConverter.attributeKeyValue(dataPayload.frame, device.manufacturerID);
} else if (frame.isCommand('read')) {
type = 'read';
data = ZclFrameConverter.attributeList(dataPayload.frame);
Expand Down
15 changes: 11 additions & 4 deletions src/controller/helpers/zclFrameConverter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import {ZclFrame} from '../../zcl';
import {ZclFrame, Utils as ZclUtils} from '../../zcl';
import Debug from "debug";

interface KeyValue {[s: string]: number | string}

function attributeKeyValue(frame: ZclFrame): KeyValue {
function attributeKeyValue(frame: ZclFrame, manufacturerID?: number): KeyValue {
const payload: KeyValue = {};
let cluster = frame.Cluster;

if (manufacturerID) {
Debug.log(`Attempting to resolve manufacturer specific (${manufacturerID}) cluster attributes.`);
cluster = ZclUtils.getCluster(frame.Cluster.ID, manufacturerID);
}

for (const item of frame.Payload) {
try {
const attribute = frame.Cluster.getAttribute(item.attrId);
const attribute = cluster.getAttribute(item.attrId);
payload[attribute.name] = item.attrData;
Debug.log(`Attr: ${item.attrId} (${attribute.name}) -> ${item.attrData}}`);
} catch (error) {
payload[item.attrId] = item.attrData;
}
}

return payload;
}

Expand Down

0 comments on commit 5aedb3f

Please sign in to comment.