Add support for specifying the sender id to each call

This parameter is optional, so compatibility shouldn't be affected. Each SLMessage can set its own sender ID which is present on the returned message. This allows callers to fire multiple requests at once, even of the same type, while being able to identify which response went with which request. If not specified, the default value is 0.

Also went ahead and documented some of the helper functions present on SLMessage (so, available on all message instances).

Finally, since I was in and messing with each message anyway, I simplified and removed some repeated code from each derived message and had it call into the super to take advantage of shared decoding functionality.

The lambdas ("arrow functions") in test functions were removed per advice from Mocha's documentation where the implicit `this` rebinding can apparently cause problems. This should probably have been its own commit, but, again, I was already in there messing with stuff, so...oh well.

Closes #43
This commit is contained in:
2020-08-11 22:20:58 -05:00
parent ab36d17a38
commit 89b8775ce3
27 changed files with 254 additions and 267 deletions

123
README.md
View File

@ -178,87 +178,87 @@ client.connect();
Closes the connection. Closes the connection.
#### getVersion() #### getVersion(senderId)
Requests the system version string from the connected unit. Emits the `version` event when the response comes back. Requests the system version string from the connected unit. Emits the `version` event when the response comes back. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### getPoolStatus() #### getPoolStatus(senderId)
Requests pool status from the connected unit. Emits the `poolStatus` event when the response comes back. Requests pool status from the connected unit. Emits the `poolStatus` event when the response comes back. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### getChemicalData() #### getChemicalData(senderId)
Requests chemical data from the connected unit (may require an IntelliChem or similar). Emits the `chemicalData` event when the response comes back. Requests chemical data from the connected unit (may require an IntelliChem or similar). Emits the `chemicalData` event when the response comes back. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### getSaltCellConfig() #### getSaltCellConfig(senderId)
Requests salt cell status/configuration from the connected unit (requires an IntelliChlor or compatible salt cell). Emits the `saltCellConfig` event when the response comes back. Requests salt cell status/configuration from the connected unit (requires an IntelliChlor or compatible salt cell). Emits the `saltCellConfig` event when the response comes back. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### getControllerConfig() #### getControllerConfig(senderId)
Requests controller configuration from the connected unit. Emits the `controllerConfig` event when the response comes back. Requests controller configuration from the connected unit. Emits the `controllerConfig` event when the response comes back. `senderId` isan optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### setCircuitState(controllerId, circuitId, circuitState) #### setCircuitState(controllerId, circuitId, circuitState, senderId)
Activates or deactivates a circuit. See [`SLSetCircuitStateMessage`](#slsetcircuitstatemessage) documentation for argument values. Emits the `circuitStateChanged` event when response is acknowledged. Activates or deactivates a circuit. See [`SLSetCircuitStateMessage`](#slsetcircuitstatemessage) documentation for argument values. Emits the `circuitStateChanged` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### setSetPoint(controllerId, bodyType, temperature) #### setSetPoint(controllerId, bodyType, temperature, senderId)
Sets the heating setpoint for any body. See [`SLSetHeatSetPointMessage`](#slsetheatsetpointmessage) documentation for argument values. Emits the `setPointChanged` event when response is acknowledged. Sets the heating setpoint for any body. See [`SLSetHeatSetPointMessage`](#slsetheatsetpointmessage) documentation for argument values. Emits the `setPointChanged` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### setHeatMode(controllerId, bodyType, heatMode) #### setHeatMode(controllerId, bodyType, heatMode, senderId)
Sets the preferred heat mode. See [`SLSetHeatModeMessage`](#slsetheatmodemessage) documentation for argument values. Emits the `heatModeChanged` event when response is acknowledged. Sets the preferred heat mode. See [`SLSetHeatModeMessage`](#slsetheatmodemessage) documentation for argument values. Emits the `heatModeChanged` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### sendLightCommand(controllerId, command) #### sendLightCommand(controllerId, command, senderId)
Sends a lighting command. See [`SLLightControlMessage`](#sllightcontrolmessage) documentation for argument values. Emits the `sentLightCommand` event when response is acknowledged. Sends a lighting command. See [`SLLightControlMessage`](#sllightcontrolmessage) documentation for argument values. Emits the `sentLightCommand` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
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. 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) #### setSaltCellOutput(controllerId, poolOutput, spaOutput, senderId)
Sets the salt cell's output levels. See [`SLSetSaltCellConfigMessage`](#slsetsaltcellconfigmessage) documentation for argument values. Emits the `setSaltCellConfig` event when response is acknowledged. Sets the salt cell's output levels. See [`SLSetSaltCellConfigMessage`](#slsetsaltcellconfigmessage) documentation for argument values. Emits the `setSaltCellConfig` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### getScheduleData(scheduleType) #### getScheduleData(scheduleType, senderId)
Retrieves a list of schedule events of the specified type. See [`SLGetScheduleData`](#slgetscheduledata) documentation for argument values. Emits the `getScheduleData` event when response is acknowledged. Retrieves a list of schedule events of the specified type. See [`SLGetScheduleData`](#slgetscheduledata) documentation for argument values. Emits the `getScheduleData` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### addNewScheduleEvent(scheduleType) #### addNewScheduleEvent(scheduleType, senderId)
Adds a new event to the specified schedule type. See [`SLAddNewScheduleEvent`](#sladdnewscheduleevent) documentation for argument values. Emits the `addNewScheduleEvent` event when response is acknowledged. Adds a new event to the specified schedule type. See [`SLAddNewScheduleEvent`](#sladdnewscheduleevent) documentation for argument values. Emits the `addNewScheduleEvent` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### deleteScheduleEventById(scheduleId) #### deleteScheduleEventById(scheduleId, senderId)
Deletes a scheduled event with specified id. See [`SLDeleteScheduleEventById`](#sldeletescheduleeventbyid) documentation for argument values. Emits the `deleteScheduleById` event when response is acknowledged. Deletes a scheduled event with specified id. See [`SLDeleteScheduleEventById`](#sldeletescheduleeventbyid) documentation for argument values. Emits the `deleteScheduleById` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) #### setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint, senderId)
Configures a schedule event. See [`SLSetScheduleEventById`](#slsetscheduleeventbyid) documentation for argument values. Emits the `setScheduleEventById` event when response is acknowledged. Configures a schedule event. See [`SLSetScheduleEventById`](#slsetscheduleeventbyid) documentation for argument values. Emits the `setScheduleEventById` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### setCircuitRuntimebyId(circuitId, runTime) #### setCircuitRuntimebyId(circuitId, runTime, senderId)
Configures default run-time of a circuit, usually referred to as the 'egg timer'. This also applies to 'run-once' programs as this will set the length of the program. See [`SLSetCircuitRuntimeById`](#slsetcircuitruntimebyid) documentation for argument values. Emits the `setCircuitRuntimeById` event when response is acknowledged. Configures default run-time of a circuit, usually referred to as the 'egg timer'. This also applies to 'run-once' programs as this will set the length of the program. See [`SLSetCircuitRuntimeById`](#slsetcircuitruntimebyid) documentation for argument values. Emits the `setCircuitRuntimeById` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### getPumpStatus(pumpId) #### getPumpStatus(pumpId, senderId)
Gets information about the specified pump. See [`SLGetPumpStatus`](#slgetpumpstatus) documentation for argument values. Emits the `getPumpStatus` event when response is acknowledged. Gets information about the specified pump. See [`SLGetPumpStatus`](#slgetpumpstatus) documentation for argument values. Emits the `getPumpStatus` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### setPumpFlow(pumpId, circuitId, setPoint, isRPMs) #### setPumpFlow(pumpId, circuitId, setPoint, isRPMs, senderId)
Sets flow setting for a pump/circuit combination. See [`SLSetPumpFlow`](#slsetpumpflow) documentation for argument values. Emits the `setPumpFlow` event when response is acknowledged. Sets flow setting for a pump/circuit combination. See [`SLSetPumpFlow`](#slsetpumpflow) documentation for argument values. Emits the `setPumpFlow` event when response is acknowledged. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### cancelDelay() #### cancelDelay(senderId)
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. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### addClient(senderId) #### addClient(clientId, 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. Registers to receive updates from controller when something changes. Takes a random number `clientId` to identify the client. Emits the `poolStatus` event when something changes on the controller. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
#### removeClient(senderId) #### removeClient(clientId, senderId)
No longer receive `poolStatus` messages from controller. Takes a random number `senderId` that should match a previously registered client with `addClient`. No longer receive `poolStatus` messages from controller. Takes a random number `clientId` that should match a previously registered client with `addClient`. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
### Events ### Events
@ -295,6 +295,49 @@ No longer receive `poolStatus` messages from controller. Takes a random number `
* `gatewaySubtype` - byte * `gatewaySubtype` - byte
* `gatewayName` - string representing the server's name. Will be in the format Pentair: xx-xx-xx * `gatewayName` - string representing the server's name. Will be in the format Pentair: xx-xx-xx
### All messages
Information about features common to all the below SL Message types.
#### decodeTime(time)
Interprets a time integer recorded as minutes past midnight and returns the ScreenLogic string representation of it in 24-hour time.
#### encodeTime(time)
Interprets the string representing 24-hour time and returns an integer of minutes past midnight.
#### decodeDayMask(mask)
Converts a day mask from, for example, `SLGetScheduleData`'s events[idx].days property into a `DAY_VALUES` array for ease of use.
#### encodeDayMask(days)
Converts an array of DAY_VALUES into a mask used by, for example, `SLGetScheduleData`'s events[idx].days property.
#### getDayValue(dayName)
Returns the value of a given `DAY_VALUES` day name.
`DAY_VALUES` is defined as the following array for simplicity of checking whether a specific day is set in a mask:
```js
const DAY_VALUES = [
['Mon', 0x1 ],
['Tue', 0x2 ],
['Wed', 0x4 ],
['Thu', 0x8 ],
['Fri', 0x10 ],
['Sat', 0x20 ],
['Sun', 0x40 ],
];
```
#### Properties
* `senderId` - an integer matching whatever was passed as the `senderId` argument when making the initial request (default 0)
* `messageId` - an integer indicating the ScreenLogic ID for this message
### SLVersionMessage ### SLVersionMessage
Passed as an argument to the emitted `version` event handler. Passed as an argument to the emitted `version` event handler.

126
index.js
View File

@ -191,110 +191,110 @@ class UnitConnection extends EventEmitter {
this.client.write(new messages.SLLoginMessage(password).toBuffer()); this.client.write(new messages.SLLoginMessage(password).toBuffer());
} }
getPoolStatus() { getPoolStatus(senderId) {
debugUnit('sending pool status query...'); debugUnit('[%d] sending pool status query...', senderId || 0);
this.client.write(new messages.SLPoolStatusMessage().toBuffer()); this.client.write(new messages.SLPoolStatusMessage(null, senderId).toBuffer());
} }
getControllerConfig() { getControllerConfig(senderId) {
debugUnit('sending controller config query...'); debugUnit('[%d] sending controller config query...', senderId || 0);
this.client.write(new messages.SLControllerConfigMessage().toBuffer()); this.client.write(new messages.SLControllerConfigMessage(null, senderId).toBuffer());
} }
getChemicalData() { getChemicalData(senderId) {
debugUnit('sending chemical data query...'); debugUnit('[%d] sending chemical data query...', senderId || 0);
this.client.write(new messages.SLChemDataMessage().toBuffer()); this.client.write(new messages.SLChemDataMessage(null, senderId).toBuffer());
} }
getSaltCellConfig() { getSaltCellConfig(senderId) {
debugUnit('sending salt cell config query...'); debugUnit('[%d] sending salt cell config query...', senderId || 0);
this.client.write(new messages.SLSaltCellConfigMessage().toBuffer()); this.client.write(new messages.SLSaltCellConfigMessage(null, senderId).toBuffer());
} }
getVersion() { getVersion(senderId) {
debugUnit('sending version query...'); debugUnit('[%d] sending version query...', senderId || 0);
this.client.write(new messages.SLVersionMessage().toBuffer()); this.client.write(new messages.SLVersionMessage(null, senderId).toBuffer());
} }
getEquipmentConfiguration() { getEquipmentConfiguration(senderId) {
debugUnit('sending equipment configuration query...'); debugUnit('[%d] sending equipment configuration query...', senderId || 0);
this.client.write(new messages.SLEquipmentConfigurationMessage().toBuffer()); this.client.write(new messages.SLEquipmentConfigurationMessage(null, senderId).toBuffer());
} }
setCircuitState(controllerId, circuitId, circuitState) { setCircuitState(controllerId, circuitId, circuitState, senderId) {
debugUnit('sending set circuit state command: controllerId: %d, circuitId: %d, circuitState: %d...', controllerId, circuitId, circuitState); debugUnit('[%d] sending set circuit state command: controllerId: %d, circuitId: %d, circuitState: %d...', senderId || 0, controllerId, circuitId, circuitState);
this.client.write(new messages.SLSetCircuitStateMessage(controllerId, circuitId, circuitState).toBuffer()); this.client.write(new messages.SLSetCircuitStateMessage(controllerId, circuitId, circuitState, senderId).toBuffer());
} }
setSetPoint(controllerId, bodyType, temperature) { setSetPoint(controllerId, bodyType, temperature, senderId) {
debugUnit('sending set setpoint command: controllerId: %d, bodyType: %d, temperature: %d...', controllerId, bodyType, temperature); debugUnit('[%d] sending set setpoint command: controllerId: %d, bodyType: %d, temperature: %d...', senderId || 0, controllerId, bodyType, temperature);
this.client.write(new messages.SLSetHeatSetPointMessage(controllerId, bodyType, temperature).toBuffer()); this.client.write(new messages.SLSetHeatSetPointMessage(controllerId, bodyType, temperature, senderId).toBuffer());
} }
setHeatMode(controllerId, bodyType, heatMode) { setHeatMode(controllerId, bodyType, heatMode, senderId) {
debugUnit('sending set heatmode command: controllerId: %d, bodyType: %d, heatMode: %d...', controllerId, bodyType, heatMode); debugUnit('[%d] sending set heatmode command: controllerId: %d, bodyType: %d, heatMode: %d...', senderId || 0, controllerId, bodyType, heatMode);
this.client.write(new messages.SLSetHeatModeMessage(controllerId, bodyType, heatMode).toBuffer()); this.client.write(new messages.SLSetHeatModeMessage(controllerId, bodyType, heatMode, senderId).toBuffer());
} }
sendLightCommand(controllerId, command) { sendLightCommand(controllerId, command, senderId) {
debugUnit('sending light command: controllerId: %d, command: %d...', controllerId, command); debugUnit('[%d] sending light command: controllerId: %d, command: %d...', senderId || 0, controllerId, command);
this.client.write(new messages.SLLightControlMessage(controllerId, command).toBuffer()); this.client.write(new messages.SLLightControlMessage(controllerId, command, senderId).toBuffer());
} }
setSaltCellOutput(controllerId, poolOutput, spaOutput) { setSaltCellOutput(controllerId, poolOutput, spaOutput, senderId) {
debugUnit('sending set saltcell output command: controllerId: %d, poolOutput: %d, spaOutput: %d...', controllerId, poolOutput, spaOutput); debugUnit('[%d] sending set saltcell output command: controllerId: %d, poolOutput: %d, spaOutput: %d...', senderId || 0, controllerId, poolOutput, spaOutput);
this.client.write(new messages.SLSetSaltCellConfigMessage(controllerId, poolOutput, spaOutput).toBuffer()); this.client.write(new messages.SLSetSaltCellConfigMessage(controllerId, poolOutput, spaOutput, senderId).toBuffer());
} }
getScheduleData(scheduleType) { getScheduleData(scheduleType, senderId) {
debugUnit('sending set schedule data query for scheduleType: %d...', scheduleType); debugUnit('[%d] sending set schedule data query for scheduleType: %d...', senderId || 0, scheduleType);
this.client.write(new messages.SLGetScheduleData(null, scheduleType).toBuffer()); this.client.write(new messages.SLGetScheduleData(null, scheduleType, senderId).toBuffer());
} }
addNewScheduleEvent(scheduleType) { addNewScheduleEvent(scheduleType, senderId) {
debugUnit('sending add new schedule event command for scheduleType: %d...', scheduleType); debugUnit('[%d] sending add new schedule event command for scheduleType: %d...', senderId || 0, scheduleType);
this.client.write(new messages.SLAddNewScheduleEvent(null, scheduleType).toBuffer()); this.client.write(new messages.SLAddNewScheduleEvent(null, scheduleType, senderId).toBuffer());
} }
deleteScheduleEventById(scheduleId) { deleteScheduleEventById(scheduleId, senderId) {
debugUnit('sending delete schedule event command for scheduleId: %d...', scheduleId); debugUnit('[%d] sending delete schedule event command for scheduleId: %d...', senderId || 0, scheduleId);
this.client.write(new messages.SLDeleteScheduleEventById(scheduleId).toBuffer()); this.client.write(new messages.SLDeleteScheduleEventById(scheduleId, senderId).toBuffer());
} }
// todo: should this just accept a SLSetScheduleEventById message instead of all these args? // todo: should this just accept a SLSetScheduleEventById message instead of all these args?
setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) { setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint, senderId) {
debugUnit('sending set schedule event command for scheduleId: %d, circuitId: %d, startTime: %d, stopTime: %d, dayMask: %d, flags: %d, heatCmd: %d, heatSetPoint: %d...', scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint); debugUnit('[%d] sending set schedule event command for scheduleId: %d, circuitId: %d, startTime: %d, stopTime: %d, dayMask: %d, flags: %d, heatCmd: %d, heatSetPoint: %d...', senderId || 0, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint);
this.client.write(new messages.SLSetScheduleEventById(null, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint).toBuffer()); this.client.write(new messages.SLSetScheduleEventById(null, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint, senderId).toBuffer());
} }
setCircuitRuntimebyId(circuitId, runTime) { setCircuitRuntimebyId(circuitId, runTime, senderId) {
debugUnit('sending set circuit runtime command for circuitId: %d, runTime: %d...', circuitId, runTime); debugUnit('[%d] sending set circuit runtime command for circuitId: %d, runTime: %d...', senderId || 0, circuitId, runTime);
this.client.write(new messages.SLSetCircuitRuntimeById(circuitId, runTime).toBuffer()); this.client.write(new messages.SLSetCircuitRuntimeById(circuitId, runTime, senderId).toBuffer());
} }
getPumpStatus(pumpId) { getPumpStatus(pumpId, senderId) {
debugUnit('sending get pump status command for pumpId: %d...', pumpId); debugUnit('[%d] sending get pump status command for pumpId: %d...', senderId || 0, pumpId);
this.client.write(new messages.SLGetPumpStatus(null, pumpId).toBuffer()); this.client.write(new messages.SLGetPumpStatus(null, pumpId, senderId).toBuffer());
} }
setPumpFlow(pumpId, circuitId, setPoint, isRPMs) { setPumpFlow(pumpId, circuitId, setPoint, isRPMs, senderId) {
debugUnit('sending set pump flow command for pumpId: %d, circuitId: %d, setPoint: %d, isRPMs: %d...', pumpId, circuitId, setPoint, isRPMs); debugUnit('[%d] sending set pump flow command for pumpId: %d, circuitId: %d, setPoint: %d, isRPMs: %d...', senderId || 0, pumpId, circuitId, setPoint, isRPMs);
this.client.write(new messages.SLSetPumpFlow(pumpId, circuitId, setPoint, isRPMs).toBuffer()); this.client.write(new messages.SLSetPumpFlow(pumpId, circuitId, setPoint, isRPMs, senderId).toBuffer());
} }
cancelDelay() { cancelDelay(senderId) {
debugUnit('sending cancel delay command...'); debugUnit('[%d] sending cancel delay command...', senderId || 0);
this.client.write(new messages.SLCancelDelay().toBuffer()); this.client.write(new messages.SLCancelDelay(senderId).toBuffer());
} }
addClient(senderId) { addClient(clientId, senderId) {
debugUnit('sending add client command...'); debugUnit('[%d] sending add client command, clientId %d...', senderId || 0, clientId);
this.client.write(new messages.SLAddClient(senderId).toBuffer()); this.client.write(new messages.SLAddClient(clientId, senderId).toBuffer());
} }
removeClient(senderId) { removeClient(clientId, senderId) {
debugUnit('sending remove client command...'); debugUnit('[%d] sending remove client command, clientId %d...', senderId || 0, clientId);
this.client.write(new messages.SLRemoveClient(senderId).toBuffer()); this.client.write(new messages.SLRemoveClient(clientId, senderId).toBuffer());
} }
onClientMessage(msg) { onClientMessage(msg) {

View File

@ -5,15 +5,15 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12522; const MSG_ID = 12522;
exports.SLAddClient = class SLAddClient extends SLMessage { exports.SLAddClient = class SLAddClient extends SLMessage {
constructor(senderId) { constructor(clientId, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.senderId = senderId; this.clientId = clientId;
} }
encode() { encode() {
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(this.senderId); this.writeInt32LE(this.clientId);
super.encode(); super.encode();
} }

View File

@ -6,23 +6,15 @@ const MSG_ID = 12544;
exports.SLAddNewScheduleEvent = class SLAddNewScheduleEvent extends SLMessage { exports.SLAddNewScheduleEvent = class SLAddNewScheduleEvent extends SLMessage {
constructor(buf, scheduleType) { constructor(buf, scheduleType, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size); } else {
super(senderId, MSG_ID);
if (!buf) {
// console.log('Requested Schedule type = ', scheduleType);
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(scheduleType); this.writeInt32LE(scheduleType);
} else {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
} }
} }

View File

@ -5,9 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12580; const MSG_ID = 12580;
exports.SLCancelDelay = class SLCancelDelay extends SLMessage { exports.SLCancelDelay = class SLCancelDelay extends SLMessage {
constructor() { constructor(senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
} }
encode() { encode() {

View File

@ -5,20 +5,14 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12592; const MSG_ID = 12592;
exports.SLChemDataMessage = class SLChemDataMessage extends SLMessage { exports.SLChemDataMessage = class SLChemDataMessage extends SLMessage {
constructor(buf) { constructor(buf, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size);
if (!buf) {
this.writeInt32LE(0); // controller index
} else { } else {
this._wroteSize = true; super(senderId, MSG_ID);
this.writeBuffer(buf, 0);
this.decode(); this.writeInt32LE(0); // controller index
} }
} }

View File

@ -13,21 +13,15 @@ const CIRCUIT_NAME_VALUE_MAP = [
]; ];
exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMessage { exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMessage {
constructor(buf) { constructor(buf, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size);
if (!buf) {
this.writeInt32LE(0);
this.writeInt32LE(0);
} else { } else {
this._wroteSize = true; super(senderId, MSG_ID);
this.writeBuffer(buf, 0);
this.decode(); this.writeInt32LE(0);
this.writeInt32LE(0);
} }
} }

View File

@ -5,8 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12546; const MSG_ID = 12546;
exports.SLDeleteScheduleEventById = class SLDeleteScheduleEventById extends SLMessage { exports.SLDeleteScheduleEventById = class SLDeleteScheduleEventById extends SLMessage {
constructor(scheduleId) { constructor(scheduleId, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(scheduleId); this.writeInt32LE(scheduleId);

View File

@ -5,21 +5,15 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12566; const MSG_ID = 12566;
exports.SLEquipmentConfigurationMessage = class SLEquipmentConfigurationMessage extends SLMessage { exports.SLEquipmentConfigurationMessage = class SLEquipmentConfigurationMessage extends SLMessage {
constructor(buf) { constructor(buf, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size);
if (!buf) {
this.writeInt32LE(0);
this.writeInt32LE(0);
} else { } else {
this._wroteSize = true; super(senderId, MSG_ID);
this.writeBuffer(buf, 0);
this.decode(); this.writeInt32LE(0);
this.writeInt32LE(0);
} }
} }

View File

@ -5,21 +5,15 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12584; const MSG_ID = 12584;
exports.SLGetPumpStatus = class SLGetPumpStatus extends SLMessage { exports.SLGetPumpStatus = class SLGetPumpStatus extends SLMessage {
constructor(buf, pumpId) { constructor(buf, pumpId, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size); } else {
super(senderId, MSG_ID);
if (!buf) {
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(pumpId); this.writeInt32LE(pumpId);
} else {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
} }
} }

View File

@ -5,22 +5,15 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12542; const MSG_ID = 12542;
exports.SLGetScheduleData = class SLGetScheduleData extends SLMessage { exports.SLGetScheduleData = class SLGetScheduleData extends SLMessage {
constructor(buf, scheduleType) { constructor(buf, scheduleType, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size); } else {
super(senderId, MSG_ID);
if (!buf) {
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(scheduleType); this.writeInt32LE(scheduleType);
} else {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
} }
} }

View File

@ -5,8 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12556; const MSG_ID = 12556;
exports.SLLightControl = class SLLightControl extends SLMessage { exports.SLLightControl = class SLLightControl extends SLMessage {
constructor(controllerIndex, command) { constructor(controllerIndex, command, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.controllerIndex = controllerIndex; this.controllerIndex = controllerIndex;
this.command = command; this.command = command;

View File

@ -27,7 +27,7 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
this.writeUInt16LE(messageId || 0); this.writeUInt16LE(messageId || 0);
this._wroteSize = false; this._wroteSize = false;
} else if (senderId) { } else if (typeof senderId === 'object') {
this._wroteSize = true; this._wroteSize = true;
var buffer = senderId; var buffer = senderId;
this.writeBuffer(buffer, 0); this.writeBuffer(buffer, 0);

View File

@ -9,20 +9,14 @@ const SPA_CIRCUIT_ID = 500;
const POOL_CIRCUIT_ID = 505; const POOL_CIRCUIT_ID = 505;
exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage { exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
constructor(buf) { constructor(buf, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size);
if (!buf) {
this.writeInt32LE(0);
} else { } else {
this._wroteSize = true; super(senderId, MSG_ID);
this.writeBuffer(buf, 0);
this.decode(); this.writeInt32LE(0);
} }
} }

View File

@ -5,15 +5,15 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12524; const MSG_ID = 12524;
exports.SLRemoveClient = class SLRemoveClient extends SLMessage { exports.SLRemoveClient = class SLRemoveClient extends SLMessage {
constructor(senderId) { constructor(clientId, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.senderId = senderId; this.clientId = clientId;
} }
encode() { encode() {
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(this.senderId); this.writeInt32LE(this.clientId);
super.encode(); super.encode();
} }

View File

@ -5,20 +5,14 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12572; const MSG_ID = 12572;
exports.SLSaltCellConfigMessage = class SLSaltCellConfigMessage extends SLMessage { exports.SLSaltCellConfigMessage = class SLSaltCellConfigMessage extends SLMessage {
constructor(buf) { constructor(buf, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size);
if (!buf) {
this.writeInt32LE(0); // controller index
} else { } else {
this._wroteSize = true; super(senderId, MSG_ID);
this.writeBuffer(buf, 0);
this.decode(); this.writeInt32LE(0); // controller index
} }
} }

View File

@ -6,8 +6,8 @@ const MSG_ID = 12550;
exports.SLSetCircuitRuntimeById = class SLSetCircuitRuntimeById extends SLMessage { exports.SLSetCircuitRuntimeById = class SLSetCircuitRuntimeById extends SLMessage {
constructor(circuitId, runTime) { constructor(circuitId, runTime, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.circuitId = circuitId; this.circuitId = circuitId;
this.runTime = runTime; this.runTime = runTime;

View File

@ -5,8 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12530; const MSG_ID = 12530;
exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMessage { exports.SLSetCircuitStateMessage = class SLSetCircuitStateMessage extends SLMessage {
constructor(controllerId, circuitId, circuitState) { constructor(controllerId, circuitId, circuitState, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.controllerId = controllerId; this.controllerId = controllerId;
this.circuitId = circuitId; this.circuitId = circuitId;

View File

@ -5,8 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12538; const MSG_ID = 12538;
exports.SLSetHeatMode = class SLSetHeatMode extends SLMessage { exports.SLSetHeatMode = class SLSetHeatMode extends SLMessage {
constructor(controllerIndex, bodyType, heatMode) { constructor(controllerIndex, bodyType, heatMode, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.controllerIndex = controllerIndex; this.controllerIndex = controllerIndex;
this.bodyType = bodyType; this.bodyType = bodyType;

View File

@ -5,8 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12528; const MSG_ID = 12528;
exports.SLSetHeatSetPoint = class SLSetHeatSetPoint extends SLMessage { exports.SLSetHeatSetPoint = class SLSetHeatSetPoint extends SLMessage {
constructor(controllerIndex, bodyType, temperature) { constructor(controllerIndex, bodyType, temperature, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.controllerIndex = controllerIndex; this.controllerIndex = controllerIndex;
this.bodyType = bodyType; this.bodyType = bodyType;

View File

@ -5,8 +5,9 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12586; const MSG_ID = 12586;
exports.SLSetPumpFlow = class SLSetPumpFlow extends SLMessage { exports.SLSetPumpFlow = class SLSetPumpFlow extends SLMessage {
constructor(pumpId, circuitId, setPoint, isRPMs) { constructor(pumpId, circuitId, setPoint, isRPMs, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.pumpId = pumpId; this.pumpId = pumpId;
this.circuitId = circuitId; this.circuitId = circuitId;
this.setPoint = setPoint; this.setPoint = setPoint;

View File

@ -5,8 +5,8 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12576; const MSG_ID = 12576;
exports.SLSetSaltCellConfigMessage = class SLSetSaltCellConfigMessage extends SLMessage { exports.SLSetSaltCellConfigMessage = class SLSetSaltCellConfigMessage extends SLMessage {
constructor(controllerIndex, poolOutput, spaOutput) { constructor(controllerIndex, poolOutput, spaOutput, senderId) {
super(0, MSG_ID); super(senderId, MSG_ID);
this.controllerIndex = controllerIndex; this.controllerIndex = controllerIndex;
this.poolOutput = poolOutput; this.poolOutput = poolOutput;

View File

@ -6,15 +6,13 @@ const MSG_ID = 12548;
exports.SLSetScheduleEventById = class SLSetScheduleEventById extends SLMessage { exports.SLSetScheduleEventById = class SLSetScheduleEventById extends SLMessage {
constructor(buf, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) { constructor(buf, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size); } else {
super(senderId, MSG_ID);
if (!buf) {
this.writeInt32LE(0); this.writeInt32LE(0);
this.writeInt32LE(scheduleId); this.writeInt32LE(scheduleId);
this.writeInt32LE(circuitId); this.writeInt32LE(circuitId);
@ -24,11 +22,6 @@ exports.SLSetScheduleEventById = class SLSetScheduleEventById extends SLMessage
this.writeInt32LE(flags); this.writeInt32LE(flags);
this.writeInt32LE(heatCmd); this.writeInt32LE(heatCmd);
this.writeInt32LE(heatSetPoint); this.writeInt32LE(heatSetPoint);
} else {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
} }
} }

View File

@ -5,18 +5,12 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 8120; const MSG_ID = 8120;
exports.SLVersionMessage = class SLVersionMessage extends SLMessage { exports.SLVersionMessage = class SLVersionMessage extends SLMessage {
constructor(buf) { constructor(buf, senderId) {
var size;
if (buf) { if (buf) {
size = buf.readInt32LE(4) + 8; var size = buf.readInt32LE(4) + 8;
} super(buf, MSG_ID, size);
super(0, MSG_ID, size); } else {
super(senderId, MSG_ID);
if (buf) {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
} }
} }

View File

@ -3,8 +3,8 @@
const ScreenLogic = require('../index'); const ScreenLogic = require('../index');
// you'll need a ScreenLogic-enabled device on your network for this to succeed // you'll need a ScreenLogic-enabled device on your network for this to succeed
describe('Finder', () => { describe('Finder', function() {
it('finds a server', done => { it('finds a server', function(done) {
let finder = new ScreenLogic.FindUnits(); let finder = new ScreenLogic.FindUnits();
finder.on('serverFound', server => { finder.on('serverFound', server => {
finder.close(); finder.close();

View File

@ -9,7 +9,7 @@ function slMessageLen(str) {
return 4 + str.length + SLMessage.slackForAlignment(str.length); return 4 + str.length + SLMessage.slackForAlignment(str.length);
} }
describe('SLMessage utilities', () => { describe('SLMessage utilities', function() {
// message header = senderId, messageId, bodyLen. // message header = senderId, messageId, bodyLen.
// senderId and messageId are int16's, so 2b each. bodyLen is an int32, so 4b. total 8b. // senderId and messageId are int16's, so 2b each. bodyLen is an int32, so 4b. total 8b.
let msgHeaderLen = 8; let msgHeaderLen = 8;

View File

@ -1,11 +1,12 @@
'use strict'; 'use strict';
const ScreenLogic = require('../index'); const ScreenLogic = require('../index');
var assert = require('assert');
// you'll need a ScreenLogic-enabled device on your network for this to succeed // you'll need a ScreenLogic-enabled device on your network for this to succeed
describe('Unit', () => { describe('Unit', function() {
let unit; let unit;
before(done => { before(function(done) {
let finder = new ScreenLogic.FindUnits(); let finder = new ScreenLogic.FindUnits();
finder.on('serverFound', server => { finder.on('serverFound', server => {
finder.close(); finder.close();
@ -21,50 +22,57 @@ describe('Unit', () => {
finder.search(); finder.search();
}); });
after(() => { after(function() {
unit.close(); unit.close();
}); });
// let circuit; it('gets pool status', function(done) {
it('gets pool status', done => {
unit.on('poolStatus', status => { unit.on('poolStatus', status => {
/* circuit = */status.circuitArray[0]; assert.equal(status.senderId, 0);
done(); done();
}); });
unit.getPoolStatus(); unit.getPoolStatus();
}); });
it('gets controller config', done => { it('gets controller config', function(done) {
unit.on('controllerConfig', config => { unit.on('controllerConfig', config => {
assert.equal(config.senderId, 42);
done(); done();
}); });
unit.getControllerConfig();
unit.getControllerConfig(42);
}); });
it('gets chemical data', done => { it('gets chemical data', function(done) {
unit.on('chemicalData', () => { unit.on('chemicalData', chemData => {
assert.equal(chemData.senderId, 123);
done(); done();
}); });
unit.getChemicalData();
unit.getChemicalData(123);
}); });
it('gets salt cell config', done => { it('gets salt cell config', function(done) {
unit.on('saltCellConfig', () => { unit.on('saltCellConfig', saltConfig => {
assert.equal(saltConfig.senderId, 0);
done(); done();
}); });
unit.getSaltCellConfig(); unit.getSaltCellConfig();
}); });
it('gets version', done => { it('gets version', function(done) {
unit.on('version', () => { unit.on('version', version => {
assert.equal(version.senderId, 41239);
done(); done();
}); });
unit.getVersion();
unit.getVersion(41239);
}); });
/* uncomment this and the `circuit` stuff above to test setting state /* uncomment this and the `circuit` stuff above to test setting state
it('sets circuit state', done => { it('sets circuit state', function(done) {
unit.on('circuitStateChanged', () => { unit.on('circuitStateChanged', () => {
done(); done();
}); });