Add support for setting the current system date/time

#56
This commit is contained in:
2021-09-06 22:52:57 -05:00
parent f271554d89
commit a5d207d3aa
4 changed files with 60 additions and 0 deletions

View File

@ -302,6 +302,23 @@ class UnitConnection extends EventEmitter {
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) {
debugUnit('received message of length %d', msg.length);
if (msg.length < 4) {
@ -411,6 +428,10 @@ class UnitConnection extends EventEmitter {
debugUnit(" it's system time");
this.emit('getSystemTime', new messages.SLGetSystemTime(msg));
break;
case messages.SLSetSystemTime.getResponseId():
debugUnit(" it's a set system time ack");
this.emit('setSystemTime', new messages.SLSetSystemTime(msg));
break;
case 12501:
debugUnit(" it's a schedule changed notification");
this.emit('scheduleChanged');