From b2439cd90cb631ba88a585bc2b83f88ff7fc60f6 Mon Sep 17 00:00:00 2001 From: Bruce Sheplan Date: Wed, 10 Jun 2020 08:05:32 -0500 Subject: [PATCH] Added SLAddClient / SLRemoveClient messages (#30) --- README.md | 17 +++++++++++++++++ index.js | 22 ++++++++++++++++++++++ messages/SLAddClient.js | 24 ++++++++++++++++++++++++ messages/SLPoolStatusMessage.js | 5 +++++ messages/SLRemoveClient.js | 24 ++++++++++++++++++++++++ messages/index.js | 2 ++ 6 files changed, 94 insertions(+) create mode 100644 messages/SLAddClient.js create mode 100644 messages/SLRemoveClient.js diff --git a/README.md b/README.md index d1630bc..b32582a 100755 --- a/README.md +++ b/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. +### 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. diff --git a/index.js b/index.js index 4ac668a..ab4dc2d 100644 --- a/index.js +++ b/index.js @@ -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'); diff --git a/messages/SLAddClient.js b/messages/SLAddClient.js new file mode 100644 index 0000000..4e24def --- /dev/null +++ b/messages/SLAddClient.js @@ -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; + } +}; diff --git a/messages/SLPoolStatusMessage.js b/messages/SLPoolStatusMessage.js index 58c7fd7..ac80522 100755 --- a/messages/SLPoolStatusMessage.js +++ b/messages/SLPoolStatusMessage.js @@ -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; + } }; diff --git a/messages/SLRemoveClient.js b/messages/SLRemoveClient.js new file mode 100644 index 0000000..3e5dea1 --- /dev/null +++ b/messages/SLRemoveClient.js @@ -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; + } +}; diff --git a/messages/index.js b/messages/index.js index 9823ce6..e9dc7f1 100644 --- a/messages/index.js +++ b/messages/index.js @@ -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;