Linter fixes

This commit is contained in:
2018-04-28 23:06:11 -05:00
parent 26083f75a7
commit 3c6b8ebcc7
14 changed files with 154 additions and 120 deletions

View File

@ -1,3 +1,5 @@
'use strict';
const ScreenLogic = require('./index'); const ScreenLogic = require('./index');
var finder = new ScreenLogic.FindUnits(); var finder = new ScreenLogic.FindUnits();
@ -16,26 +18,27 @@ function connect(client) {
this.getVersion(); this.getVersion();
}).on('version', function(version) { }).on('version', function(version) {
this.getPoolStatus(); this.getPoolStatus();
console.log(" version=" + version.version); console.log(' version=' + version.version);
}).on('poolStatus', function(status) { }).on('poolStatus', function(status) {
this.getChemicalData(); this.getChemicalData();
console.log(" pool ok=" + status.ok); console.log(' pool ok=' + status.ok);
console.log(" air temp=" + status.airTemp); console.log(' pool temp=' + status.currentTemp[0]);
console.log(" salt ppm=" + status.saltPPM); console.log(' air temp=' + status.airTemp);
console.log(" pH=" + status.pH); console.log(' salt ppm=' + status.saltPPM);
console.log(" saturation=" + status.saturation); console.log(' pH=' + status.pH);
console.log(" spa active=" + status.isSpaActive()); console.log(' saturation=' + status.saturation);
console.log(" pool active=" + status.isPoolActive()); console.log(' spa active=' + status.isSpaActive());
console.log(' pool active=' + status.isPoolActive());
}).on('chemicalData', function(chemData) { }).on('chemicalData', function(chemData) {
this.getSaltCellConfig(); this.getSaltCellConfig();
console.log(" calcium=" + chemData.calcium); console.log(' calcium=' + chemData.calcium);
console.log(" cyanuric acid=" + chemData.cyanuricAcid); console.log(' cyanuric acid=' + chemData.cyanuricAcid);
console.log(" alkalinity=" + chemData.alkalinity); console.log(' alkalinity=' + chemData.alkalinity);
}).on('saltCellConfig', function(saltCellConfig) { }).on('saltCellConfig', function(saltCellConfig) {
this.getControllerConfig(); this.getControllerConfig();
console.log(" salt cell installed=" + saltCellConfig.installed); console.log(' salt cell installed=' + saltCellConfig.installed);
}).on('controllerConfig', function(config) { }).on('controllerConfig', function(config) {
console.log(" controller is in celsius=" + config.degC); console.log(' controller is in celsius=' + config.degC);
client.close(); client.close();
}); });

View File

@ -1,3 +1,5 @@
'use strict';
var dgram = require('dgram'); var dgram = require('dgram');
var net = require('net'); var net = require('net');
const EventEmitter = require('events'); const EventEmitter = require('events');
@ -33,10 +35,11 @@ class FindUnits extends EventEmitter {
port: message.readInt16LE(8), port: message.readInt16LE(8),
gatewayType: message.readUInt8(10), gatewayType: message.readUInt8(10),
gatewaySubtype: message.readUInt8(11), gatewaySubtype: message.readUInt8(11),
gatewayName: message.toString('utf8', 12, 28) gatewayName: message.toString('utf8', 12, 28),
}; };
//console.log(' type: ' + server.type + ', host: ' + server.address + ':' + server.port + ', identified as ' + server.gatewayName); // console.log(' type: ' + server.type + ', host: ' + server.address + ':' + server.port + ',
// identified as ' + server.gatewayName);
if (server.type === 2) { if (server.type === 2) {
this.emit('serverFound', server); this.emit('serverFound', server);
} }
@ -46,7 +49,7 @@ class FindUnits extends EventEmitter {
sendServerBroadcast() { sendServerBroadcast() {
var message = Buffer.alloc(8); var message = Buffer.alloc(8);
message[0] = 1; message[0] = 1;
this.finder.send(message, 0, message.length, 1444, "255.255.255.255"); this.finder.send(message, 0, message.length, 1444, '255.255.255.255');
// console.log("Looking for ScreenLogic hosts..."); // console.log("Looking for ScreenLogic hosts...");
} }
@ -186,5 +189,5 @@ for (const value of buf.values()) {
module.exports = { module.exports = {
FindUnits, FindUnits,
UnitConnection UnitConnection,
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 14; const MSG_ID = 14;
@ -10,4 +12,4 @@ exports.SLChallengeMessage = class SLChallengeMessage extends SLMessage {
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12592; const MSG_ID = 12592;
@ -53,4 +55,4 @@ exports.SLChemDataMessage = class SLChemDataMessage extends SLMessage {
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12532; const MSG_ID = 12532;
@ -49,8 +51,8 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
colorPos: this.readUInt8(), colorPos: this.readUInt8(),
colorStagger: this.readUInt8(), colorStagger: this.readUInt8(),
deviceId: this.readUInt8(), deviceId: this.readUInt8(),
dfaultRt: this.readUInt16LE() dfaultRt: this.readUInt16LE(),
} };
this._readOffset += 2; this._readOffset += 2;
} }
@ -60,11 +62,11 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
this.colorArray[i] = { this.colorArray[i] = {
name: this.readSLString(), name: this.readSLString(),
color: { color: {
r: this.readInt32LE() & 0xFF, r: this.readInt32LE() & 0xff,
g: this.readInt32LE() & 0xFF, g: this.readInt32LE() & 0xff,
b: this.readInt32LE() & 0xFF b: this.readInt32LE() & 0xff,
} },
} };
} }
let pumpCircCount = 8; let pumpCircCount = 8;
@ -80,4 +82,4 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 27; const MSG_ID = 27;
@ -15,4 +17,4 @@ exports.SLLoginMessage = class SLLoginMessage extends SLMessage {
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SmartBuffer = require('smart-buffer').SmartBuffer; const SmartBuffer = require('smart-buffer').SmartBuffer;
exports.SLMessage = class SLMessage extends SmartBuffer { exports.SLMessage = class SLMessage extends SmartBuffer {
@ -25,16 +27,16 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
writeSLString(str) { writeSLString(str) {
this.writeInt32LE(str.length); this.writeInt32LE(str.length);
this.writeString(str); this.writeString(str);
if (str.length % 4 != 0) { if (str.length % 4 !== 0) {
this.skipWrite(4 - (str.length % 4)); this.skipWrite(4 - str.length % 4);
} }
} }
readSLString() { readSLString() {
var len = this.readInt32LE(); var len = this.readInt32LE();
var str = this.readString(len); var str = this.readString(len);
if (len % 4 != 0) { if (len % 4 !== 0) {
this.readOffset += 4 - (len % 4); this.readOffset += 4 - len % 4;
} }
return str; return str;
} }
@ -57,7 +59,5 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
this.dataLength = this.readInt32LE(); this.dataLength = this.readInt32LE();
} }
encode() { encode() {}
};
}
}

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12526; const MSG_ID = 12526;
@ -60,8 +62,8 @@ exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
colorSet: this.readUInt8(), colorSet: this.readUInt8(),
colorPos: this.readUInt8(), colorPos: this.readUInt8(),
colorStagger: this.readUInt8(), colorStagger: this.readUInt8(),
delay: this.readUInt8() delay: this.readUInt8(),
} };
} }
this.pH = this.readInt32LE() / 100; this.pH = this.readInt32LE() / 100;
@ -104,4 +106,4 @@ exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12572; const MSG_ID = 12572;
@ -30,4 +32,4 @@ exports.SLSaltCellConfigMessage = class SLSaltCellConfigMessage extends SLMessag
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12530; const MSG_ID = 12530;
@ -22,4 +24,4 @@ exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMess
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,3 +1,5 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 8120; const MSG_ID = 8120;
@ -22,4 +24,4 @@ exports.SLVersionMessage = class SLVersionMessage extends SLMessage {
static getResponseId() { static getResponseId() {
return MSG_ID + 1; return MSG_ID + 1;
} }
} };

View File

@ -1,8 +1,10 @@
exports.SLPoolStatusMessage = require("./SLPoolStatusMessage.js").SLPoolStatusMessage; 'use strict';
exports.SLControllerConfigMessage = require("./SLControllerConfigMessage.js").SLControllerConfigMessage;
exports.SLChallengeMessage = require("./SLChallengeMessage.js").SLChallengeMessage; exports.SLPoolStatusMessage = require('./SLPoolStatusMessage.js').SLPoolStatusMessage;
exports.SLLoginMessage = require("./SLLoginMessage.js").SLLoginMessage; exports.SLControllerConfigMessage = require('./SLControllerConfigMessage.js').SLControllerConfigMessage;
exports.SLChemDataMessage = require("./SLChemDataMessage.js").SLChemDataMessage; exports.SLChallengeMessage = require('./SLChallengeMessage.js').SLChallengeMessage;
exports.SLSaltCellConfigMessage = require("./SLSaltCellConfigMessage.js").SLSaltCellConfigMessage; exports.SLLoginMessage = require('./SLLoginMessage.js').SLLoginMessage;
exports.SLVersionMessage = require("./SLVersionMessage.js").SLVersionMessage; exports.SLChemDataMessage = require('./SLChemDataMessage.js').SLChemDataMessage;
exports.SLSetCircuitStateMessage = require("./SLSetCircuitStateMessage.js").SLSetCircuitStateMessage; exports.SLSaltCellConfigMessage = require('./SLSaltCellConfigMessage.js').SLSaltCellConfigMessage;
exports.SLVersionMessage = require('./SLVersionMessage.js').SLVersionMessage;
exports.SLSetCircuitStateMessage = require('./SLSetCircuitStateMessage.js').SLSetCircuitStateMessage;

View File

@ -1,4 +1,4 @@
'use strict' 'use strict';
const ScreenLogic = require('../index'); const ScreenLogic = require('../index');
@ -7,9 +7,9 @@ describe('Finder', () => {
it('finds a server', done => { it('finds a server', done => {
let finder = new ScreenLogic.FindUnits(); let finder = new ScreenLogic.FindUnits();
finder.on('serverFound', server => { finder.on('serverFound', server => {
finder.close() finder.close();
done() done();
}) });
finder.search(); finder.search();
}) });
}) });

View File

@ -1,62 +1,72 @@
'use strict' 'use strict';
const ScreenLogic = require('../index'); const ScreenLogic = require('../index');
// you'll need a ScreenLogic-enabled device on your network for this to succeed // you'll need a ScreenLogic-enabled device on your network for this to succeed
describe('Unit', () => { describe('Unit', () => {
let unit let unit;
before(done => { before(done => {
let finder = new ScreenLogic.FindUnits(); let finder = new ScreenLogic.FindUnits();
finder.on('serverFound', server => { finder.on('serverFound', server => {
finder.close() finder.close();
unit = new ScreenLogic.UnitConnection(server) unit = new ScreenLogic.UnitConnection(server);
unit.on('loggedIn', () => { unit.on('loggedIn', () => {
done() done();
}) });
unit.connect() unit.connect();
}) });
finder.search(); finder.search();
}) });
after(() => { after(() => {
unit.close() unit.close();
}) });
let circuit let circuit;
it('gets pool status', done => { it('gets pool status', done => {
unit.on('poolStatus', status => { unit.on('poolStatus', status => {
circuit = status.circuitArray[0] circuit = status.circuitArray[0];
done() done();
}) });
unit.getPoolStatus() unit.getPoolStatus();
}) });
it('gets controller config', done => { it('gets controller config', done => {
unit.on('controllerConfig', config => { done() }) unit.on('controllerConfig', config => {
unit.getControllerConfig() done();
}) });
unit.getControllerConfig();
});
it('gets chemical data', done => { it('gets chemical data', done => {
unit.on('chemicalData', () => { done() }) unit.on('chemicalData', () => {
unit.getChemicalData() done();
}) });
unit.getChemicalData();
});
it('gets salt cell config', done => { it('gets salt cell config', done => {
unit.on('saltCellConfig', () => { done() }) unit.on('saltCellConfig', () => {
unit.getSaltCellConfig() done();
}) });
unit.getSaltCellConfig();
});
it('gets version', done => { it('gets version', done => {
unit.on('version', () => { done() }) unit.on('version', () => {
unit.getVersion() done();
}) });
unit.getVersion();
});
it('sets circuit state', done => { it('sets circuit state', done => {
unit.on('circuitStateChanged', () => { done() }) unit.on('circuitStateChanged', () => {
unit.setCircuitState(0, circuit.id, circuit.state) done();
}) });
}) unit.setCircuitState(0, circuit.id, circuit.state);
});
});