Schedule Editing Additions (#24)
* Added support for: adding schedule events, deleting schedule events, listing schedule events and updating scheduled events
This commit is contained in:
29
index.js
29
index.js
@ -232,6 +232,23 @@ class UnitConnection extends EventEmitter {
|
||||
this.client.write(new messages.SLSetSaltCellConfigMessage(controllerId, poolOutput, spaOutput).toBuffer());
|
||||
}
|
||||
|
||||
getScheduleData(scheduleType) {
|
||||
this.client.write(new messages.SLGetScheduleData(null, scheduleType).toBuffer());
|
||||
}
|
||||
|
||||
addNewScheduleEvent(scheduleType) {
|
||||
this.client.write(new messages.SLAddNewScheduleEvent(null, scheduleType).toBuffer());
|
||||
}
|
||||
|
||||
deleteScheduleEventById(scheduleId) {
|
||||
this.client.write(new messages.SLDeleteScheduleEventById(scheduleId).toBuffer());
|
||||
}
|
||||
|
||||
setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) {
|
||||
this.client.write(new messages.SLSetScheduleEventById(null, scheduleId, circuitId, startTime, stopTime,
|
||||
dayMask, flags, heatCmd, heatSetPoint).toBuffer());
|
||||
}
|
||||
|
||||
onClientMessage(msg) {
|
||||
// console.log('received message of length ' + msg.length);
|
||||
if (msg.length < 4) {
|
||||
@ -292,6 +309,18 @@ class UnitConnection extends EventEmitter {
|
||||
case messages.SLEquipmentConfigurationMessage.getResponseId():
|
||||
this.emit('equipmentConfiguration', new messages.SLEquipmentConfigurationMessage(msg));
|
||||
break;
|
||||
case messages.SLGetScheduleData.getResponseId():
|
||||
this.emit('getScheduleData', new messages.SLGetScheduleData(msg));
|
||||
break;
|
||||
case messages.SLAddNewScheduleEvent.getResponseId():
|
||||
this.emit('addNewScheduleEvent', new messages.SLAddNewScheduleEvent(msg));
|
||||
break;
|
||||
case messages.SLDeleteScheduleEventById.getResponseId():
|
||||
this.emit('deleteScheduleEventById', new messages.SLDeleteScheduleEventById(msg));
|
||||
break;
|
||||
case messages.SLSetScheduleEventById.getResponseId():
|
||||
this.emit('setScheduleEventById', new messages.SLSetScheduleEventById(msg));
|
||||
break;
|
||||
case 13:
|
||||
// console.log(" it's a login failure.");
|
||||
this.emit('loginFailed');
|
||||
|
38
messages/SLAddNewScheduleEvent.js
Normal file
38
messages/SLAddNewScheduleEvent.js
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12544;
|
||||
|
||||
|
||||
exports.SLAddNewScheduleEvent = class SLAddNewScheduleEvent extends SLMessage {
|
||||
constructor(buf, scheduleType) {
|
||||
var size;
|
||||
if (buf) {
|
||||
size = buf.readInt32LE(4) + 8;
|
||||
}
|
||||
super(0, MSG_ID, size);
|
||||
|
||||
|
||||
if (!buf) {
|
||||
// console.log('Requested Schedule type = ', scheduleType);
|
||||
this.writeInt32LE(0);
|
||||
this.writeInt32LE(scheduleType);
|
||||
} else {
|
||||
this._wroteSize = true;
|
||||
this.writeBuffer(buf, 0);
|
||||
|
||||
this.decode();
|
||||
}
|
||||
}
|
||||
|
||||
decode() {
|
||||
super.decode();
|
||||
|
||||
this.scheduleId = this.readUInt32LE();
|
||||
}
|
||||
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
};
|
18
messages/SLDeleteScheduleEventById.js
Normal file
18
messages/SLDeleteScheduleEventById.js
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12546;
|
||||
|
||||
exports.SLDeleteScheduleEventById = class SLDeleteScheduleEventById extends SLMessage {
|
||||
constructor(scheduleId) {
|
||||
super(0, MSG_ID);
|
||||
|
||||
this.writeInt32LE(0);
|
||||
this.writeInt32LE(scheduleId);
|
||||
}
|
||||
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
};
|
63
messages/SLGetScheduleData.js
Normal file
63
messages/SLGetScheduleData.js
Normal file
@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12542;
|
||||
|
||||
exports.SLGetScheduleData = class SLGetScheduleData extends SLMessage {
|
||||
constructor(buf, scheduleType) {
|
||||
var size;
|
||||
if (buf) {
|
||||
size = buf.readInt32LE(4) + 8;
|
||||
}
|
||||
super(0, MSG_ID, size);
|
||||
|
||||
|
||||
if (!buf) {
|
||||
// console.log('Requested Schedule type = ', scheduleType);
|
||||
this.writeInt32LE(0);
|
||||
this.writeInt32LE(scheduleType);
|
||||
} else {
|
||||
this._wroteSize = true;
|
||||
this.writeBuffer(buf, 0);
|
||||
|
||||
this.decode();
|
||||
}
|
||||
}
|
||||
|
||||
decode() {
|
||||
super.decode();
|
||||
|
||||
this.eventCount = this.readUInt32LE();
|
||||
|
||||
this.events = new Array(this.eventCount);
|
||||
|
||||
for (var i = 0; i < this.events.length; i++) {
|
||||
this.events[i] = {};
|
||||
|
||||
this.events[i].scheduleId = this.readUInt32LE();
|
||||
this.events[i].circuitId = this.readUInt32LE();
|
||||
this.events[i].startTime = this.readTime(this.readUInt32LE());
|
||||
this.events[i].stopTime = this.readTime(this.readUInt32LE());
|
||||
this.events[i].dayMask = this.readUInt32LE();
|
||||
this.events[i].flags = this.readUInt32LE();
|
||||
this.events[i].heatCmd = this.readUInt32LE();
|
||||
this.events[i].heatSetPoint = this.readUInt32LE();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
readTime(rawTime) {
|
||||
var retVal;
|
||||
|
||||
retVal = Math.floor(rawTime / 60) * 100 + rawTime % 60;
|
||||
|
||||
retVal = String(retVal).padStart(4, '0');
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
};
|
38
messages/SLSetScheduleEventById.js
Normal file
38
messages/SLSetScheduleEventById.js
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const SLMessage = require('./SLMessage.js').SLMessage;
|
||||
|
||||
const MSG_ID = 12548;
|
||||
|
||||
|
||||
exports.SLSetScheduleEventById = class SLSetScheduleEventById extends SLMessage {
|
||||
constructor(buf, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) {
|
||||
var size;
|
||||
if (buf) {
|
||||
size = buf.readInt32LE(4) + 8;
|
||||
}
|
||||
super(0, MSG_ID, size);
|
||||
|
||||
|
||||
if (!buf) {
|
||||
this.writeInt32LE(0);
|
||||
this.writeInt32LE(scheduleId);
|
||||
this.writeInt32LE(circuitId);
|
||||
this.writeInt32LE(startTime);
|
||||
this.writeInt32LE(stopTime);
|
||||
this.writeInt32LE(dayMask);
|
||||
this.writeInt32LE(flags);
|
||||
this.writeInt32LE(heatCmd);
|
||||
this.writeInt32LE(heatSetPoint);
|
||||
} else {
|
||||
this._wroteSize = true;
|
||||
this.writeBuffer(buf, 0);
|
||||
|
||||
this.decode();
|
||||
}
|
||||
}
|
||||
|
||||
static getResponseId() {
|
||||
return MSG_ID + 1;
|
||||
}
|
||||
};
|
@ -15,3 +15,7 @@ exports.SLLightControlMessage = require('./SLLightControl.js').SLLightControl;
|
||||
exports.SLSetSaltCellConfigMessage = require('./SLSetSaltCellConfigMessage.js').SLSetSaltCellConfigMessage;
|
||||
exports.SLEquipmentConfigurationMessage =
|
||||
require('./SLEquipmentConfigurationMessage.js').SLEquipmentConfigurationMessage;
|
||||
exports.SLGetScheduleData = require('./SLGetScheduleData.js').SLGetScheduleData;
|
||||
exports.SLAddNewScheduleEvent = require('./SLAddNewScheduleEvent.js').SLAddNewScheduleEvent;
|
||||
exports.SLDeleteScheduleEventById = require('./SLDeleteScheduleEventById.js').SLDeleteScheduleEventById;
|
||||
exports.SLSetScheduleEventById = require('./SLSetScheduleEventById.js').SLSetScheduleEventById;
|
||||
|
Reference in New Issue
Block a user