Skip to content

Commit

Permalink
Emit write events from devices. Koenkk/zigbee-herdsman-converters#281
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Dec 11, 2019
1 parent 958889f commit eaba706
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ class Controller extends events.EventEmitter {
} else if (frame.isCommand('read')) {
type = 'read';
data = ZclFrameConverter.attributeList(dataPayload.frame);
} else if (frame.isCommand('write')) {
type = 'write';
data = ZclFrameConverter.attributeKeyValue(dataPayload.frame);
} else {
/* istanbul ignore else */
if (frame.isCommand('readRsp')) {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const CommandsLookup: {[s: string]: MessagePayloadType} = {

type MessagePayloadType =
// Global
'attributeReport' | 'readResponse' | 'raw' | 'read' |
'attributeReport' | 'readResponse' | 'raw' | 'read' | 'write' |
// Specific
'commandOn' | 'commandOffWithEffect' | 'commandStep' | 'commandStop' | 'commandHueNotification' |
'commandOff' | 'commandStepColorTemp' | 'commandMoveWithOnOff' | 'commandMove' | 'commandMoveHue' |
Expand Down
91 changes: 91 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2103,4 +2103,95 @@ describe('Controller', () => {
expect(events.message.length).toBe(1);
expect(deepClone(events.message[0])).toStrictEqual(expected);
});

it('Emit write from device', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
await mockAdapterEvents['zclData']({
address: 129,
// Attrid 9999 does not exist in ZCL
frame: ZclFrame.create(0, 0, true, null, 40, 2, 10, [{attrId:16389, dataType:32, attrData:3}]),
endpoint: 1,
linkquality: 19,
groupID: 10,
});

const expected = {
"type":"write",
"device":{
"ID":2,
"_applicationVersion":2,
"_dateCode":"201901",
"_endpoints":[
{
"deviceID":5,
"inputClusters":[
1
],
"outputClusters":[
2
],
"profileID":99,
"ID":1,
"clusters":{

},
"deviceIeeeAddress":"0x129",
"deviceNetworkAddress":129,
"_binds":[

]
}
],
"_hardwareVersion":3,
"ieeeAddr":"0x129",
"_interviewCompleted":true,
"_interviewing":false,
"_lastSeen":"1970-01-01T00:00:00.150Z",
"_manufacturerID":1212,
"_manufacturerName":"KoenAndCo",
"_modelID":"myModelID",
"_networkAddress":129,
"_powerSource":"Mains (single phase)",
"_softwareBuildID":"1.01",
"_stackVersion":101,
"_type":"Router",
"_zclVersion":1,
"meta":{

}
},
"endpoint":{
"deviceID":5,
"inputClusters":[
1
],
"outputClusters":[
2
],
"profileID":99,
"ID":1,
"clusters":{

},
"deviceIeeeAddress":"0x129",
"deviceNetworkAddress":129,
"_binds":[

]
},
"data":{
"16389": 3,
},
"linkquality":19,
"groupID":10,
"cluster":"genTime",
"meta":{
"zclTransactionSequenceNumber":40
}
};

expect(events.message.length).toBe(1);
expect(deepClone(events.message[0])).toStrictEqual(expected);
});
});

0 comments on commit eaba706

Please sign in to comment.