Skip to content
This repository has been archived by the owner on Jul 5, 2019. It is now read-only.

Commit

Permalink
Add ind:cmd for cmdids: 'on', 'offWithEffect', 'step', 'stop'. Koenkk…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Jun 23, 2018
1 parent 6510114 commit bc13acc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/components/af.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var af = {
_seq: 0
};

var debug = require('debug')('zigbee-shepherd:af');

af.send = function (srcEp, dstEp, cId, rawPayload, opt, callback) {
// srcEp maybe a local app ep, or a remote ep
var deferred = Q.defer(),
Expand Down Expand Up @@ -571,6 +573,8 @@ function dispatchIncomingMsg(type, msg) {
mandatoryEvent; // bridged event
var coord = af.controller.getCoord();

debug(`dispatchIncomingMsg(): type: ${type}, msg: ${msg}`);

if (msg.hasOwnProperty('endpoint')) { // dataConfirm, reflectError
if(!coord) return;
targetEp = coord.getEndpoint(msg.endpoint); // => find local ep, such a message is going to local ep
Expand Down Expand Up @@ -664,6 +668,10 @@ function dispatchIncomingMsg(type, msg) {
if (frameType === 0 && msg.zclMsg.cmdId === 'report')
af.controller.getShepherd().emit('ind:reported', targetEp, msg.clusterid, msg.zclMsg.payload);

const cmdIDs = ['on', 'offWithEffect', 'step', 'stop'];
if (frameType === 1 && cmdIDs.includes(msg.zclMsg.cmdId) && msg.zclMsg.payload)
af.controller.getShepherd().emit('ind:cmd', targetEp, msg.clusterid, msg.zclMsg.payload, msg.zclMsg.cmdId);

if (frameType === 0) // foundation
dispatchTo = targetEp.onZclFoundation;
else if (frameType === 1) // functional
Expand Down
11 changes: 11 additions & 0 deletions lib/shepherd.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ function ZShepherd(path, opts) {
self.emit('ind', { type: 'devChange', endpoints: [ ep ], data: notifData });
});

this.on('ind:cmd', function (ep, cId, payload, cmdId) {
const cIdString = zclId.cluster(cId);
const type = `cmd${cmdId.charAt(0).toUpperCase() + cmdId.substr(1)}`;
const notifData = {};

notifData.cid = cIdString ? cIdString.key : cId;
notifData.data = payload;

self.emit('ind', { type: type, endpoints: [ ep ], data: notifData });
});

this.on('ind:statusChange', function (ep, cId, payload) {
var cIdString = zclId.cluster(cId),
notifData = {
Expand Down

0 comments on commit bc13acc

Please sign in to comment.