Add support for specifying the sender id to each call
This parameter is optional, so compatibility shouldn't be affected. Each SLMessage can set its own sender ID which is present on the returned message. This allows callers to fire multiple requests at once, even of the same type, while being able to identify which response went with which request. If not specified, the default value is 0. Also went ahead and documented some of the helper functions present on SLMessage (so, available on all message instances). Finally, since I was in and messing with each message anyway, I simplified and removed some repeated code from each derived message and had it call into the super to take advantage of shared decoding functionality. The lambdas ("arrow functions") in test functions were removed per advice from Mocha's documentation where the implicit `this` rebinding can apparently cause problems. This should probably have been its own commit, but, again, I was already in there messing with stuff, so...oh well. Closes #43
This commit is contained in:
@ -3,8 +3,8 @@
|
||||
const ScreenLogic = require('../index');
|
||||
|
||||
// you'll need a ScreenLogic-enabled device on your network for this to succeed
|
||||
describe('Finder', () => {
|
||||
it('finds a server', done => {
|
||||
describe('Finder', function() {
|
||||
it('finds a server', function(done) {
|
||||
let finder = new ScreenLogic.FindUnits();
|
||||
finder.on('serverFound', server => {
|
||||
finder.close();
|
||||
|
@ -9,7 +9,7 @@ function slMessageLen(str) {
|
||||
return 4 + str.length + SLMessage.slackForAlignment(str.length);
|
||||
}
|
||||
|
||||
describe('SLMessage utilities', () => {
|
||||
describe('SLMessage utilities', function() {
|
||||
// message header = senderId, messageId, bodyLen.
|
||||
// senderId and messageId are int16's, so 2b each. bodyLen is an int32, so 4b. total 8b.
|
||||
let msgHeaderLen = 8;
|
||||
|
@ -1,11 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const ScreenLogic = require('../index');
|
||||
var assert = require('assert');
|
||||
|
||||
// you'll need a ScreenLogic-enabled device on your network for this to succeed
|
||||
describe('Unit', () => {
|
||||
describe('Unit', function() {
|
||||
let unit;
|
||||
before(done => {
|
||||
before(function(done) {
|
||||
let finder = new ScreenLogic.FindUnits();
|
||||
finder.on('serverFound', server => {
|
||||
finder.close();
|
||||
@ -21,50 +22,57 @@ describe('Unit', () => {
|
||||
finder.search();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
after(function() {
|
||||
unit.close();
|
||||
});
|
||||
|
||||
// let circuit;
|
||||
it('gets pool status', done => {
|
||||
it('gets pool status', function(done) {
|
||||
unit.on('poolStatus', status => {
|
||||
/* circuit = */status.circuitArray[0];
|
||||
assert.equal(status.senderId, 0);
|
||||
done();
|
||||
});
|
||||
|
||||
unit.getPoolStatus();
|
||||
});
|
||||
|
||||
it('gets controller config', done => {
|
||||
it('gets controller config', function(done) {
|
||||
unit.on('controllerConfig', config => {
|
||||
assert.equal(config.senderId, 42);
|
||||
done();
|
||||
});
|
||||
unit.getControllerConfig();
|
||||
|
||||
unit.getControllerConfig(42);
|
||||
});
|
||||
|
||||
it('gets chemical data', done => {
|
||||
unit.on('chemicalData', () => {
|
||||
it('gets chemical data', function(done) {
|
||||
unit.on('chemicalData', chemData => {
|
||||
assert.equal(chemData.senderId, 123);
|
||||
done();
|
||||
});
|
||||
unit.getChemicalData();
|
||||
|
||||
unit.getChemicalData(123);
|
||||
});
|
||||
|
||||
it('gets salt cell config', done => {
|
||||
unit.on('saltCellConfig', () => {
|
||||
it('gets salt cell config', function(done) {
|
||||
unit.on('saltCellConfig', saltConfig => {
|
||||
assert.equal(saltConfig.senderId, 0);
|
||||
done();
|
||||
});
|
||||
|
||||
unit.getSaltCellConfig();
|
||||
});
|
||||
|
||||
it('gets version', done => {
|
||||
unit.on('version', () => {
|
||||
it('gets version', function(done) {
|
||||
unit.on('version', version => {
|
||||
assert.equal(version.senderId, 41239);
|
||||
done();
|
||||
});
|
||||
unit.getVersion();
|
||||
|
||||
unit.getVersion(41239);
|
||||
});
|
||||
|
||||
/* uncomment this and the `circuit` stuff above to test setting state
|
||||
it('sets circuit state', done => {
|
||||
it('sets circuit state', function(done) {
|
||||
unit.on('circuitStateChanged', () => {
|
||||
done();
|
||||
});
|
||||
|
Reference in New Issue
Block a user