Added ability to send light commands (on, off, set colors, etc.)
This implementation is barebones and only does what I was able to find easily in the official app's source code. I'd love to do more with this, so any pull requests adding functionality would be welcomed. Closes https://github.com/parnic/node-screenlogic/issues/4
This commit is contained in:
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
* Ability to set heat setpoint.
|
||||
* Event for supplying incorrect parameters to `set` functions.
|
||||
* Ability to send limited selection of light commands.
|
||||
|
||||
## v1.2.1 - 2019-03-26
|
||||
### Fixed
|
||||
|
35
README.md
35
README.md
@ -196,6 +196,12 @@ Activates or deactivates a circuit. See [`SLSetCircuitStateMessage`](#slsetcircu
|
||||
|
||||
Sets the heating setpoint for any body. See [`SLSetHeatSetPointMessage`](#slsetheatsetpointmessage) documentation for argument values. Emits the `setPointChanged` event when response is acknowledged.
|
||||
|
||||
### sendLightCommand(controllerId, command)
|
||||
|
||||
Sends a lighting command. See [`SLLightControlMessage`](#sllightcontrolmessage) documentation for argument values. Emits the `sentLightCommand` event when response is acknowledged.
|
||||
|
||||
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.
|
||||
|
||||
### 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.
|
||||
@ -206,6 +212,7 @@ Sets the heating setpoint for any body. See [`SLSetHeatSetPointMessage`](#slseth
|
||||
* `controllerConfig` - Indicates that a response to `getControllerConfig()` has been received. Event handler receives a [`SLControllerConfigMessage`](#slcontrollerconfigmessage) object.
|
||||
* `circuitStateChanged` - Indicates that a response to `setCircuitState()` has been received. Event handler receives a [`SLSetCircuitStateMessage`](#slsetcircuitstatemessage) object.
|
||||
* `setPointChanged` - Indicates that a response to `setSetPoint()` has been received. Event handler receives a [`SLSetHeatSetPointMessage`](#slsetheatsetpointmessage) object.
|
||||
* `sentLightCommand` - Indicates that a response to `sendLightCommand()` has been received. Event handler receives a [`SLLightControlMessage`](#sllightcontrolmessage) object.
|
||||
* `loginFailed` - Indicates that a remote login attempt via supplying a system address and password to `UnitConnection` has failed likely due to the incorrect password being used.
|
||||
* `badParameter` - Indicates that a bad parameter has been supplied to a function. This can be triggered, for example, by sending the wrong controller ID to a `set` function.
|
||||
|
||||
@ -373,6 +380,34 @@ Passed as an argument to the emitted `setPointChanged` event. The passed version
|
||||
* `bodyType` - integer indicating the type of body to set the setpoint of. The pool is body `0` and the spa is body `1`.
|
||||
* `temperature` - integer indicating the desired setpoint. This is presumably in whatever units your system is set to (celsius or fahrenheit).
|
||||
|
||||
## SLLightControlMessage
|
||||
|
||||
Passed as an argument to the emitted `sentLightCommand` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the light 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.
|
||||
* `command` - integer indicating which command to send to the lights. Valid values are:
|
||||
* ScreenLogic.LIGHT_CMD_LIGHTS_OFF
|
||||
* ScreenLogic.LIGHT_CMD_LIGHTS_ON
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_SET
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_SYNC
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_SWIM
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_MODE_PARTY
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_MODE_ROMANCE
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_MODE_CARRIBEAN
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_MODE_AMERICAN
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_MODE_SUNSET
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_MODE_ROYAL
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_SET_SAVE
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_SET_RECALL
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_BLUE
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_GREEN
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_RED
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_WHITE
|
||||
* ScreenLogic.LIGHT_CMD_COLOR_PURPLE
|
||||
|
||||
## SLGetGatewayDataMessage
|
||||
|
||||
Passed as an argument to the emitted `gatewayFound` event. Contains information about the remote unit's status and access properties.
|
||||
|
26
index.js
26
index.js
@ -210,6 +210,10 @@ class UnitConnection extends EventEmitter {
|
||||
this.client.write(new messages.SLSetHeatSetPointMessage(controllerId, bodyType, temperature).toBuffer());
|
||||
}
|
||||
|
||||
sendLightCommand(controllerId, command) {
|
||||
this.client.write(new messages.SLLightControlMessage(controllerId, command).toBuffer());
|
||||
}
|
||||
|
||||
onClientMessage(msg) {
|
||||
// console.log('received message of length ' + msg.length);
|
||||
if (msg.length < 4) {
|
||||
@ -255,6 +259,10 @@ class UnitConnection extends EventEmitter {
|
||||
// console.log(" it's a setpoint ack");
|
||||
this.emit('setPointChanged', new messages.SLSetHeatSetPointMessage());
|
||||
break;
|
||||
case messages.SLLightControlMessage.getResponseId():
|
||||
// console.log(" it's a light control ack");
|
||||
this.emit('sentLightCommand', new messages.SLLightControlMessage());
|
||||
break;
|
||||
case 13:
|
||||
// console.log(" it's a login failure.");
|
||||
this.emit('loginFailed');
|
||||
@ -280,4 +288,22 @@ module.exports = {
|
||||
FindUnits,
|
||||
RemoteLogin,
|
||||
UnitConnection,
|
||||
LIGHT_CMD_LIGHTS_OFF: 0,
|
||||
LIGHT_CMD_LIGHTS_ON: 1,
|
||||
LIGHT_CMD_COLOR_SET: 2,
|
||||
LIGHT_CMD_COLOR_SYNC: 3,
|
||||
LIGHT_CMD_COLOR_SWIM: 4,
|
||||
LIGHT_CMD_COLOR_MODE_PARTY: 5,
|
||||
LIGHT_CMD_COLOR_MODE_ROMANCE: 6,
|
||||
LIGHT_CMD_COLOR_MODE_CARRIBEAN: 7,
|
||||
LIGHT_CMD_COLOR_MODE_AMERICAN: 8,
|
||||
LIGHT_CMD_COLOR_MODE_SUNSET: 9,
|
||||
LIGHT_CMD_COLOR_MODE_ROYAL: 10,
|
||||
LIGHT_CMD_COLOR_SET_SAVE: 11,
|
||||
LIGHT_CMD_COLOR_SET_RECALL: 12,
|
||||
LIGHT_CMD_COLOR_BLUE: 13,
|
||||
LIGHT_CMD_COLOR_GREEN: 14,
|
||||
LIGHT_CMD_COLOR_RED: 15,
|
||||
LIGHT_CMD_COLOR_WHITE: 16,
|
||||
LIGHT_CMD_COLOR_PURPLE: 17,
|
||||
};
|
||||
|
25
messages/SLLightControl.js
Normal file
25
messages/SLLightControl.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12556;
|
||||
|
||||
exports.SLLightControl = class SLLightControl extends SLMessage {
|
||||
constructor(controllerIndex, command) {
|
||||
super(0, MSG_ID);
|
||||
|
||||
this.controllerIndex = controllerIndex;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
encode() {
|
||||
this.writeInt32LE(this.controllerIndex || 0);
|
||||
this.writeInt32LE(this.command || 0);
|
||||
|
||||
super.encode();
|
||||
}
|
||||
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
};
|
@ -10,3 +10,4 @@ exports.SLVersionMessage = require('./SLVersionMessage.js').SLVersionMessage;
|
||||
exports.SLSetCircuitStateMessage = require('./SLSetCircuitStateMessage.js').SLSetCircuitStateMessage;
|
||||
exports.SLGetGatewayDataMessage = require('./SLGetGatewayDataMessage.js').SLGetGatewayDataMessage;
|
||||
exports.SLSetHeatSetPointMessage = require('./SLSetHeatSetPoint.js').SLSetHeatSetPoint;
|
||||
exports.SLLightControlMessage = require('./SLLightControl.js').SLLightControl;
|
||||
|
Reference in New Issue
Block a user