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();
@ -9,33 +11,34 @@ finder.on('serverFound', function(server) {
finder.search(); finder.search();
// use this instead of the above `finder` logic if you want to use a direct connection // use this instead of the above `finder` logic if you want to use a direct connection
//connect(new ScreenLogic.UnitConnection(80, '10.0.0.85')); // connect(new ScreenLogic.UnitConnection(80, '10.0.0.85'));
function connect(client) { function connect(client) {
client.on('loggedIn', function() { client.on('loggedIn', function() {
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');
@ -8,10 +10,10 @@ class FindUnits extends EventEmitter {
super(); super();
this.finder = dgram.createSocket('udp4'); this.finder = dgram.createSocket('udp4');
var _this = this; var _this = this;
this.finder.on('message', function (message, remote) { this.finder.on('message', function(message, remote) {
_this.foundServer(message, remote); _this.foundServer(message, remote);
}).on('close', function() { }).on('close', function() {
//console.log('finder closed'); // console.log('finder closed');
}); });
} }
@ -25,7 +27,7 @@ class FindUnits extends EventEmitter {
} }
foundServer(message, remote) { foundServer(message, remote) {
//console.log('Found something'); // console.log('Found something');
if (message.length >= 40) { if (message.length >= 40) {
var server = { var server = {
address: remote.address, address: remote.address,
@ -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,8 +49,8 @@ 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...");
} }
close() { close() {
@ -71,7 +74,7 @@ class UnitConnection extends EventEmitter {
this.client.on('data', function(msg) { this.client.on('data', function(msg) {
_this.onClientMessage(msg); _this.onClientMessage(msg);
}).on('close', function(had_error) { }).on('close', function(had_error) {
//console.log('unit connection closed'); // console.log('unit connection closed');
}); });
} }
@ -80,7 +83,7 @@ class UnitConnection extends EventEmitter {
} }
connect() { connect() {
//console.log("connecting..."); // console.log("connecting...");
var _this = this; var _this = this;
this.client.connect(this.serverPort, this.serverAddress, function() { this.client.connect(this.serverPort, this.serverAddress, function() {
_this.onConnected(); _this.onConnected();
@ -88,42 +91,42 @@ class UnitConnection extends EventEmitter {
} }
onConnected() { onConnected() {
//console.log('connected'); // console.log('connected');
//console.log('sending init message...'); // console.log('sending init message...');
this.client.write('CONNECTSERVERHOST\r\n\r\n'); this.client.write('CONNECTSERVERHOST\r\n\r\n');
//console.log('sending challenge message...'); // console.log('sending challenge message...');
this.client.write(new messages.SLChallengeMessage().toBuffer()); this.client.write(new messages.SLChallengeMessage().toBuffer());
} }
login() { login() {
//console.log('sending login message...'); // console.log('sending login message...');
this.client.write(new messages.SLLoginMessage().toBuffer()); this.client.write(new messages.SLLoginMessage().toBuffer());
} }
getPoolStatus() { getPoolStatus() {
//console.log('sending pool status query...'); // console.log('sending pool status query...');
this.client.write(new messages.SLPoolStatusMessage().toBuffer()); this.client.write(new messages.SLPoolStatusMessage().toBuffer());
} }
getControllerConfig() { getControllerConfig() {
//console.log('sending controller config query...'); // console.log('sending controller config query...');
this.client.write(new messages.SLControllerConfigMessage().toBuffer()); this.client.write(new messages.SLControllerConfigMessage().toBuffer());
} }
getChemicalData() { getChemicalData() {
//console.log('sending chemical data query...'); // console.log('sending chemical data query...');
this.client.write(new messages.SLChemDataMessage().toBuffer()); this.client.write(new messages.SLChemDataMessage().toBuffer());
} }
getSaltCellConfig() { getSaltCellConfig() {
//console.log('sending salt cell config query...'); // console.log('sending salt cell config query...');
this.client.write(new messages.SLSaltCellConfigMessage().toBuffer()); this.client.write(new messages.SLSaltCellConfigMessage().toBuffer());
} }
getVersion() { getVersion() {
//console.log('sending version query...'); // console.log('sending version query...');
this.client.write(new messages.SLVersionMessage().toBuffer()); this.client.write(new messages.SLVersionMessage().toBuffer());
} }
@ -132,7 +135,7 @@ class UnitConnection extends EventEmitter {
} }
onClientMessage(msg) { onClientMessage(msg) {
//console.log('received message of length ' + msg.length); // console.log('received message of length ' + msg.length);
if (msg.length < 4) { if (msg.length < 4) {
return; return;
} }
@ -140,39 +143,39 @@ class UnitConnection extends EventEmitter {
var msgType = msg.readInt16LE(2); var msgType = msg.readInt16LE(2);
switch (msgType) { switch (msgType) {
case messages.SLChallengeMessage.getResponseId(): case messages.SLChallengeMessage.getResponseId():
//console.log(" it's a challenge response"); // console.log(" it's a challenge response");
this.login(); this.login();
break; break;
case messages.SLLoginMessage.getResponseId(): case messages.SLLoginMessage.getResponseId():
//console.log(" it's a login response"); // console.log(" it's a login response");
this.emit('loggedIn'); this.emit('loggedIn');
break; break;
case messages.SLPoolStatusMessage.getResponseId(): case messages.SLPoolStatusMessage.getResponseId():
//console.log(" it's pool status"); // console.log(" it's pool status");
this.emit('poolStatus', new messages.SLPoolStatusMessage(msg)); this.emit('poolStatus', new messages.SLPoolStatusMessage(msg));
break; break;
case messages.SLControllerConfigMessage.getResponseId(): case messages.SLControllerConfigMessage.getResponseId():
//console.log(" it's controller configuration"); // console.log(" it's controller configuration");
this.emit('controllerConfig', new messages.SLControllerConfigMessage(msg)); this.emit('controllerConfig', new messages.SLControllerConfigMessage(msg));
break; break;
case messages.SLChemDataMessage.getResponseId(): case messages.SLChemDataMessage.getResponseId():
//console.log(" it's chem data"); // console.log(" it's chem data");
this.emit('chemicalData', new messages.SLChemDataMessage(msg)); this.emit('chemicalData', new messages.SLChemDataMessage(msg));
break; break;
case messages.SLSaltCellConfigMessage.getResponseId(): case messages.SLSaltCellConfigMessage.getResponseId():
//console.log(" it's salt cell config"); // console.log(" it's salt cell config");
this.emit('saltCellConfig', new messages.SLSaltCellConfigMessage(msg)); this.emit('saltCellConfig', new messages.SLSaltCellConfigMessage(msg));
break; break;
case messages.SLVersionMessage.getResponseId(): case messages.SLVersionMessage.getResponseId():
//console.log(" it's version"); // console.log(" it's version");
this.emit('version', new messages.SLVersionMessage(msg)); this.emit('version', new messages.SLVersionMessage(msg));
break; break;
case messages.SLSetCircuitStateMessage.getResponseId(): case messages.SLSetCircuitStateMessage.getResponseId():
//console.log(" it's circuit toggle ack"); // console.log(" it's circuit toggle ack");
this.emit('circuitStateChanged', new messages.SLSetCircuitStateMessage()); this.emit('circuitStateChanged', new messages.SLSetCircuitStateMessage());
break; break;
default: default:
//console.log(" it's unknown. type: " + msgType); // console.log(" it's unknown. type: " + msgType);
break; break;
} }
} }
@ -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,14 +1,16 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage; const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12530; const MSG_ID = 12530;
exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMessage { exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMessage {
constructor(controllerId, circuitId, circuitState) { constructor(controllerId, circuitId, circuitState) {
super(0, MSG_ID); super(0, MSG_ID);
this.controllerId = controllerId; this.controllerId = controllerId;
this.circuitId = circuitId; this.circuitId = circuitId;
this.circuitState = circuitState; this.circuitState = circuitState;
} }
encode() { encode() {
@ -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);
});
});