From 0397e8ad8f348880751236b271a0d89f33ab0307 Mon Sep 17 00:00:00 2001 From: Parnic Date: Sat, 8 Feb 2020 15:33:13 -0600 Subject: [PATCH] Added support for controlling the salt cell generator output levels Closes #17 --- README.md | 23 ++++++++++++++++---- index.js | 8 +++++++ messages/SLSetSaltCellConfigMessage.js | 29 ++++++++++++++++++++++++++ messages/index.js | 1 + 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 messages/SLSetSaltCellConfigMessage.js diff --git a/README.md b/README.md index 874fbe1..34497ba 100755 --- a/README.md +++ b/README.md @@ -206,6 +206,10 @@ Sends a lighting command. See [`SLLightControlMessage`](#sllightcontrolmessage) Note that better/more complete handling of lighting is desired, but I have yet to find all the commands I need to implement to make that happen. This currently sends each command to all lights and there is no ability to send to an individual light. Pull requests adding more functionality here would be most welcome. +### setSaltCellOutput(controllerId, poolOutput, spaOutput) + +Sets the salt cell's output levels. See [`SLSetSaltCellConfigMessage`](#slsetsaltcellconfigmessage) documentation for argument values. Emits the `setSaltCellConfig` event when response is acknowledged. + ### 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. @@ -320,13 +324,24 @@ Passed as an argument to the emitted `saltCellConfig` event handler. ### Properties * `installed` - boolean indicating whether a salt cell is installed or not -* `status` - integer -* `level1` - integer -* `level2` - integer +* `status` - integer bitmask +* `level1` - integer indicating the output level of the salt cell for the pool. I believe this operates on a 0-100 scale +* `level2` - integer indicating the output level of the salt cell for the spa. I believe this operates on a 0-100 scale * `salt` - integer indicating salt level in parts-per-million -* `flags` - integer +* `flags` - integer bitmask * `superChlorTimer` - integer +## SLSetSaltCellConfigMessage + +Passed as an argument to the emitted `setSaltCellConfig` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the set command. + +### Properties + +* `controllerId` - integer indicating the ID of the controller to send this command to. + * Note that while `SLControllerConfigMessage` includes a controllerId, this ID, in my experience, should always be 0. +* `poolOutput` - integer indicating the output level of the salt cell for the pool. I believe this operates on a 0-100 scale. +* `spaOutput` - integer indicating the output level of the salt cell for the spa. I believe this operates on a 0-100 scale. + ## SLControllerConfigMessage Passed as an argument to the emitted `controllerConfig` event handler. diff --git a/index.js b/index.js index 7d851e6..b28960e 100644 --- a/index.js +++ b/index.js @@ -218,6 +218,10 @@ class UnitConnection extends EventEmitter { this.client.write(new messages.SLLightControlMessage(controllerId, command).toBuffer()); } + setSaltCellOutput(controllerId, poolOutput, spaOutput) { + this.client.write(new messages.SLSetSaltCellConfigMessage(controllerId, poolOutput, spaOutput).toBuffer()); + } + onClientMessage(msg) { // console.log('received message of length ' + msg.length); if (msg.length < 4) { @@ -271,6 +275,10 @@ class UnitConnection extends EventEmitter { // console.log(" it's a light control ack"); this.emit('sentLightCommand', new messages.SLLightControlMessage()); break; + case messages.SLSetSaltCellConfigMessage.getResponseId(): + // console.log(" it's a set salt cell config ack"); + this.emit('setSaltCellConfig', new messages.SLSetSaltCellConfigMessage()); + break; case 13: // console.log(" it's a login failure."); this.emit('loginFailed'); diff --git a/messages/SLSetSaltCellConfigMessage.js b/messages/SLSetSaltCellConfigMessage.js new file mode 100644 index 0000000..b95f4d7 --- /dev/null +++ b/messages/SLSetSaltCellConfigMessage.js @@ -0,0 +1,29 @@ +'use strict'; + +const SLMessage = require('./SLMessage.js').SLMessage; + +const MSG_ID = 12576; + +exports.SLSetSaltCellConfigMessage = class SLSetSaltCellConfigMessage extends SLMessage { + constructor(controllerIndex, poolOutput, spaOutput) { + super(0, MSG_ID); + + this.controllerIndex = controllerIndex; + this.poolOutput = poolOutput; + this.spaOutput = spaOutput; + } + + encode() { + this.writeInt32LE(this.controllerIndex || 0); + this.writeInt32LE(this.poolOutput || 0); + this.writeInt32LE(this.spaOutput || 0); + this.writeInt32LE(0); + this.writeInt32LE(0); + + super.encode(); + } + + static getResponseId() { + return MSG_ID + 1; + } +}; diff --git a/messages/index.js b/messages/index.js index d099248..de9da0b 100644 --- a/messages/index.js +++ b/messages/index.js @@ -12,3 +12,4 @@ exports.SLGetGatewayDataMessage = require('./SLGetGatewayDataMessage.js').SLGetG exports.SLSetHeatSetPointMessage = require('./SLSetHeatSetPoint.js').SLSetHeatSetPoint; exports.SLSetHeatModeMessage = require('./SLSetHeatMode.js').SLSetHeatMode; exports.SLLightControlMessage = require('./SLLightControl.js').SLLightControl; +exports.SLSetSaltCellConfigMessage = require('./SLSetSaltCellConfigMessage.js').SLSetSaltCellConfigMessage;