Added SLAddClient / SLRemoveClient messages (#30)
This commit is contained in:
17
README.md
17
README.md
@ -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.
|
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
|
### 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.
|
* `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
|
## 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.
|
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.
|
||||||
|
22
index.js
22
index.js
@ -286,6 +286,16 @@ class UnitConnection extends EventEmitter {
|
|||||||
this.client.write(new messages.SLCancelDelay().toBuffer());
|
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) {
|
onClientMessage(msg) {
|
||||||
debugUnit('received message of length %d', msg.length);
|
debugUnit('received message of length %d', msg.length);
|
||||||
if (msg.length < 4) {
|
if (msg.length < 4) {
|
||||||
@ -379,6 +389,18 @@ class UnitConnection extends EventEmitter {
|
|||||||
debugUnit(" it's a cancel delay ack");
|
debugUnit(" it's a cancel delay ack");
|
||||||
this.emit('cancelDelay', new messages.SLCancelDelay());
|
this.emit('cancelDelay', new messages.SLCancelDelay());
|
||||||
break;
|
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:
|
case 13:
|
||||||
debugUnit(" it's a login failure.");
|
debugUnit(" it's a login failure.");
|
||||||
this.emit('loginFailed');
|
this.emit('loginFailed');
|
||||||
|
24
messages/SLAddClient.js
Normal file
24
messages/SLAddClient.js
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
@ -3,6 +3,7 @@
|
|||||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||||
|
|
||||||
const MSG_ID = 12526;
|
const MSG_ID = 12526;
|
||||||
|
const ASYNC_MSG_ID = 12500;
|
||||||
|
|
||||||
const SPA_CIRCUIT_ID = 500;
|
const SPA_CIRCUIT_ID = 500;
|
||||||
const POOL_CIRCUIT_ID = 505;
|
const POOL_CIRCUIT_ID = 505;
|
||||||
@ -112,4 +113,8 @@ exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
|
|||||||
static getResponseId() {
|
static getResponseId() {
|
||||||
return MSG_ID + 1;
|
return MSG_ID + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getAsyncResponseId() {
|
||||||
|
return ASYNC_MSG_ID;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
24
messages/SLRemoveClient.js
Normal file
24
messages/SLRemoveClient.js
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
@ -23,3 +23,5 @@ exports.SLSetCircuitRuntimeById = require('./SLSetCircuitRuntimeById.js').SLSetC
|
|||||||
exports.SLGetPumpStatus = require('./SLGetPumpStatus.js').SLGetPumpStatus;
|
exports.SLGetPumpStatus = require('./SLGetPumpStatus.js').SLGetPumpStatus;
|
||||||
exports.SLSetPumpFlow = require('./SLSetPumpFlow.js').SLSetPumpFlow;
|
exports.SLSetPumpFlow = require('./SLSetPumpFlow.js').SLSetPumpFlow;
|
||||||
exports.SLCancelDelay = require('./SLCancelDelay.js').SLCancelDelay;
|
exports.SLCancelDelay = require('./SLCancelDelay.js').SLCancelDelay;
|
||||||
|
exports.SLAddClient = require('./SLAddClient.js').SLAddClient;
|
||||||
|
exports.SLRemoveClient = require('./SLRemoveClient.js').SLRemoveClient;
|
||||||
|
Reference in New Issue
Block a user