Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Apr 14, 2024
1 parent 53e2785 commit 5e151b7
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"start": "./node_modules/.bin/tsc -w",
"test": "jest test --silent",
"test-with-coverage": "jest test --silent --coverage --collectCoverageFrom 'src/**/*.ts'",
"test-watch": "jest test --silent --watch",
"test-watch": "jest test --watch",
"eslint": "node_modules/.bin/eslint . --ext .ts --max-warnings=0",
"docs": "typedoc --tsconfig typedoc-tsconfig.json",
"clean": "rimraf temp coverage dist",
Expand Down
26 changes: 1 addition & 25 deletions src/zcl/definition/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
/* eslint max-len: 0 */
import DataType from './dataType';
import {ParameterDefinition} from './tstype';
import {ClusterDefinition} from './tstype';
import BuffaloZclDataType from './buffaloZclDataType';
import ManufacturerCode from './manufacturerCode';

interface AttributeDefinition {
ID: number;
type: DataType;
manufacturerCode?: number;
}

interface ClusterDefinition {
ID: number;
manufacturerCode?: number;
attributes: {[s: string]: AttributeDefinition};
commands: {
[s: string]: CommandDefinition;
};
commandsResponse: {
[s: string]: CommandDefinition;
};
}

interface CommandDefinition {
ID: number;
parameters: ParameterDefinition[];
response?: number;
}

const Cluster: {
[s: string]: ClusterDefinition;
}
Expand Down
27 changes: 26 additions & 1 deletion src/zcl/definition/tstype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ interface ParameterDefinition extends TsType.Parameter {
type: DataType | BuffaloZclDataType;
}

interface AttributeDefinition {
ID: number;
type: DataType;
manufacturerCode?: number;
}

interface ClusterDefinition {
ID: number;
manufacturerCode?: number;
attributes: {[s: string]: AttributeDefinition};
commands: {
[s: string]: CommandDefinition;
};
commandsResponse: {
[s: string]: CommandDefinition;
};
}

interface CommandDefinition {
ID: number;
parameters: ParameterDefinition[];
response?: number;
}


export {
ParameterDefinition,
ParameterDefinition, ClusterDefinition, AttributeDefinition, CommandDefinition,
};
157 changes: 156 additions & 1 deletion test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as Models from "../src/models";
import * as Utils from "../src/utils";
import Bonjour, {BrowserConfig, Service} from 'bonjour-service';
import {setLogger} from "../src/utils/logger";
import {createCustomCluster} from "../src/zcl/utils";
const globalSetImmediate = setImmediate;
const flushPromises = () => new Promise(globalSetImmediate);

Expand Down Expand Up @@ -534,7 +535,9 @@ const options = {
const databaseContents = () => fs.readFileSync(options.databasePath).toString();

describe('Controller', () => {
let controller;
let controller: {
getDeviceByIeeeAddr(ieeeAddr: string): Device
};

beforeAll(async () => {
jest.useFakeTimers({doNotFake: ['setTimeout']});
Expand Down Expand Up @@ -2421,6 +2424,158 @@ describe('Controller', () => {
expect(deepClone(events.message[0])).toStrictEqual(expected);
});

it('onlythis Should allow to specific custom clusters', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
const device = controller.getDeviceByIeeeAddr('0x129');
device.customClusters.push(createCustomCluster(0, 'genBasic', null, {customAttr: {ID: 256, type: Zcl.DataType.uint8}}, {}, {}, true));
const buffer = Buffer.from([24,169,10,0,1,24,3,0,0,24,1]);
const frame = ZclFrame.fromBuffer(Zcl.Utils.getCluster("genBasic").ID, ZclHeader.fromBuffer(buffer), buffer);
jest.spyOn(ZclFrame, 'fromBuffer').mockReturnValueOnce(frame); // Mock because no Buffalo write isn't supported for this payload
await mockAdapterEvents['zclPayload']({
wasBroadcast: false,
address: 129,
clusterID: frame.cluster.ID,
data: null, // null intentionally
header: frame.header,
endpoint: 1,
linkquality: 50,
groupID: 1,
});


expect(events.message.length).toBe(1);
console.log(events.message[0].data)
// const expected = {
// "cluster": 'genBasic',
// "type":"attributeReport",
// "device":{
// "_events":{},"_eventsCount":0,
// "_lastSeen": deepClone(Date.now()),
// "_linkquality":50,
// "_skipDefaultResponse": false,
// "ID":2,
// "_ieeeAddr":"0x129",
// "_networkAddress":129,
// "_endpoints":[
// {
// "_events":{},"_eventsCount":0,
// "ID":1,
// "clusters": {
// "genBasic": {
// "attributes": {
// "65281": {
// "1": 3285,
// "10": 0,
// "100": 0,
// "3": 33,
// "4": 5032,
// "5": 43,
// "6": [
// 0,
// 327680,
// ],
// "8": 516,
// },
// "modelId": "lumi.sensor_wleak.aq1",
// },
// },
// },
// "inputClusters":[
// 0,
// 1
// ],
// "outputClusters":[
// 2
// ],
// "pendingRequests": {"ID": 1,"deviceIeeeAddress": "0x129","sendInProgress": false},
// "deviceNetworkAddress":129,
// "deviceIeeeAddress":"0x129",
// "_binds": [],
// "_configuredReportings": [],
// "meta":{},
// "deviceID":5,
// "profileID":99,
// }
// ],
// "_type":"Router",
// "_manufacturerID":1212,
// "_manufacturerName":"KoenAndCo",
// "meta": {},
// "_powerSource":"Mains (single phase)",
// "_modelID":"lumi.sensor_wleak.aq1",
// "_applicationVersion":2,
// "_stackVersion":101,
// "_zclVersion":1,
// "_hardwareVersion":3,"_events":{},"_eventsCount":0,
// "_dateCode":"201901",
// "_pendingRequestTimeout":0,
// "_softwareBuildID":"1.01",
// "_interviewCompleted":true,
// "_interviewing":false,
// },
// "endpoint":{
// "_events":{},"_eventsCount":0,
// "ID":1,
// "deviceID": 5,
// "inputClusters":[0, 1],
// "outputClusters":[2],
// "pendingRequests": {"ID": 1,"deviceIeeeAddress": "0x129","sendInProgress": false},
// "deviceNetworkAddress":129,
// "deviceIeeeAddress":"0x129",
// "_binds": [],
// "_configuredReportings": [],
// "profileID": 99,
// "meta":{},
// "clusters": {
// "genBasic": {
// "attributes": {
// "65281": {
// "1": 3285,
// "10": 0,
// "100": 0,
// "3": 33,
// "4": 5032,
// "5": 43,
// "6": [
// 0,
// 327680,
// ],
// "8": 516,
// },
// "modelId": "lumi.sensor_wleak.aq1",
// },
// },
// },
// },
// "data":{ '65281':{
// '1': 3285,
// '3': 33,
// '4': 5032,
// '5': 43,
// '6': [ 0, 327680 ],
// '8': 516,
// '10': 0,
// '100': 0 },
// modelId: 'lumi.sensor_wleak.aq1'
// },
// "linkquality":50,
// "groupID":1,
// "meta": {
// "zclTransactionSequenceNumber": 3,
// "manufacturerCode": 4447,
// "frameControl": {
// "reservedBits": 0,
// "direction": 1,
// "disableDefaultResponse": true,
// "frameType": 0,
// "manufacturerSpecific": true,
// },
// },
// };
// expect(deepClone(events.message[0])).toStrictEqual(expected);
});

it('Should roll-over transaction ID', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
Expand Down

0 comments on commit 5e151b7

Please sign in to comment.