zigbee-bridge
Version:
An open source ZigBee gateway solution with node.js.
1,020 lines (947 loc) • 97.5 kB
JavaScript
const EventEmitter = require('events');
const controller = new EventEmitter();
const sinon = require('sinon');
const expect = require('chai').expect;
const Q = require('q');
let af = require('../lib/components/af');
const Device = require('../lib/model/device');
const Endpoint = require('../lib/model/endpoint');
const Coord = require('../lib/model/coord');
const Coordpoint = require('../lib/model/coordpoint');
let remoteDev = new Device({
type: 1,
ieeeAddr: '0x123456789ABCDEF',
nwkAddr: 100,
status: 2,
joinTime: 1468293176128,
manufId: 10,
epList: [1, 2],
endpoints: {},
});
let rmEp1 = new Endpoint(remoteDev, {
profId: 0x0104,
epId: 1,
devId: 0x0000,
inClusterList: [0x0000, 0x0006],
outClusterList: [0x0000],
});
let rmEp2 = new Endpoint(remoteDev, {
profId: 0x0104,
epId: 2,
devId: 0x0002,
inClusterList: [0x0000],
outClusterList: [0x0000, 0x0006],
});
let coordDev = new Coord({
type: 0,
ieeeAddr: '0xABCDEF123456789',
nwkAddr: 0,
status: 2,
joinTime: 1468293006128,
manufId: 10,
epList: [1, 8],
endpoints: {},
});
let loEp1 = new Coordpoint(coordDev, {
profId: 0x0104,
epId: 1,
devId: 0x0002,
inClusterList: [0x0000],
outClusterList: [0x0000, 0x0006],
}, true);
let loEp8 = new Coordpoint(coordDev, {
profId: 0x0104,
epId: 8,
devId: 0x0050,
inClusterList: [0x0000],
outClusterList: [0x0000, 0x0006],
});
coordDev.endpoints[loEp1.getEpId()] = loEp1;
coordDev.endpoints[loEp8.getEpId()] = loEp8;
coordDev.getDelegator = function(profId) {
if (profId === 0x0104) return loEp1;
};
controller.getCoord = function() {
return coordDev;
};
let transId = 0;
controller.nextTransId = function() {
if (++transId > 255) transId = 1;
return transId;
};
controller.request = function(subsys, cmdId, valObj, callback) {
let deferred = Q.defer();
process.nextTick(function() {
deferred.resolve({status: 0});
});
return deferred.promise.nodeify(callback);
};
controller.findEndpoint = function(srcaddr, srcendpoint) {
if (srcaddr === 100) {
if (srcendpoint === rmEp1.getEpId()) {
return rmEp1;
} else if (srcendpoint === rmEp2.getEpId()) {
return rmEp2;
}
} else if (srcaddr === 0) {
if (srcendpoint === loEp1.getEpId()) {
return loEp1;
} else if (srcendpoint === loEp8.getEpId()) {
return loEp8;
}
}
};
function fireFakeCnf(status, epid, transid) {
let afEventCnf = 'AF:dataConfirm:' + epid + ':' + transid;
setTimeout(function() {
controller.emit(afEventCnf, {
status: status,
endpoint: epid,
transid: transid,
});
});
}
function fireFakeZclRsp(dstNwkAddr, dstEpId, srcEpId, zclData) {
setTimeout(function() {
controller.emit('ZCL:incomingMsg', {
srcaddr: dstNwkAddr,
srcendpoint: dstEpId,
dstendpoint: srcEpId || loEp1.getEpId(),
zclMsg: zclData,
});
});
}
function fireFakeZclRawRsp(dstNwkAddr, dstEpId, srcEpId, zclBuffer, cid) {
// msg: { groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, len, data }
setTimeout(function() {
controller.emit('AF:incomingMsg', {
srcaddr: dstNwkAddr,
srcendpoint: dstEpId,
dstendpoint: srcEpId || loEp1.getEpId(),
clusterid: cid || 0,
data: zclBuffer,
});
});
}
// af is an inner module, don't have to check all the arguments things
describe('APIs Arguments Check for Throwing Error', function() {
before(function() {
af = require('../lib/components/af')(controller);
});
describe('#.send', function() {
it('should be a function', function() {
expect(af.send).to.be.a('function');
});
it('Throw TypeError if srcEp is not an Endpoint or a Coorpoint', function() {
expect(function() {
return af.send('x', rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send([], rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send({}, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(undefined, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(null, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(NaN, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(new Date(), rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(function() {}, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.send(loEp1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if dstEp is not an Endpoint or a Coorpoint', function() {
expect(function() {
return af.send(rmEp1, 'x', 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, 1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, [], 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, {}, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, undefined, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, null, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, NaN, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, new Date(), 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, function() {}, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp2, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.send(rmEp1, loEp8, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cluster id is string, but not a valud id', function(done) {
af.send(rmEp1, rmEp1, 'x', new Buffer([1, 2]), {options: 3000}, function(err) {
if (err) {
done();
}
});
});
it('Throw TypeError if cluster id is string, but a valud id', function(done) {
af.send(rmEp1, rmEp1, 'genAlarms', new Buffer([1, 2]), {options: 3000}, function(err) {
if (!err) {
done();
}
});
fireFakeCnf(0, 1, transId);
});
it('Throw TypeError if cluster id is not a number', function() {
expect(function() {
return af.send(rmEp1, rmEp1, {}, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, [], new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, NaN, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, undefined, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, null, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, new Date(), new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, function() {}, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if rawPayload is not a buffer', function() {
expect(function() {
return af.send(rmEp1, rmEp1, 3, 'x', {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, [], {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, {}, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, 311, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, NaN, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Date(), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, function() {}, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('if opt is given: should throw if opt.options is not a number', function() {
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: 'x'}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: []}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: null}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: function() {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: NaN}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('if opt is given: should throw if opt.radius is not a number', function() {
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: 'x'}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: []}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: null}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: function() {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: NaN}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {radius: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('if opt is given: should throw if opt.timeout is not a number', function() {
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: 'x'}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: []}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: null}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: function() {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: NaN}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.send(rmEp1, rmEp1, 3, new Buffer([1, 2]), {timeout: 3000}, function() {});
}).not.to.throw(TypeError);
});
});
describe('#.sendExt', function() {
it('should be a function', function() {
expect(af.sendExt).to.be.a('function');
});
it('Throw TypeError if srcEp is not an Instance of Endpoint or Coordpoint class', function() {
expect(function() {
return af.sendExt('x', 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(1, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt([], 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt({}, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(new Date(), 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(null, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(undefined, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(NaN, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(function() {}, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if addrMode is not a number', function() {
expect(function() {
return af.sendExt(loEp8, 'x', 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, [], 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, {}, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, NaN, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, new Date(), 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, function() {}, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if dstAddrOrGrpId is not a number for ADDR_16BIT(2)', function() {
expect(function() {
return af.sendExt(loEp8, 2, [], 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, {}, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, NaN, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, new Date(), 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, function() {}, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 'xxx', 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if dstAddrOrGrpId is not a number for ADDR_GROUP(1)', function() {
expect(function() {
return af.sendExt(loEp8, 1, [], 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 1, {}, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 1, NaN, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 1, new Date(), 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 1, function() {}, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 1, 'xxx', 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 1, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if dstAddrOrGrpId is not a string for ADDR_64BIT(1)', function() {
expect(function() {
return af.sendExt(loEp8, 3, [], 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 3, {}, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 3, NaN, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 3, new Date(), 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 3, function() {}, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 3, 1234, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 3, 'xxx', 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cluster id is string, but not a valud id', function(done) {
af.sendExt(loEp8, 2, 3, 'x', new Buffer([1, 2]), {options: 3000}, function(err) {
if (err) {
done();
}
});
});
it('Throw TypeError if cluster id is string, but a valud id', function(done) {
af.sendExt(loEp8, 2, 3, 'genAlarms', new Buffer([1, 2]), {options: 3000}, function(err) {
if (!err) {
done();
}
});
fireFakeCnf(0, 8, transId);
});
it('Throw TypeError if cluster id is not a number', function() {
expect(function() {
return af.sendExt(loEp8, 2, 3, {}, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, [], new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, NaN, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, undefined, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, null, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, new Date(), new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, function() {}, new Buffer([1, 2]), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 3, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if rawPayload is not a buffer', function() {
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, 'x', {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, [], {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, {}, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, 311, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, NaN, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Date(), {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, function() {}, {options: 3000}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('if opt is given: should throw if opt.options is not a number', function() {
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: 'x'}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: []}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: null}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: function() {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: NaN}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {options: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('if opt is given: should throw if opt.radius is not a number', function() {
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: 'x'}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: []}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: null}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: function() {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: NaN}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {radius: 3000}, function() {});
}).not.to.throw(TypeError);
});
it('if opt is given: should throw if opt.timeout is not a number', function() {
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: 'x'}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: []}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: null}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: function() {}}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: NaN}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.sendExt(loEp8, 2, 3, 12, new Buffer([1, 2]), {timeout: 3000}, function() {});
}).not.to.throw(TypeError);
});
});
describe('#.zclFoundation', function() {
it('Throw TypeError if srcEp is not an Instance of Endpoint or Coordpoint class', function() {
expect(function() {
return af.zclFoundation('x', rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(1, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation([], rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation({}, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(null, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(true, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(undefined, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(new Date(), rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(function() {}, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if dstEp is not an Instance of Endpoint or Coordpoint class', function() {
expect(function() {
return af.zclFoundation(rmEp1, 'x', 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, 1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, [], 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, {}, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, null, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, true, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, undefined, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, new Date(), 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, function() {}, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cId is not a string and not a number', function() {
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, [], 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, {}, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, null, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, undefined, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, NaN, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, false, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, new Date(), 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, function() {}, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cmd is not a string and not a number', function() {
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, [], [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, {}, [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, null, [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, undefined, [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, NaN, [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, false, [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, new Date(), [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, function() {}, [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [{attrId: 0}, {attrId: 1}, {attrId: 3}], function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if zclData is with bad type', function() {
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', 'x', function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', null, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', 3, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', true, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', NaN, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', undefined, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', function() {}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', new Date(), function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', {}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', function() {}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cfg is given but not an object', function() {
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], 'x', function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], 1, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], [], function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], true, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], function() {}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], NaN, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], null, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], undefined, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFoundation(rmEp1, rmEp1, 3, 'read', [], {}, function() {});
}).not.to.throw(TypeError);
});
});
describe('#.zclFunctional', function() {
it('Throw TypeError if srcEp is not an Instance of Endpoint or Coordpoint class', function() {
expect(function() {
return af.zclFunctional('x', rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(1, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional([], rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional({}, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(null, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(true, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(undefined, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(new Date(), rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(function() {}, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 5, 3, {groupid: 1}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if dstEp is not an Instance of Endpoint or Coordpoint class', function() {
expect(function() {
return af.zclFunctional(rmEp1, 'x', 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, 1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, [], 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, {}, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, null, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, true, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, undefined, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, new Date(), 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, function() {}, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 5, 3, {groupid: 1}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cId is not a string and not a number', function() {
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, [], 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, {}, 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, null, 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, true, 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, undefined, 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, new Date(), 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, function() {}, 'removeAll', {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 5, 3, {groupid: 1}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if cmd is not a string and not a number', function() {
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', [], {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', {}, {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', null, {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', true, {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', undefined, {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', NaN, {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', new Date(), {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', function() {}, {groupid: 1}, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 5, 3, {groupid: 1}, function() {});
}).not.to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', {groupid: 1}, function() {});
}).not.to.throw(TypeError);
});
it('Throw TypeError if zclData is with bad type', function() {
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', 'x', function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', null, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', 3, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', true, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', NaN, function() {});
}).to.throw(TypeError);
expect(function() {
return af.zclFunctional(rmEp1, rmEp1, 'genScenes', 'removeAll', undefined,