Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Fix always use number for reportableChange #1190

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controller/model/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ConfigureReportingItem {
attribute: string | number | {ID: number; type: number};
minimumReportInterval: number;
maximumReportInterval: number;
reportableChange: number | [number, number];
reportableChange: number;
}

interface Options {
Expand Down
45 changes: 6 additions & 39 deletions src/zspec/zcl/buffaloZcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,6 @@ interface MiboxerZone {
export class BuffaloZcl extends Buffalo {
// TODO: remove read/write int "SB" versions in favor of plain numbers, implemented in buffalo.ts

private writeUInt40SB(value: number[]): void {
this.writeUInt32(value[1]);
this.writeUInt8(value[0]);
}

private readUInt40SB(): [number, number] {
const lsb = this.readUInt32();
const msb = this.readUInt8();
return [msb, lsb];
}

private writeUInt48SB(value: number[]): void {
this.writeUInt32(value[1]);
this.writeUInt16(value[0]);
}

private readUInt48SB(): [number, number] {
const lsb = this.readUInt32();
const msb = this.readUInt16();
return [msb, lsb];
}

private writeUInt56SB(value: number[]): void {
// XXX: [uint32, uint32] param not following read return pattern [uint32, uint16, uint8]
const temp = Buffer.alloc(8);
Expand Down Expand Up @@ -177,17 +155,6 @@ export class BuffaloZcl extends Buffalo {
this.writeUInt32(msb);
}

private writeInt40SB(value: number[]): void {
this.writeInt32(value[1]);
this.writeInt8(value[0]);
}

private readInt40SB(): [number, number] {
const lsb = this.readInt32();
const msb = this.readInt8();
return [msb, lsb];
}

private writeInt56SB(value: number[]): void {
const temp = Buffer.alloc(8);
temp.writeInt32LE(value[1], 0);
Expand Down Expand Up @@ -773,12 +740,12 @@ export class BuffaloZcl extends Buffalo {
case DataType.DATA40:
case DataType.BITMAP40:
case DataType.UINT40: {
return this.writeUInt40SB(value);
return this.writeUInt40(value);
}
case DataType.DATA48:
case DataType.BITMAP48:
case DataType.UINT48: {
return this.writeUInt48SB(value);
return this.writeUInt48(value);
}
case DataType.DATA56:
case DataType.BITMAP56:
Expand All @@ -803,7 +770,7 @@ export class BuffaloZcl extends Buffalo {
return this.writeInt32(value);
}
case DataType.INT40: {
return this.writeInt40SB(value);
return this.writeInt40(value);
}
case DataType.INT48: {
return this.writeInt48(value);
Expand Down Expand Up @@ -957,12 +924,12 @@ export class BuffaloZcl extends Buffalo {
case DataType.DATA40:
case DataType.BITMAP40:
case DataType.UINT40: {
return this.readUInt40SB();
return this.readUInt40();
}
case DataType.DATA48:
case DataType.BITMAP48:
case DataType.UINT48: {
return this.readUInt48SB();
return this.readUInt48();
}
case DataType.DATA56:
case DataType.BITMAP56:
Expand All @@ -987,7 +954,7 @@ export class BuffaloZcl extends Buffalo {
return this.readInt32();
}
case DataType.INT40: {
return this.readInt40SB();
return this.readInt40();
}
case DataType.INT48: {
return this.readInt48();
Expand Down
6 changes: 3 additions & 3 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,7 @@ describe('Controller', () => {
'3': 33,
'4': 5032,
'5': 43,
'6': [0, 327680],
'6': 327680,
'8': 516,
},
modelId: 'lumi.sensor_wleak.aq1',
Expand Down Expand Up @@ -4080,7 +4080,7 @@ describe('Controller', () => {
'3': 33,
'4': 5032,
'5': 43,
'6': [0, 327680],
'6': 327680,
'8': 516,
},
modelId: 'lumi.sensor_wleak.aq1',
Expand All @@ -4094,7 +4094,7 @@ describe('Controller', () => {
'3': 33,
'4': 5032,
'5': 43,
'6': [0, 327680],
'6': 327680,
'8': 516,
'10': 0,
'100': 0,
Expand Down
30 changes: 15 additions & 15 deletions test/zcl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ describe('Zcl', () => {

const payload = [
{attrId: 5, dataType: 66, attrData: 'lumi.sensor_wleak.aq1'},
{attrId: 65281, dataType: 66, attrData: {'1': 3285, '3': 33, '4': 5032, '5': 43, '6': [0, 327680], '8': 516, '10': 0, '100': 0}},
{attrId: 65281, dataType: 66, attrData: {'1': 3285, '3': 33, '4': 5032, '5': 43, '6': 327680, '8': 516, '10': 0, '100': 0}},
];

expect(frame.header).toStrictEqual(header);
Expand Down Expand Up @@ -537,15 +537,15 @@ describe('Zcl', () => {
{elmType: 16, elmVal: 1},
{elmType: 33, elmVal: 3022},
{elmType: 33, elmVal: 17320},
{elmType: 36, elmVal: [0, 1]},
{elmType: 36, elmVal: 1},
{elmType: 33, elmVal: 560},
{elmType: 32, elmVal: 86},
],
attrData: [
{elmType: 16, elmVal: 1},
{elmType: 33, elmVal: 3022},
{elmType: 33, elmVal: 17320},
{elmType: 36, elmVal: [0, 1]},
{elmType: 36, elmVal: 1},
{elmType: 33, elmVal: 560},
{elmType: 32, elmVal: 86},
],
Expand Down Expand Up @@ -1560,15 +1560,15 @@ describe('Zcl', () => {
const buffalo = new BuffaloZcl(buffer);
const value = buffalo.read(type, {});
expect(buffalo.getPosition()).toBe(5);
expect(value).toStrictEqual([6, 84149505]);
expect(value).toStrictEqual(25853953281);
});

it.each([DataType.UINT48, DataType.DATA48, DataType.BITMAP48])('BuffaloZcl read uint48, data48, bitmap48', (type) => {
const buffer = Buffer.from([1, 5, 4, 5, 6, 7]);
const buffalo = new BuffaloZcl(buffer);
const value = buffalo.read(type, {});
expect(buffalo.getPosition()).toBe(6);
expect(value).toStrictEqual([1798, 84149505]);
expect(value).toStrictEqual(7722435347713);
});

it.each([DataType.UINT56, DataType.DATA56, DataType.BITMAP56])('BuffaloZcl read uint56, data56, bitmap56', (type) => {
Expand All @@ -1588,11 +1588,11 @@ describe('Zcl', () => {
});

it('BuffaloZcl read int40', () => {
const buffer = Buffer.from([1, 5, 4, 5, 6, 7]);
const buffer = Buffer.from([254, 255, 255, 255, 127]);
const buffalo = new BuffaloZcl(buffer);
const value = buffalo.read(DataType.INT40, {});
expect(buffalo.getPosition()).toBe(5);
expect(value).toStrictEqual([6, 84149505]);
expect(value).toStrictEqual(549755813886);
});

it('BuffaloZcl read int56', () => {
Expand Down Expand Up @@ -1701,20 +1701,20 @@ describe('Zcl', () => {
expect(buffer).toStrictEqual(expected);
});

it.each([DataType.UINT40, DataType.DATA40, DataType.BITMAP56])('BuffaloZcl write uint40, data40, bitmap40', (type) => {
const payload = [30, 40];
it.each([DataType.UINT40, DataType.DATA40, DataType.BITMAP40])('BuffaloZcl write uint40, data40, bitmap40', (type) => {
const payload = 1099511627773;
const buffer = Buffer.alloc(5);
const expected = Buffer.from([40, 0, 0, 0, 30]);
const expected = Buffer.from([253, 255, 255, 255, 255]);
const buffalo = new BuffaloZcl(buffer);
buffalo.write(type, payload, {});
expect(buffalo.getPosition()).toBe(5);
expect(buffer).toStrictEqual(expected);
});

it.each([DataType.UINT48, DataType.DATA48, DataType.BITMAP56])('BuffaloZcl write uint48, data48, bitmap48', (type) => {
const payload = [1798, 84149505];
it.each([DataType.UINT48, DataType.DATA48, DataType.BITMAP48])('BuffaloZcl write uint48, data48, bitmap48', (type) => {
const payload = 281474976710653;
const buffer = Buffer.alloc(6);
const expected = Buffer.from([1, 5, 4, 5, 6, 7]);
const expected = Buffer.from([253, 255, 255, 255, 255, 255]);
const buffalo = new BuffaloZcl(buffer);
buffalo.write(type, payload, {});
expect(buffalo.getPosition()).toBe(6);
Expand Down Expand Up @@ -1742,9 +1742,9 @@ describe('Zcl', () => {
});

it('BuffaloZcl write int40', () => {
const payload = [30, 40];
const payload = 549755813886;
const buffer = Buffer.alloc(5);
const expected = Buffer.from([40, 0, 0, 0, 30]);
const expected = Buffer.from([254, 255, 255, 255, 127]);
const buffalo = new BuffaloZcl(buffer);
buffalo.write(DataType.INT40, payload, {});
expect(buffalo.getPosition()).toBe(5);
Expand Down
13 changes: 1 addition & 12 deletions test/zspec/zcl/buffalo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,6 @@ describe('ZCL Buffalo', () => {
});

it.each([
[
'uint40-like',
{value: [250, 25635482], types: [Zcl.DataType.DATA40, Zcl.DataType.BITMAP40, Zcl.DataType.UINT40]},
{position: 5, written: [...uint32To8Array(25635482), 250]},
],
[
'uint48-like',
{value: [65530, 65894582], types: [Zcl.DataType.DATA48, Zcl.DataType.BITMAP48, Zcl.DataType.UINT48]},
{position: 6, written: [...uint32To8Array(65894582), ...uint16To8Array(65530)]},
],
['int40-like', {value: [120, -2147483640], types: [Zcl.DataType.INT40]}, {position: 5, written: [...uint32To8Array(-2147483640), 120]}],
[
'int64-like',
{value: [-2147483640, 2147483640], types: [Zcl.DataType.INT64]},
Expand Down Expand Up @@ -373,7 +362,7 @@ describe('ZCL Buffalo', () => {
});

it('[workaround] Reads char str as Mi struct for Xiaomi attridId=65281', () => {
const expectedValue = {'1': 3285, '3': 33, '4': 5032, '5': 43, '6': [0, 327680], '8': 516, '10': 0, '100': 0};
const expectedValue = {'1': 3285, '3': 33, '4': 5032, '5': 43, '6': 327680, '8': 516, '10': 0, '100': 0};
const buffer = Buffer.from([
34,
1,
Expand Down
6 changes: 3 additions & 3 deletions test/zspec/zcl/frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ describe('ZCL Frame', () => {
it('[workaround] Reads Foundation char str as Mi struct for Xiaomi attridId=65281', () => {
const expected = [
{attrId: 5, dataType: Zcl.DataType.CHAR_STR, attrData: 'lumi.sensor_wleak.aq1'},
{attrId: 65281, dataType: Zcl.DataType.CHAR_STR, attrData: {1: 3285, 3: 33, 4: 5032, 5: 43, 6: [0, 327680], 8: 516, 10: 0, 100: 0}},
{attrId: 65281, dataType: Zcl.DataType.CHAR_STR, attrData: {1: 3285, 3: 33, 4: 5032, 5: 43, 6: 327680, 8: 516, 10: 0, 100: 0}},
];
const buffer = Buffer.from([
28,
Expand Down Expand Up @@ -779,15 +779,15 @@ describe('ZCL Frame', () => {
{elmType: Zcl.DataType.BOOLEAN, elmVal: 1},
{elmType: Zcl.DataType.UINT16, elmVal: 3022},
{elmType: Zcl.DataType.UINT16, elmVal: 17320},
{elmType: Zcl.DataType.UINT40, elmVal: [0, 1]},
{elmType: Zcl.DataType.UINT40, elmVal: 1},
{elmType: Zcl.DataType.UINT16, elmVal: 560},
{elmType: Zcl.DataType.UINT8, elmVal: 86},
],
attrData: [
{elmType: Zcl.DataType.BOOLEAN, elmVal: 1},
{elmType: Zcl.DataType.UINT16, elmVal: 3022},
{elmType: Zcl.DataType.UINT16, elmVal: 17320},
{elmType: Zcl.DataType.UINT40, elmVal: [0, 1]},
{elmType: Zcl.DataType.UINT40, elmVal: 1},
{elmType: Zcl.DataType.UINT16, elmVal: 560},
{elmType: Zcl.DataType.UINT8, elmVal: 86},
],
Expand Down