Socket
Socket
Sign inDemoInstall

syntex-automation

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

syntex-automation - npm Package Compare versions

Comparing version 1.2.1-b12 to 1.2.1-b13

2

package.json
{
"name": "syntex-automation",
"version": "1.2.1-b12",
"version": "1.2.1-b13",
"description": "An automation system for your smart home",

@@ -5,0 +5,0 @@ "main": "main.js",

@@ -167,3 +167,3 @@ module.exports = class Automation

{
if(automation.active && this._includesBlock(automation, service.id, service.letters))
if(automation.active && this._includesBlock(this._getBlocks(automation.id), service))
{

@@ -175,3 +175,3 @@ if(this._checkLock(automation, service, state))

if(!this._isLocked(automation))
if(!this._isLocked(automation, service))
{

@@ -193,27 +193,34 @@ this.checkTrigger(automation, service, state);

async checkTrigger(automation, service, state)
checkTrigger(automation, service, state)
{
const TRIGGER = (blocks, logic) => {
return new Promise((resolve) => {
return new Promise((resolve) => {
const TRIGGER = (group) => {
var promiseArray = [];
return new Promise((resolve) => {
for(const block of blocks)
{
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 }))));
}
var promiseArray = [];
Promise.all(promiseArray).then((result) => {
for(const block of group.blocks)
{
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 }))));
}
if(!result.includes(null))
{
if(logic == 'AND' && AND(result))
Promise.all(promiseArray).then((result) => {
if(!result.includes(null))
{
resolve(true);
if(group.logic == 'AND' && AND(result))
{
resolve(true);
}
else if(group.logic == 'OR' && OR(result))
{
resolve(true);
}
else
{
resolve(false);
}
}
else if(logic == 'OR' && OR(result))
{
resolve(true);
}
else

@@ -223,76 +230,75 @@ {

}
}
else
{
resolve(false);
}
});
});
});
};
};
const AND = (blocks) => {
const AND = (blocks) => {
var success = true;
var success = true;
for(const block of blocks)
{
if(!this._getOutput(block.block, block.state))
for(const block of blocks)
{
success = false;
var output = this._getOutput(block.block, block.state);
if(!output)
{
success = false;
}
}
}
return success;
};
return success;
};
const OR = (blocks) => {
const OR = (blocks) => {
var success = false;
var success = false;
for(const block of blocks)
{
if(this._getOutput(block.block, block.state))
for(const block of blocks)
{
success = true;
var output = this._getOutput(block.block, block.state);
if(output)
{
success = true;
}
}
}
return success;
};
return success;
};
var promiseArray = [];
var groups = this._getGroups(automation.id), promiseArray = [];
if(automation.trigger != null && automation.trigger.groups != null)
{
for(const group of automation.trigger.groups)
for(const group of groups)
{
if(group.blocks != null && group.logic != null)
if(automation.trigger.logic == 'AND' || this._includesBlock(group.blocks, service))
{
promiseArray.push(TRIGGER(group.blocks, group.logic, service.id, service.letters));
promiseArray.push(TRIGGER(group));
}
}
}
Promise.all(promiseArray).then((triggers) => {
Promise.all(promiseArray).then((triggers) => {
if(automation.trigger.logic == 'AND' ? !triggers.includes(false) : automation.trigger.logic == 'OR' ? triggers.includes(true) : false)
{
if(automation.options == null
|| automation.options.timeLock == null
|| this.timeLock[automation.id] == null
|| new Date().getTime() >= this.timeLock[automation.id])
if(automation.trigger.logic == 'AND' ? !triggers.includes(false) : automation.trigger.logic == 'OR' ? triggers.includes(true) : false)
{
this.logger.debug('Automation [' + automation.name + '] %trigger_activated%');
if(automation.options == null
|| automation.options.timeLock == null
|| this.timeLock[automation.id] == null
|| new Date().getTime() >= this.timeLock[automation.id])
{
this.logger.debug('Automation [' + automation.name + '] %trigger_activated%');
this.executeResult(automation, service);
this.executeResult(automation, service);
}
}
}
else if(this.stateLock[automation.id] != null && this.stateLock[automation.id].result == true)
{
this.stateLock[automation.id].result = false;
else if(this.stateLock[automation.id] != null && this.stateLock[automation.id].result == true)
{
this.stateLock[automation.id].result = false;
this._updateSockets(false, automation.id);
this._updateSockets(false, automation.id);
this.logger.debug('Automation [' + automation.name + '] %automation_different% ' + automation.id);
}
this.logger.debug('Automation [' + automation.name + '] %automation_different% ' + automation.id);
}
resolve();
});
});

@@ -330,3 +336,3 @@ }

this._automationLock(automation, block);
this._automationLock(automation, { result : block });
}

@@ -371,3 +377,3 @@

this._automationLock(automation, block);
this._automationLock(automation, { result : block });
}

@@ -386,3 +392,3 @@

this._automationLock(automation, block);
this._automationLock(automation, { result : block });
}

@@ -408,8 +414,8 @@

{
this._automationLock(automation);
this.logger.log('success', trigger.id, trigger.letters, '[' + trigger.name + '] %automation_executed[0]% [' + automation.name + '] %automation_executed[1]%!');
this._automationLock(automation, { trigger });
this.ContextManager.updateAutomation(trigger.id, trigger.letters, automation);
this.logger.log('success', trigger.id, trigger.letters, '[' + trigger.name + '] %automation_executed[0]% [' + automation.name + '] %automation_executed[1]%!');
if(this.platform.bridgeConnection != null)

@@ -439,9 +445,9 @@ {

_automationLock(automation, block)
_automationLock(automation, entry = {})
{
var changed = false;
if(block != null)
if(entry.result != null)
{
if(block.options == null || block.options.stateLock != false)
if(entry.result.options == null || entry.result.options.stateLock != false)
{

@@ -463,4 +469,7 @@ if(this.stateLock[automation.id] == null)

}
else
if(entry.trigger != null)
{
var groups = this._getGroups(automation.id);
if(automation.options != null && automation.options.timeLock != null)

@@ -473,23 +482,29 @@ {

for(const i in automation.trigger.groups)
for(const i in groups)
{
for(const j in automation.trigger.groups[i].blocks)
if(automation.trigger.logic == 'AND' || this._includesBlock(groups[i].blocks, entry.trigger))
{
if(automation.trigger.groups[i].blocks[j].options != null && automation.trigger.groups[i].blocks[j].options.stateLock == true)
for(const j in groups[i].blocks)
{
if(this.stateLock[automation.id] == null)
if(groups[i].logic == 'AND' || ((groups[i].blocks[j].id == entry.trigger.id && groups[i].blocks[j].letters == entry.trigger.letters) || entry.trigger.days != null || entry.trigger.time != null))
{
this.stateLock[automation.id] = {};
}
if(groups[i].blocks[j].options != null && groups[i].blocks[j].options.stateLock == true)
{
if(this.stateLock[automation.id] == null)
{
this.stateLock[automation.id] = {};
}
if(this.stateLock[automation.id].trigger == null)
{
this.stateLock[automation.id].trigger = {};
}
if(this.stateLock[automation.id].trigger == null)
{
this.stateLock[automation.id].trigger = {};
}
this.stateLock[automation.id].trigger[i + '' + j] = true;
this.stateLock[automation.id].trigger[i + '' + j] = true;
this._updateSockets(true, automation.id, i + '' + j);
this._updateSockets(true, automation.id, i + '' + j);
changed = true;
changed = true;
}
}
}

@@ -653,16 +668,23 @@ }

_isLocked(automation)
_getGroups(id)
{
var blocks = this._getBlocks(automation.id);
var groups = [];
for(const block of blocks)
for(const automation of this.automation)
{
if(block.options != null
&& block.options.stateLock == true)
if((id == null || automation.id == id) && automation.trigger != null && automation.trigger.groups != null)
{
if(this.stateLock[automation.id] != null
&& this.stateLock[automation.id].trigger != null
&& this.stateLock[automation.id].trigger[block.blockID] == true)
for(const i in automation.trigger.groups)
{
return true;
if(automation.trigger.groups[i].blocks != null && automation.trigger.groups[i].logic != null)
{
var blocks = [];
for(const j in automation.trigger.groups[i].blocks)
{
blocks.push({ ...automation.trigger.groups[i].blocks[j], blockID : i + '' + j });
}
groups.push({ ...automation.trigger.groups[i], blocks, groupID : i });
}
}

@@ -672,2 +694,63 @@ }

return groups;
}
_isLocked(automation, service = {})
{
var groups = this._getGroups(automation.id), groupCounter = { lock : 0, locked : 0 };
for(const group of groups)
{
var blockCounter = { lock : 0, locked : 0 }, included = false;
for(const block of group.blocks)
{
if(block.options != null
&& block.options.stateLock == true)
{
if(this.stateLock[automation.id] != null
&& this.stateLock[automation.id].trigger != null
&& this.stateLock[automation.id].trigger[block.blockID] == true)
{
blockCounter.locked++;
}
blockCounter.lock++;
}
if((block.id == service.id && block.letters == service.letters) || block.days != null || block.time != null)
{
included = true;
}
}
if(blockCounter.lock > 0 && (automation.trigger.logic == 'AND' || included))
{
if(group.logic == 'AND' && blockCounter.locked > 0)
{
groupCounter.locked++;
}
if(group.logic == 'OR' && blockCounter.locked == blockCounter.lock)
{
groupCounter.locked++;
}
groupCounter.lock++;
}
}
if(groupCounter.lock > 0)
{
if(automation.trigger.logic == 'AND' && groupCounter.locked > 0)
{
return true;
}
if(automation.trigger.logic == 'OR' && groupCounter.locked == groupCounter.lock)
{
return true;
}
}
return false;

@@ -691,9 +774,7 @@ }

_includesBlock(automation, id, letters)
_includesBlock(blocks, service)
{
var blocks = this._getBlocks(automation.id);
for(const block of blocks)
{
if(block.id == id && block.letters == letters)
if(block.id == service.id && block.letters == service.letters)
{

@@ -738,4 +819,2 @@ return true;

this._updateSockets(false, automation.id, block.blockID);
if(block.operation == '<')

@@ -754,2 +833,4 @@ {

this._updateSockets(false, automation.id, block.blockID);
changed = true;

@@ -756,0 +837,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc