Added server support for issuing light commands

This commit is contained in:
2020-03-31 22:10:10 -05:00
parent d1d2117549
commit 5e35e1e58b

View File

@ -33,6 +33,13 @@ module.exports = NodeHelper.create({
}); });
}, },
setLightcmd: function(lightCmd) {
var self = this;
setLights(lightCmd, function(poolStatus) {
self.sendSocketNotification('SCREENLOGIC_LIGHTCMD_DONE', {lightCmd: lightCmd, status: poolStatus});
});
},
restartTimer: function() { restartTimer: function() {
var interval = this.updateInterval; var interval = this.updateInterval;
this.updateInterval = undefined; this.updateInterval = undefined;
@ -183,3 +190,21 @@ function setHeatstateState(heatstate, cb) {
foundUnit.connect(); foundUnit.connect();
} }
function setLights(lightCmd, cb) {
if (!foundUnit) {
cb();
return;
}
foundUnit.once('loggedIn', function() {
foundUnit.sendLightCommand(0, lightCmd);
}).once('sentLightCommand', function() {
foundUnit.getPoolStatus();
}).once('poolStatus', function(status) {
foundUnit.close();
cb(status);
});
foundUnit.connect();
}