Skip to content

Commit

Permalink
fix: Fix some manufacturer specific attribute names being wrong (#797)
Browse files Browse the repository at this point in the history
* fix: Restrict attribute name remapping (PR#787)

* Restrict to Legrand only following regressions

* fix(ignore): Updated tests

* Restrict attribute name remapping to Legrand only

* fix(ignore): Remove unnecessary integer check

* fix(refactor): Use ManufacturerCode enum instead of a hardcoded value

* Update zclFrameConverter.ts

---------

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
  • Loading branch information
FabianMangold and Koenkk committed Nov 13, 2023
1 parent 5c0666a commit 285e9ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/controller/helpers/zclFrameConverter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {ZclFrame, Utils as ZclUtils} from '../../zcl';
import {Cluster} from '../../zcl/tstype';
import ManufacturerCode from '../../zcl/definition/manufacturerCode';

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

// Certain devices (e.g. Legrand/4129) fail to set the manufacturerSpecific flag and
// Legrand devices (e.g. 4129) fail to set the manufacturerSpecific flag and
// manufacturerCode in the frame header, despite using specific attributes.
// This leads to incorrect reported attribute names.
// Remap the attributes using the target device's manufacturer ID
// if the header is lacking the information.
function getCluster(frame: ZclFrame, deviceManufacturerID: number): Cluster {
let cluster = frame.Cluster;

if (!frame?.Header?.manufacturerCode && frame?.Cluster && Number.isInteger(deviceManufacturerID)) {
if (!frame?.Header?.manufacturerCode && frame?.Cluster && deviceManufacturerID == ManufacturerCode.LegrandNetatmo) {
cluster = ZclUtils.getCluster(frame.Cluster.ID, deviceManufacturerID);
}
return cluster;
Expand Down Expand Up @@ -50,4 +50,4 @@ function attributeList(frame: ZclFrame, deviceManufacturerID: number): Array<str
export {
attributeKeyValue,
attributeList,
};
};
4 changes: 2 additions & 2 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5033,8 +5033,8 @@ describe('Controller', () => {
expect(events.message[0].data).not.toMatchObject({calibrationMode:4});
});

// ZCLFrame without manufacturer specific flag set or manufacturer code set, to specific device
it('Should resolve manufacturer specific cluster attribute names on generic ZCL frames: specific target device', async () => {
// ZCLFrame without manufacturer specific flag set or manufacturer code set, to specific device (Legrand only)
it('Should resolve manufacturer specific cluster attribute names on generic ZCL frames: Legrand target device', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 177, ieeeAddr: '0x177'});
await mockAdapterEvents['zclData']({
Expand Down

0 comments on commit 285e9ac

Please sign in to comment.