syntex-automation
Advanced tools
Comparing version 1.2.1-b16 to 1.2.1-b17
{ | ||
"name": "syntex-automation", | ||
"version": "1.2.1-b16", | ||
"version": "1.2.1-b17", | ||
"description": "An automation system for your smart home", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -36,3 +36,3 @@ module.exports = class Automation | ||
var changed = false; | ||
var promiseArray = []; | ||
@@ -43,10 +43,7 @@ for(const automation of this.automation) | ||
{ | ||
if(this._checkLock(automation)) | ||
{ | ||
changed = true; | ||
} | ||
promiseArray.push(this._checkLock(automation)); | ||
if(!this._isLocked(automation)) | ||
{ | ||
this.checkTrigger(automation, { name : ('0' + new Date().getHours()).slice(-2) + ':' + ('0' + new Date().getMinutes()).slice(-2) }, {}); | ||
this.checkTrigger(automation, { name : ('0' + new Date().getHours()).slice(-2) + ':' + ('0' + new Date().getMinutes()).slice(-2) }); | ||
} | ||
@@ -56,7 +53,10 @@ } | ||
if(changed) | ||
{ | ||
this.files.writeFile('automation/automation-lock.json', { timeLock : this.timeLock, stateLock : this.stateLock }); | ||
} | ||
Promise.all(promiseArray).then((result) => { | ||
if(result.includes(true)) | ||
{ | ||
this.files.writeFile('automation/automation-lock.json', { timeLock : this.timeLock, stateLock : this.stateLock }); | ||
} | ||
}); | ||
}, 60000); | ||
@@ -166,3 +166,3 @@ | ||
{ | ||
var changed = false; | ||
var promiseArray = []; | ||
@@ -173,6 +173,3 @@ for(const automation of this.automation) | ||
{ | ||
if(this._checkLock(automation, service, state)) | ||
{ | ||
changed = true; | ||
} | ||
promiseArray.push(this._checkLock(automation, service, state)); | ||
@@ -186,6 +183,9 @@ if(!this._isLocked(automation, service)) | ||
if(changed) | ||
{ | ||
this.files.writeFile('automation/automation-lock.json', { timeLock : this.timeLock, stateLock : this.stateLock }); | ||
} | ||
Promise.all(promiseArray).then((result) => { | ||
if(result.includes(true)) | ||
{ | ||
this.files.writeFile('automation/automation-lock.json', { timeLock : this.timeLock, stateLock : this.stateLock }); | ||
} | ||
}); | ||
} | ||
@@ -197,3 +197,3 @@ | ||
checkTrigger(automation, service, state) | ||
checkTrigger(automation, service, state = {}) | ||
{ | ||
@@ -210,3 +210,3 @@ return new Promise((resolve) => { | ||
{ | ||
promiseArray.push(new Promise((callback) => (block.id != service.id || block.letters != service.letters ? this._getState(automation, block).then((state) => callback({ block : block, state : state || {} })) : callback({ block : block, state })))); | ||
promiseArray.push(this._getComparison(automation, block, service, state)); | ||
} | ||
@@ -602,35 +602,24 @@ | ||
if(block.id != null && block.letters != null && block.state != null && block.state instanceof Object && block.operation != null) | ||
if(block.id != null && block.letters != null && block.operation != null && block.state instanceof Object) | ||
{ | ||
if(block.operation == '>') | ||
var success = true; | ||
for(const x in block.state) | ||
{ | ||
if((state.value == null || block.state.value == null || state.value > block.state.value) | ||
&& (state.hue == null || block.state.hue == null || state.hue > block.state.hue) | ||
&& (state.saturation == null || block.state.saturation == null || state.saturation > block.state.saturation) | ||
&& (state.brightness == null || block.state.brightness == null || state.brightness > block.state.brightness)) | ||
if(state[x] == null) | ||
{ | ||
return true; | ||
success = false; | ||
} | ||
} | ||
if(block.operation == '<') | ||
{ | ||
if((state.value == null || block.state.value == null || state.value < block.state.value) | ||
&& (state.hue == null || block.state.hue == null || state.hue < block.state.hue) | ||
&& (state.saturation == null || block.state.saturation == null || state.saturation < block.state.saturation) | ||
&& (state.brightness == null || block.state.brightness == null || state.brightness < block.state.brightness)) | ||
if((block.operation == '>' && block.state[x] <= state[x]) | ||
|| (block.operation == '<' && block.state[x] >= state[x]) | ||
|| (block.operation == '=' && block.state[x] != state[x])) | ||
{ | ||
return true; | ||
success = false; | ||
} | ||
} | ||
if(block.operation == '=') | ||
if(success) | ||
{ | ||
if((state.value == null || block.state.value == null || state.value == block.state.value) | ||
&& (state.hue == null || block.state.hue == null || state.hue == block.state.hue) | ||
&& (state.saturation == null || block.state.saturation == null || state.saturation == block.state.saturation) | ||
&& (state.brightness == null || block.state.brightness == null || state.brightness == block.state.brightness)) | ||
{ | ||
return true; | ||
} | ||
return true; | ||
} | ||
@@ -778,2 +767,7 @@ } | ||
} | ||
if(block.comparison != null && block.comparison.id == service.id && block.comparison.letters == service.letters) | ||
{ | ||
return true; | ||
} | ||
} | ||
@@ -801,39 +795,91 @@ | ||
{ | ||
var blocks = this._getBlocks(automation.id), changed = false; | ||
return new Promise((resolve) => { | ||
for(const block of blocks) | ||
{ | ||
if(this.stateLock[automation.id] != null | ||
&& this.stateLock[automation.id].trigger != null | ||
&& this.stateLock[automation.id].trigger[block.blockID] == true) | ||
var blocks = this._getBlocks(automation.id), promiseArray = []; | ||
for(const block of blocks) | ||
{ | ||
if((block.id == service.id && block.letters == service.letters) || block.days != null || block.time != null) | ||
if(this.stateLock[automation.id] != null | ||
&& this.stateLock[automation.id].trigger != null | ||
&& this.stateLock[automation.id].trigger[block.blockID] == true) | ||
{ | ||
if(!this._getOutput(block, state)) | ||
if((block.id == service.id && block.letters == service.letters) || (block.comparison != null && block.comparison.id == service.id && block.comparison.letters == service.letters) || block.days != null || block.time != null) | ||
{ | ||
this.stateLock[automation.id].trigger[block.blockID] = false; | ||
promiseArray.push(new Promise((callback) => { | ||
this._getComparison(automation, block, service, state).then((result) => { | ||
if(block.operation == '<') | ||
{ | ||
this.logger.debug('Automation [' + automation.name + '] %automation_greater% ' + automation.id + ' ' + block.blockID); | ||
} | ||
else if(block.operation == '>') | ||
{ | ||
this.logger.debug('Automation [' + automation.name + '] %automation_lower% ' + automation.id + ' ' + block.blockID); | ||
} | ||
else | ||
{ | ||
this.logger.debug('Automation [' + automation.name + '] %automation_different% ' + automation.id + ' ' + block.blockID); | ||
} | ||
if(!this._getOutput(result.block, result.state)) | ||
{ | ||
this.stateLock[automation.id].trigger[block.blockID] = false; | ||
this._updateSockets(false, automation.id, block.blockID); | ||
if(block.operation == '<') | ||
{ | ||
this.logger.debug('Automation [' + automation.name + '] %automation_greater% ' + automation.id + ' ' + block.blockID); | ||
} | ||
else if(block.operation == '>') | ||
{ | ||
this.logger.debug('Automation [' + automation.name + '] %automation_lower% ' + automation.id + ' ' + block.blockID); | ||
} | ||
else | ||
{ | ||
this.logger.debug('Automation [' + automation.name + '] %automation_different% ' + automation.id + ' ' + block.blockID); | ||
} | ||
changed = true; | ||
this._updateSockets(false, automation.id, block.blockID); | ||
callback(true); | ||
} | ||
else | ||
{ | ||
callback(false); | ||
} | ||
}); | ||
})); | ||
} | ||
} | ||
} | ||
} | ||
return changed; | ||
Promise.all(promiseArray).then((result) => resolve(result.includes(true))); | ||
}); | ||
} | ||
_getComparison(automation, block, service, state) | ||
{ | ||
return new Promise((resolve) => { | ||
if(block.id == service.id && block.letters == service.letters) | ||
{ | ||
if(block.comparison != null) | ||
{ | ||
this._getState(automation, block.comparison).then((comparison) => { | ||
block.state = comparison; | ||
resolve({ block, state }); | ||
}); | ||
} | ||
else | ||
{ | ||
resolve({ block, state }); | ||
} | ||
} | ||
else | ||
{ | ||
if(block.comparison != null) | ||
{ | ||
this._getState(automation, block).then((comparison) => { | ||
block.state = state; | ||
resolve({ block, state : comparison }); | ||
}); | ||
} | ||
else | ||
{ | ||
this._getState(automation, block).then((state) => resolve({ block, state })); | ||
} | ||
} | ||
}); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25018
754