Added ability to set circuit state
This allows for, for example, turning on a water feature or changing pool/spa active status.
This commit is contained in:
8
index.js
8
index.js
@ -127,6 +127,10 @@ class UnitConnection extends EventEmitter {
|
|||||||
this.client.write(new messages.SLVersionMessage().toBuffer());
|
this.client.write(new messages.SLVersionMessage().toBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCircuitState(controllerId, circuitId, circuitState) {
|
||||||
|
this.client.write(new messages.SLSetCircuitStateMessage(controllerId, circuitId, circuitState).toBuffer());
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@ -163,6 +167,10 @@ class UnitConnection extends EventEmitter {
|
|||||||
//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():
|
||||||
|
//console.log(" it's circuit toggle ack");
|
||||||
|
this.emit('circuitStateChanged', new messages.SLSetCircuitStateMessage());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
//console.log(" it's unknown. type: " + msgType);
|
//console.log(" it's unknown. type: " + msgType);
|
||||||
break;
|
break;
|
||||||
|
6
messages/SLMessage.js
Executable file → Normal file
6
messages/SLMessage.js
Executable file → Normal file
@ -10,6 +10,8 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toBuffer() {
|
toBuffer() {
|
||||||
|
this.encode();
|
||||||
|
|
||||||
if (this._wroteSize === false) {
|
if (this._wroteSize === false) {
|
||||||
this.insertInt32LE(this.length - 4, 4);
|
this.insertInt32LE(this.length - 4, 4);
|
||||||
this._wroteSize = true;
|
this._wroteSize = true;
|
||||||
@ -54,4 +56,8 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
|
|||||||
this.messageId = this.readUInt16LE();
|
this.messageId = this.readUInt16LE();
|
||||||
this.dataLength = this.readInt32LE();
|
this.dataLength = this.readInt32LE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
encode() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
25
messages/SLSetCircuitStateMessage.js
Normal file
25
messages/SLSetCircuitStateMessage.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||||
|
|
||||||
|
const MSG_ID = 12530;
|
||||||
|
|
||||||
|
exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMessage {
|
||||||
|
constructor(controllerId, circuitId, circuitState) {
|
||||||
|
super(0, MSG_ID);
|
||||||
|
|
||||||
|
this.controllerId = controllerId;
|
||||||
|
this.circuitId = circuitId;
|
||||||
|
this.circuitState = circuitState;
|
||||||
|
}
|
||||||
|
|
||||||
|
encode() {
|
||||||
|
this.writeInt32LE(this.controllerId || 0);
|
||||||
|
this.writeInt32LE(this.circuitId || 0);
|
||||||
|
this.writeInt32LE(this.circuitState || 0);
|
||||||
|
|
||||||
|
super.encode();
|
||||||
|
}
|
||||||
|
|
||||||
|
static getResponseId() {
|
||||||
|
return MSG_ID + 1;
|
||||||
|
}
|
||||||
|
}
|
1
messages/index.js
Executable file → Normal file
1
messages/index.js
Executable file → Normal file
@ -5,3 +5,4 @@ exports.SLLoginMessage = require("./SLLoginMessage.js").SLLoginMessage;
|
|||||||
exports.SLChemDataMessage = require("./SLChemDataMessage.js").SLChemDataMessage;
|
exports.SLChemDataMessage = require("./SLChemDataMessage.js").SLChemDataMessage;
|
||||||
exports.SLSaltCellConfigMessage = require("./SLSaltCellConfigMessage.js").SLSaltCellConfigMessage;
|
exports.SLSaltCellConfigMessage = require("./SLSaltCellConfigMessage.js").SLSaltCellConfigMessage;
|
||||||
exports.SLVersionMessage = require("./SLVersionMessage.js").SLVersionMessage;
|
exports.SLVersionMessage = require("./SLVersionMessage.js").SLVersionMessage;
|
||||||
|
exports.SLSetCircuitStateMessage = require("./SLSetCircuitStateMessage.js").SLSetCircuitStateMessage;
|
||||||
|
Reference in New Issue
Block a user