Skip to content

Commit

Permalink
Support Livolo malformed messages. #127
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Jan 17, 2020
1 parent 773e20d commit dec27ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/zcl/buffaloZcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ class BuffaloZcl extends Buffalo {
} else if (type === 'USE_DATA_TYPE') {
return this.writeUseDataType(value, options);
} else {
// In case the type is undefined, write it as a buffer to easily allow for custom types
// e.g. for https://github.com/Koenkk/zigbee-herdsman/issues/127
type = type === undefined ? 'BUFFER' : type;

// TODO: remove uppercase once dataTypes are snake case
return super.write(type.toUpperCase(), value, options);
}
Expand Down
17 changes: 17 additions & 0 deletions test/zcl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,23 @@ describe('Zcl', () => {
expect(frame.toBuffer()).toStrictEqual(expected);
});

it('ZclFrame to buffer write Livolo malformed', () => {
// Created as example for https://github.com/Koenkk/zigbee-herdsman/issues/127
const expectedOn = Buffer.from([0x1c ,0xd2 ,0x1a ,0xe9 ,0x02 ,0x01 ,0x00 ,0x01 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00]);
const payloadOn = [{attrId: 1, attrData: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]), dataType: 1}];
const frameOn = Zcl.ZclFrame.create(
FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, 0x1ad2, 233, 'write', 0, payloadOn
);
expect(frameOn.toBuffer()).toStrictEqual(expectedOn);

const expectedOff = Buffer.from([0x1c ,0xd2 ,0x1a ,0xe9 ,0x02 ,0x01 ,0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00]);
const payloadOff = [{attrId: 1, attrData: Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]), dataType: 1}];
const frameOff = Zcl.ZclFrame.create(
FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, 0x1ad2, 233, 'write', 0, payloadOff
);
expect(frameOff.toBuffer()).toStrictEqual(expectedOff);
});

it('ZclFrame write request with string as bytes array', () => {
const payload = [{attrId: 0x0401, attrData: [0x07, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x14], dataType: 0x42}];
const frame = Zcl.ZclFrame.create(
Expand Down

0 comments on commit dec27ed

Please sign in to comment.