Added SLAddClient / SLRemoveClient messages (#30)

This commit is contained in:
Bruce Sheplan
2020-06-10 08:05:32 -05:00
committed by GitHub
parent 71c606cb94
commit b2439cd90c
6 changed files with 94 additions and 0 deletions

View File

@ -245,6 +245,15 @@ Sets flow setting for a pump/circuit combination. See [`SLSetPumpFlow`](#slsetpu
Cancels any delays on the system. See [`SLCancelDelay`](#slcanceldelay) documentation. Emits the `cancelDelay` event when response is acknowledged.
### addClient(senderId)
Registers to receive updates from controller when something changes. Takes a random number `senderId` to identify the client. Emits the `poolStatus` event when something changes on the controller.
### removeClient(senderId)
No longer receive `poolStatus` messages from controller. Takes a random number `senderId` that should match a previously registered client with `addClient`.
### Events
* `loggedIn` - Indicates that a connection to the server has been established and the login process completed. `get` methods can be called once this event has been emitted.
@ -643,3 +652,11 @@ Passed as an argument to the emitted `setPumpFlow` event. The passed version is
## SLCancelDelay
Passed as an argument to the emitted `cancelDelay` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the set command.
## SLAddClient
Passed as an argument to the emitted `addClient` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the command.
## SLRemoveClient
Passed as an argument to the emitted `removeClient` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the command.

View File

@ -286,6 +286,16 @@ class UnitConnection extends EventEmitter {
this.client.write(new messages.SLCancelDelay().toBuffer());
}
addClient(senderId) {
debugUnit('sending add client command...');
this.client.write(new messages.SLAddClient(senderId).toBuffer());
}
removeClient(senderId) {
debugUnit('sending remove client command...');
this.client.write(new messages.SLRemoveClient(senderId).toBuffer());
}
onClientMessage(msg) {
debugUnit('received message of length %d', msg.length);
if (msg.length < 4) {
@ -379,6 +389,18 @@ class UnitConnection extends EventEmitter {
debugUnit(" it's a cancel delay ack");
this.emit('cancelDelay', new messages.SLCancelDelay());
break;
case messages.SLAddClient.getResponseId():
debugUnit(" it's an add client ack");
this.emit('addClient', new messages.SLCancelDelay());
break;
case messages.SLRemoveClient.getResponseId():
debugUnit(" it's a remove client ack");
this.emit('removeClient', new messages.SLCancelDelay());
break;
case messages.SLPoolStatusMessage.getAsyncResponseId():
debugUnit(" it's async pool status");
this.emit('poolStatus', new messages.SLPoolStatusMessage(msg));
break;
case 13:
debugUnit(" it's a login failure.");
this.emit('loginFailed');

24
messages/SLAddClient.js Normal file
View File

@ -0,0 +1,24 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12522;
exports.SLAddClient = class SLAddClient extends SLMessage {
constructor(senderId) {
super(0, MSG_ID);
this.senderId = senderId;
}
encode() {
this.writeInt32LE(0);
this.writeInt32LE(this.senderId);
super.encode();
}
static getResponseId() {
return MSG_ID + 1;
}
};

View File

@ -3,6 +3,7 @@
const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12526;
const ASYNC_MSG_ID = 12500;
const SPA_CIRCUIT_ID = 500;
const POOL_CIRCUIT_ID = 505;
@ -112,4 +113,8 @@ exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
static getResponseId() {
return MSG_ID + 1;
}
static getAsyncResponseId() {
return ASYNC_MSG_ID;
}
};

View File

@ -0,0 +1,24 @@
'use strict';
const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12524;
exports.SLRemoveClient = class SLRemoveClient extends SLMessage {
constructor(senderId) {
super(0, MSG_ID);
this.senderId = senderId;
}
encode() {
this.writeInt32LE(0);
this.writeInt32LE(this.senderId);
super.encode();
}
static getResponseId() {
return MSG_ID + 1;
}
};

View File

@ -23,3 +23,5 @@ exports.SLSetCircuitRuntimeById = require('./SLSetCircuitRuntimeById.js').SLSetC
exports.SLGetPumpStatus = require('./SLGetPumpStatus.js').SLGetPumpStatus;
exports.SLSetPumpFlow = require('./SLSetPumpFlow.js').SLSetPumpFlow;
exports.SLCancelDelay = require('./SLCancelDelay.js').SLCancelDelay;
exports.SLAddClient = require('./SLAddClient.js').SLAddClient;
exports.SLRemoveClient = require('./SLRemoveClient.js').SLRemoveClient;