Linter fixes
This commit is contained in:
31
example.js
31
example.js
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const ScreenLogic = require('./index');
|
||||
|
||||
var finder = new ScreenLogic.FindUnits();
|
||||
@ -9,33 +11,34 @@ finder.on('serverFound', function(server) {
|
||||
finder.search();
|
||||
|
||||
// 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) {
|
||||
client.on('loggedIn', function() {
|
||||
this.getVersion();
|
||||
}).on('version', function(version) {
|
||||
this.getPoolStatus();
|
||||
console.log(" version=" + version.version);
|
||||
console.log(' version=' + version.version);
|
||||
}).on('poolStatus', function(status) {
|
||||
this.getChemicalData();
|
||||
console.log(" pool ok=" + status.ok);
|
||||
console.log(" air temp=" + status.airTemp);
|
||||
console.log(" salt ppm=" + status.saltPPM);
|
||||
console.log(" pH=" + status.pH);
|
||||
console.log(" saturation=" + status.saturation);
|
||||
console.log(" spa active=" + status.isSpaActive());
|
||||
console.log(" pool active=" + status.isPoolActive());
|
||||
console.log(' pool ok=' + status.ok);
|
||||
console.log(' pool temp=' + status.currentTemp[0]);
|
||||
console.log(' air temp=' + status.airTemp);
|
||||
console.log(' salt ppm=' + status.saltPPM);
|
||||
console.log(' pH=' + status.pH);
|
||||
console.log(' saturation=' + status.saturation);
|
||||
console.log(' spa active=' + status.isSpaActive());
|
||||
console.log(' pool active=' + status.isPoolActive());
|
||||
}).on('chemicalData', function(chemData) {
|
||||
this.getSaltCellConfig();
|
||||
console.log(" calcium=" + chemData.calcium);
|
||||
console.log(" cyanuric acid=" + chemData.cyanuricAcid);
|
||||
console.log(" alkalinity=" + chemData.alkalinity);
|
||||
console.log(' calcium=' + chemData.calcium);
|
||||
console.log(' cyanuric acid=' + chemData.cyanuricAcid);
|
||||
console.log(' alkalinity=' + chemData.alkalinity);
|
||||
}).on('saltCellConfig', function(saltCellConfig) {
|
||||
this.getControllerConfig();
|
||||
console.log(" salt cell installed=" + saltCellConfig.installed);
|
||||
console.log(' salt cell installed=' + saltCellConfig.installed);
|
||||
}).on('controllerConfig', function(config) {
|
||||
console.log(" controller is in celsius=" + config.degC);
|
||||
console.log(' controller is in celsius=' + config.degC);
|
||||
client.close();
|
||||
});
|
||||
|
||||
|
63
index.js
63
index.js
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var dgram = require('dgram');
|
||||
var net = require('net');
|
||||
const EventEmitter = require('events');
|
||||
@ -8,10 +10,10 @@ class FindUnits extends EventEmitter {
|
||||
super();
|
||||
this.finder = dgram.createSocket('udp4');
|
||||
var _this = this;
|
||||
this.finder.on('message', function (message, remote) {
|
||||
this.finder.on('message', function(message, remote) {
|
||||
_this.foundServer(message, remote);
|
||||
}).on('close', function() {
|
||||
//console.log('finder closed');
|
||||
// console.log('finder closed');
|
||||
});
|
||||
}
|
||||
|
||||
@ -25,7 +27,7 @@ class FindUnits extends EventEmitter {
|
||||
}
|
||||
|
||||
foundServer(message, remote) {
|
||||
//console.log('Found something');
|
||||
// console.log('Found something');
|
||||
if (message.length >= 40) {
|
||||
var server = {
|
||||
address: remote.address,
|
||||
@ -33,10 +35,11 @@ class FindUnits extends EventEmitter {
|
||||
port: message.readInt16LE(8),
|
||||
gatewayType: message.readUInt8(10),
|
||||
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) {
|
||||
this.emit('serverFound', server);
|
||||
}
|
||||
@ -46,8 +49,8 @@ class FindUnits extends EventEmitter {
|
||||
sendServerBroadcast() {
|
||||
var message = Buffer.alloc(8);
|
||||
message[0] = 1;
|
||||
this.finder.send(message, 0, message.length, 1444, "255.255.255.255");
|
||||
//console.log("Looking for ScreenLogic hosts...");
|
||||
this.finder.send(message, 0, message.length, 1444, '255.255.255.255');
|
||||
// console.log("Looking for ScreenLogic hosts...");
|
||||
}
|
||||
|
||||
close() {
|
||||
@ -71,7 +74,7 @@ class UnitConnection extends EventEmitter {
|
||||
this.client.on('data', function(msg) {
|
||||
_this.onClientMessage(msg);
|
||||
}).on('close', function(had_error) {
|
||||
//console.log('unit connection closed');
|
||||
// console.log('unit connection closed');
|
||||
});
|
||||
}
|
||||
|
||||
@ -80,7 +83,7 @@ class UnitConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
connect() {
|
||||
//console.log("connecting...");
|
||||
// console.log("connecting...");
|
||||
var _this = this;
|
||||
this.client.connect(this.serverPort, this.serverAddress, function() {
|
||||
_this.onConnected();
|
||||
@ -88,42 +91,42 @@ class UnitConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
//console.log('sending challenge message...');
|
||||
// console.log('sending challenge message...');
|
||||
this.client.write(new messages.SLChallengeMessage().toBuffer());
|
||||
}
|
||||
|
||||
login() {
|
||||
//console.log('sending login message...');
|
||||
// console.log('sending login message...');
|
||||
this.client.write(new messages.SLLoginMessage().toBuffer());
|
||||
}
|
||||
|
||||
getPoolStatus() {
|
||||
//console.log('sending pool status query...');
|
||||
// console.log('sending pool status query...');
|
||||
this.client.write(new messages.SLPoolStatusMessage().toBuffer());
|
||||
}
|
||||
|
||||
getControllerConfig() {
|
||||
//console.log('sending controller config query...');
|
||||
// console.log('sending controller config query...');
|
||||
this.client.write(new messages.SLControllerConfigMessage().toBuffer());
|
||||
}
|
||||
|
||||
getChemicalData() {
|
||||
//console.log('sending chemical data query...');
|
||||
// console.log('sending chemical data query...');
|
||||
this.client.write(new messages.SLChemDataMessage().toBuffer());
|
||||
}
|
||||
|
||||
getSaltCellConfig() {
|
||||
//console.log('sending salt cell config query...');
|
||||
// console.log('sending salt cell config query...');
|
||||
this.client.write(new messages.SLSaltCellConfigMessage().toBuffer());
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
//console.log('sending version query...');
|
||||
// console.log('sending version query...');
|
||||
this.client.write(new messages.SLVersionMessage().toBuffer());
|
||||
}
|
||||
|
||||
@ -132,7 +135,7 @@ class UnitConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
onClientMessage(msg) {
|
||||
//console.log('received message of length ' + msg.length);
|
||||
// console.log('received message of length ' + msg.length);
|
||||
if (msg.length < 4) {
|
||||
return;
|
||||
}
|
||||
@ -140,39 +143,39 @@ class UnitConnection extends EventEmitter {
|
||||
var msgType = msg.readInt16LE(2);
|
||||
switch (msgType) {
|
||||
case messages.SLChallengeMessage.getResponseId():
|
||||
//console.log(" it's a challenge response");
|
||||
// console.log(" it's a challenge response");
|
||||
this.login();
|
||||
break;
|
||||
case messages.SLLoginMessage.getResponseId():
|
||||
//console.log(" it's a login response");
|
||||
// console.log(" it's a login response");
|
||||
this.emit('loggedIn');
|
||||
break;
|
||||
case messages.SLPoolStatusMessage.getResponseId():
|
||||
//console.log(" it's pool status");
|
||||
// console.log(" it's pool status");
|
||||
this.emit('poolStatus', new messages.SLPoolStatusMessage(msg));
|
||||
break;
|
||||
case messages.SLControllerConfigMessage.getResponseId():
|
||||
//console.log(" it's controller configuration");
|
||||
// console.log(" it's controller configuration");
|
||||
this.emit('controllerConfig', new messages.SLControllerConfigMessage(msg));
|
||||
break;
|
||||
case messages.SLChemDataMessage.getResponseId():
|
||||
//console.log(" it's chem data");
|
||||
// console.log(" it's chem data");
|
||||
this.emit('chemicalData', new messages.SLChemDataMessage(msg));
|
||||
break;
|
||||
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));
|
||||
break;
|
||||
case messages.SLVersionMessage.getResponseId():
|
||||
//console.log(" it's version");
|
||||
// console.log(" it's version");
|
||||
this.emit('version', new messages.SLVersionMessage(msg));
|
||||
break;
|
||||
case messages.SLSetCircuitStateMessage.getResponseId():
|
||||
//console.log(" it's circuit toggle ack");
|
||||
// console.log(" it's circuit toggle ack");
|
||||
this.emit('circuitStateChanged', new messages.SLSetCircuitStateMessage());
|
||||
break;
|
||||
default:
|
||||
//console.log(" it's unknown. type: " + msgType);
|
||||
// console.log(" it's unknown. type: " + msgType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -186,5 +189,5 @@ for (const value of buf.values()) {
|
||||
|
||||
module.exports = {
|
||||
FindUnits,
|
||||
UnitConnection
|
||||
}
|
||||
UnitConnection,
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 14;
|
||||
@ -10,4 +12,4 @@ exports.SLChallengeMessage = class SLChallengeMessage extends SLMessage {
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12592;
|
||||
@ -53,4 +55,4 @@ exports.SLChemDataMessage = class SLChemDataMessage extends SLMessage {
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12532;
|
||||
@ -49,8 +51,8 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
|
||||
colorPos: this.readUInt8(),
|
||||
colorStagger: this.readUInt8(),
|
||||
deviceId: this.readUInt8(),
|
||||
dfaultRt: this.readUInt16LE()
|
||||
}
|
||||
dfaultRt: this.readUInt16LE(),
|
||||
};
|
||||
this._readOffset += 2;
|
||||
}
|
||||
|
||||
@ -60,11 +62,11 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
|
||||
this.colorArray[i] = {
|
||||
name: this.readSLString(),
|
||||
color: {
|
||||
r: this.readInt32LE() & 0xFF,
|
||||
g: this.readInt32LE() & 0xFF,
|
||||
b: this.readInt32LE() & 0xFF
|
||||
}
|
||||
}
|
||||
r: this.readInt32LE() & 0xff,
|
||||
g: this.readInt32LE() & 0xff,
|
||||
b: this.readInt32LE() & 0xff,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let pumpCircCount = 8;
|
||||
@ -80,4 +82,4 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 27;
|
||||
@ -15,4 +17,4 @@ exports.SLLoginMessage = class SLLoginMessage extends SLMessage {
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SmartBuffer = require('smart-buffer').SmartBuffer;
|
||||
|
||||
exports.SLMessage = class SLMessage extends SmartBuffer {
|
||||
@ -25,16 +27,16 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
|
||||
writeSLString(str) {
|
||||
this.writeInt32LE(str.length);
|
||||
this.writeString(str);
|
||||
if (str.length % 4 != 0) {
|
||||
this.skipWrite(4 - (str.length % 4));
|
||||
if (str.length % 4 !== 0) {
|
||||
this.skipWrite(4 - str.length % 4);
|
||||
}
|
||||
}
|
||||
|
||||
readSLString() {
|
||||
var len = this.readInt32LE();
|
||||
var str = this.readString(len);
|
||||
if (len % 4 != 0) {
|
||||
this.readOffset += 4 - (len % 4);
|
||||
if (len % 4 !== 0) {
|
||||
this.readOffset += 4 - len % 4;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@ -57,7 +59,5 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
|
||||
this.dataLength = this.readInt32LE();
|
||||
}
|
||||
|
||||
encode() {
|
||||
|
||||
}
|
||||
}
|
||||
encode() {}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12526;
|
||||
@ -60,8 +62,8 @@ exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
|
||||
colorSet: this.readUInt8(),
|
||||
colorPos: this.readUInt8(),
|
||||
colorStagger: this.readUInt8(),
|
||||
delay: this.readUInt8()
|
||||
}
|
||||
delay: this.readUInt8(),
|
||||
};
|
||||
}
|
||||
|
||||
this.pH = this.readInt32LE() / 100;
|
||||
@ -104,4 +106,4 @@ exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12572;
|
||||
@ -30,4 +32,4 @@ exports.SLSaltCellConfigMessage = class SLSaltCellConfigMessage extends SLMessag
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,14 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12530;
|
||||
|
||||
exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMessage {
|
||||
constructor(controllerId, circuitId, circuitState) {
|
||||
super(0, MSG_ID);
|
||||
super(0, MSG_ID);
|
||||
|
||||
this.controllerId = controllerId;
|
||||
this.circuitId = circuitId;
|
||||
this.circuitState = circuitState;
|
||||
this.controllerId = controllerId;
|
||||
this.circuitId = circuitId;
|
||||
this.circuitState = circuitState;
|
||||
}
|
||||
|
||||
encode() {
|
||||
@ -22,4 +24,4 @@ exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMess
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 8120;
|
||||
@ -22,4 +24,4 @@ exports.SLVersionMessage = class SLVersionMessage extends SLMessage {
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,8 +1,10 @@
|
||||
exports.SLPoolStatusMessage = require("./SLPoolStatusMessage.js").SLPoolStatusMessage;
|
||||
exports.SLControllerConfigMessage = require("./SLControllerConfigMessage.js").SLControllerConfigMessage;
|
||||
exports.SLChallengeMessage = require("./SLChallengeMessage.js").SLChallengeMessage;
|
||||
exports.SLLoginMessage = require("./SLLoginMessage.js").SLLoginMessage;
|
||||
exports.SLChemDataMessage = require("./SLChemDataMessage.js").SLChemDataMessage;
|
||||
exports.SLSaltCellConfigMessage = require("./SLSaltCellConfigMessage.js").SLSaltCellConfigMessage;
|
||||
exports.SLVersionMessage = require("./SLVersionMessage.js").SLVersionMessage;
|
||||
exports.SLSetCircuitStateMessage = require("./SLSetCircuitStateMessage.js").SLSetCircuitStateMessage;
|
||||
'use strict';
|
||||
|
||||
exports.SLPoolStatusMessage = require('./SLPoolStatusMessage.js').SLPoolStatusMessage;
|
||||
exports.SLControllerConfigMessage = require('./SLControllerConfigMessage.js').SLControllerConfigMessage;
|
||||
exports.SLChallengeMessage = require('./SLChallengeMessage.js').SLChallengeMessage;
|
||||
exports.SLLoginMessage = require('./SLLoginMessage.js').SLLoginMessage;
|
||||
exports.SLChemDataMessage = require('./SLChemDataMessage.js').SLChemDataMessage;
|
||||
exports.SLSaltCellConfigMessage = require('./SLSaltCellConfigMessage.js').SLSaltCellConfigMessage;
|
||||
exports.SLVersionMessage = require('./SLVersionMessage.js').SLVersionMessage;
|
||||
exports.SLSetCircuitStateMessage = require('./SLSetCircuitStateMessage.js').SLSetCircuitStateMessage;
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const ScreenLogic = require('../index');
|
||||
|
||||
@ -7,9 +7,9 @@ describe('Finder', () => {
|
||||
it('finds a server', done => {
|
||||
let finder = new ScreenLogic.FindUnits();
|
||||
finder.on('serverFound', server => {
|
||||
finder.close()
|
||||
done()
|
||||
})
|
||||
finder.close();
|
||||
done();
|
||||
});
|
||||
finder.search();
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@ -1,62 +1,72 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const ScreenLogic = require('../index');
|
||||
|
||||
// you'll need a ScreenLogic-enabled device on your network for this to succeed
|
||||
describe('Unit', () => {
|
||||
let unit
|
||||
let unit;
|
||||
before(done => {
|
||||
let finder = new ScreenLogic.FindUnits();
|
||||
finder.on('serverFound', server => {
|
||||
finder.close()
|
||||
finder.close();
|
||||
|
||||
unit = new ScreenLogic.UnitConnection(server)
|
||||
unit = new ScreenLogic.UnitConnection(server);
|
||||
unit.on('loggedIn', () => {
|
||||
done()
|
||||
})
|
||||
done();
|
||||
});
|
||||
|
||||
unit.connect()
|
||||
})
|
||||
unit.connect();
|
||||
});
|
||||
|
||||
finder.search();
|
||||
})
|
||||
});
|
||||
|
||||
after(() => {
|
||||
unit.close()
|
||||
})
|
||||
unit.close();
|
||||
});
|
||||
|
||||
let circuit
|
||||
let circuit;
|
||||
it('gets pool status', done => {
|
||||
unit.on('poolStatus', status => {
|
||||
circuit = status.circuitArray[0]
|
||||
done()
|
||||
})
|
||||
circuit = status.circuitArray[0];
|
||||
done();
|
||||
});
|
||||
|
||||
unit.getPoolStatus()
|
||||
})
|
||||
unit.getPoolStatus();
|
||||
});
|
||||
|
||||
it('gets controller config', done => {
|
||||
unit.on('controllerConfig', config => { done() })
|
||||
unit.getControllerConfig()
|
||||
})
|
||||
unit.on('controllerConfig', config => {
|
||||
done();
|
||||
});
|
||||
unit.getControllerConfig();
|
||||
});
|
||||
|
||||
it('gets chemical data', done => {
|
||||
unit.on('chemicalData', () => { done() })
|
||||
unit.getChemicalData()
|
||||
})
|
||||
unit.on('chemicalData', () => {
|
||||
done();
|
||||
});
|
||||
unit.getChemicalData();
|
||||
});
|
||||
|
||||
it('gets salt cell config', done => {
|
||||
unit.on('saltCellConfig', () => { done() })
|
||||
unit.getSaltCellConfig()
|
||||
})
|
||||
unit.on('saltCellConfig', () => {
|
||||
done();
|
||||
});
|
||||
unit.getSaltCellConfig();
|
||||
});
|
||||
|
||||
it('gets version', done => {
|
||||
unit.on('version', () => { done() })
|
||||
unit.getVersion()
|
||||
})
|
||||
unit.on('version', () => {
|
||||
done();
|
||||
});
|
||||
unit.getVersion();
|
||||
});
|
||||
|
||||
it('sets circuit state', done => {
|
||||
unit.on('circuitStateChanged', () => { done() })
|
||||
unit.setCircuitState(0, circuit.id, circuit.state)
|
||||
})
|
||||
})
|
||||
unit.on('circuitStateChanged', () => {
|
||||
done();
|
||||
});
|
||||
unit.setCircuitState(0, circuit.id, circuit.state);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user