Skip to content

Commit

Permalink
Update rules.js
Browse files Browse the repository at this point in the history
This code makes some changes to the rule generation which enables the use of the conditions.   I have been running this code for almost 2 years now without any issues.

I don't think this was implemented in the main fork but i made a pull requests on them.

see openhab-scripters#287

and  openhab-scripters#286 respectively.
  • Loading branch information
volfan6415 authored Feb 11, 2021
1 parent 4fae85d commit 205fb86
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Core/automation/lib/javascript/core/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ return RuleBuilder.create(ruleDto.uid)
try{
var ruid = uuid.randomUUID() + "-" + obj.name.replace(/[^\w]/g, "-");
logInfo("################ JSRule Line: "+__LINE__+" ################# ruid:" + ruid);


//var rule = new SimpleRule({ setUID: function(i) { uid = i; } })
var rule = new SimpleRule(){
var rule = new SimpleRule({
execute: obj.execute //DOES THIS WORK? AND IF YES, WHY? => execute is found in implemented SimpleRuleActionHandler
};
var triggers = obj.triggers ? obj.triggers : obj.getEventTrigger();
});
var triggers = obj.triggers ? decodeTriggers(obj.triggers) : obj.getEventTrigger();

rule.setTemplateUID(ruid);

Expand All @@ -110,6 +112,10 @@ return RuleBuilder.create(ruleDto.uid)
rule.setName(obj.name);
}

if (obj.conditions){
rule.setConditions(obj.conditions);
}

//1. Register rule here
if (triggers && triggers.length > 0) {
rule.setTriggers(triggers);
Expand All @@ -126,7 +132,6 @@ return RuleBuilder.create(ruleDto.uid)
}
return null;
},

//TODO like in org.openhab.core.automation.core.dto.RuleDTOMapper
// or org.openhab.core.automation.sample.extension.java.internal.WelcomeHomeRulesProvider
//Missing SimpleRuleActionHandler!!
Expand Down

0 comments on commit 205fb86

Please sign in to comment.