10
README.md
10
README.md
@ -34,6 +34,7 @@ Tested with a Pentair ScreenLogic system on firmware versions 5.2 Build 736.0 Re
|
|||||||
* [SLAddClient](#sladdclient)
|
* [SLAddClient](#sladdclient)
|
||||||
* [SLRemoveClient](#slremoveclient)
|
* [SLRemoveClient](#slremoveclient)
|
||||||
* [SLGetSystemTime](#slgetsystemtime)
|
* [SLGetSystemTime](#slgetsystemtime)
|
||||||
|
* [SLSetSystemTime](#slsetsystemtime)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -295,6 +296,10 @@ No longer receive `poolStatus` messages from controller. Emits the `removeClient
|
|||||||
|
|
||||||
Retrieves the current time the system is set to. Emits the `getSystemTime` event when response is received. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
|
Retrieves the current time the system is set to. Emits the `getSystemTime` event when response is received. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
|
||||||
|
|
||||||
|
#### setSystemTime(date, adjustForDST, senderId)
|
||||||
|
|
||||||
|
Sets the current date and time of the ScreenLogic system. Emits the `setSystemTime` event when request is acknowledged. `date` must be a `Date` instance holding the date/time to set, and `adjustForDST` must be a boolean indicating whether the system should adjust for daylight saving time or not. `senderId` is an optional 16-bit integer and will be present as the `senderId` field on the returned message.
|
||||||
|
|
||||||
### 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.
|
||||||
@ -320,6 +325,7 @@ Retrieves the current time the system is set to. Emits the `getSystemTime` event
|
|||||||
* `addClient` - Indicates that a response to `addClient()` has been received. Event handler receives a [`SLAddClient`](#sladdclient) object.
|
* `addClient` - Indicates that a response to `addClient()` has been received. Event handler receives a [`SLAddClient`](#sladdclient) object.
|
||||||
* `removeClient` - Indicates that a response to `removeClient()` has been received. Event handler receives a [`SLRemoveClient`](#slremoveclient) object.
|
* `removeClient` - Indicates that a response to `removeClient()` has been received. Event handler receives a [`SLRemoveClient`](#slremoveclient) object.
|
||||||
* `getSystemTime` - Indicates that a response to `getSystemTime()` has been received. Event handler receives a [`SLGetSystemTime`](#slgetsystemtime) object.
|
* `getSystemTime` - Indicates that a response to `getSystemTime()` has been received. Event handler receives a [`SLGetSystemTime`](#slgetsystemtime) object.
|
||||||
|
* `setSystemTime` - Indicates that a response to `setSystemTime()` has been received. Event handler receives a [`SLSetSystemTime`](#slsetsystemtime) object if the request was valid, or `null` if the request was invalid (input parameters were not of the required types).
|
||||||
* `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.
|
* `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.
|
* `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.
|
||||||
* `error` - Indicates that an unhandled error was caught (such as the connection timing out)
|
* `error` - Indicates that an unhandled error was caught (such as the connection timing out)
|
||||||
@ -783,3 +789,7 @@ Contains information about the system's current time and date. Passed as an argu
|
|||||||
* `millisecond` - short representing current system millisecond
|
* `millisecond` - short representing current system millisecond
|
||||||
* `adjustForDST` - bool indicating whether the system should adjust for daylight saving time or not
|
* `adjustForDST` - bool indicating whether the system should adjust for daylight saving time or not
|
||||||
* `date` - `Date` instance representing the current system datetime (convenience, constructed from the above properties)
|
* `date` - `Date` instance representing the current system datetime (convenience, constructed from the above properties)
|
||||||
|
|
||||||
|
### SLSetSystemTime
|
||||||
|
|
||||||
|
Passed as an argument to the emitted `setSystemTime` event.
|
||||||
|
21
index.js
21
index.js
@ -302,6 +302,23 @@ class UnitConnection extends EventEmitter {
|
|||||||
this.client.write(new messages.SLGetSystemTime(null, senderId).toBuffer());
|
this.client.write(new messages.SLGetSystemTime(null, senderId).toBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSystemTime(date, shouldAdjustForDST, senderId) {
|
||||||
|
if (!(date instanceof Date)) {
|
||||||
|
debugUnit('setSystemTime() must receive valid Date object for the date argument');
|
||||||
|
this.emit('setSystemTime', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof shouldAdjustForDST !== 'boolean') {
|
||||||
|
debugUnit('setSystemTime() must receive a boolean for the shouldAdjustForDST argument');
|
||||||
|
this.emit('setSystemTime', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
debugUnit('[%d] sending set system time command...', senderId || 0);
|
||||||
|
this.client.write(new messages.SLSetSystemTime(null, date, shouldAdjustForDST, 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) {
|
||||||
@ -411,6 +428,10 @@ class UnitConnection extends EventEmitter {
|
|||||||
debugUnit(" it's system time");
|
debugUnit(" it's system time");
|
||||||
this.emit('getSystemTime', new messages.SLGetSystemTime(msg));
|
this.emit('getSystemTime', new messages.SLGetSystemTime(msg));
|
||||||
break;
|
break;
|
||||||
|
case messages.SLSetSystemTime.getResponseId():
|
||||||
|
debugUnit(" it's a set system time ack");
|
||||||
|
this.emit('setSystemTime', new messages.SLSetSystemTime(msg));
|
||||||
|
break;
|
||||||
case 12501:
|
case 12501:
|
||||||
debugUnit(" it's a schedule changed notification");
|
debugUnit(" it's a schedule changed notification");
|
||||||
this.emit('scheduleChanged');
|
this.emit('scheduleChanged');
|
||||||
|
28
messages/SLSetSystemTime.js
Normal file
28
messages/SLSetSystemTime.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||||
|
|
||||||
|
const MSG_ID = 8112;
|
||||||
|
|
||||||
|
exports.SLSetSystemTime = class SLSetSystemTime extends SLMessage {
|
||||||
|
constructor(buf, date, shouldAdjustForDST, senderId) {
|
||||||
|
if (buf) {
|
||||||
|
var size = buf.readInt32LE(4) + 8;
|
||||||
|
super(buf, MSG_ID, size);
|
||||||
|
} else {
|
||||||
|
super(senderId, MSG_ID);
|
||||||
|
|
||||||
|
this.date = date;
|
||||||
|
this.shouldAdjustForDST = shouldAdjustForDST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
encode() {
|
||||||
|
this.writeSLDateTime(this.date);
|
||||||
|
this.writeInt32LE(this.shouldAdjustForDST ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getResponseId() {
|
||||||
|
return MSG_ID + 1;
|
||||||
|
}
|
||||||
|
};
|
@ -26,3 +26,4 @@ exports.SLCancelDelay = require('./SLCancelDelay.js').SLCancelDelay;
|
|||||||
exports.SLAddClient = require('./SLAddClient.js').SLAddClient;
|
exports.SLAddClient = require('./SLAddClient.js').SLAddClient;
|
||||||
exports.SLRemoveClient = require('./SLRemoveClient.js').SLRemoveClient;
|
exports.SLRemoveClient = require('./SLRemoveClient.js').SLRemoveClient;
|
||||||
exports.SLGetSystemTime = require('./SLGetSystemTime.js').SLGetSystemTime;
|
exports.SLGetSystemTime = require('./SLGetSystemTime.js').SLGetSystemTime;
|
||||||
|
exports.SLSetSystemTime = require('./SLSetSystemTime.js').SLSetSystemTime;
|
||||||
|
Reference in New Issue
Block a user