Skip to content

Commit 8a85486

Browse files
Textual Rules: evaluate global variables in the context of previous variables
1 parent 2c6fdb3 commit 8a85486

File tree

1 file changed

+1
-10
lines changed
  • bundles/org.openhab.core.model.rule.runtime/src/org/openhab/core/model/rule/runtime/internal

1 file changed

+1
-10
lines changed

bundles/org.openhab.core.model.rule.runtime/src/org/openhab/core/model/rule/runtime/internal/RuleContextHelper.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.eclipse.emf.ecore.util.EContentAdapter;
1717
import org.eclipse.jdt.annotation.NonNull;
1818
import org.eclipse.xtext.naming.QualifiedName;
19-
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
2019
import org.eclipse.xtext.xbase.interpreter.IEvaluationContext;
2120
import org.openhab.core.model.rule.RulesStandaloneSetup;
2221
import org.openhab.core.model.rule.rules.RuleModel;
@@ -61,7 +60,7 @@ public static synchronized IEvaluationContext getContext(RuleModel ruleModel) {
6160
for (VariableDeclaration var : ruleModel.getVariables()) {
6261
try {
6362
Object initialValue = var.getRight() == null ? null
64-
: scriptEngine.newScriptFromXExpression(var.getRight()).execute();
63+
: scriptEngine.newScriptFromXExpression(var.getRight()).execute(evaluationContext);
6564
evaluationContext.newValue(QualifiedName.create(var.getName()), initialValue);
6665
} catch (ScriptExecutionException e) {
6766
logger.warn("Variable '{}' on rule file '{}' cannot be initialized with value '{}': {}", var.getName(),
@@ -72,14 +71,6 @@ public static synchronized IEvaluationContext getContext(RuleModel ruleModel) {
7271
return evaluationContext;
7372
}
7473

75-
public static synchronized String getVariableDeclaration(RuleModel ruleModel) {
76-
StringBuilder vars = new StringBuilder();
77-
for (VariableDeclaration var : ruleModel.getVariables()) {
78-
vars.append(NodeModelUtils.findActualNodeFor(var).getText());
79-
}
80-
return vars.toString();
81-
}
82-
8374
/**
8475
* Inner class that wraps an evaluation context into an EMF adapters
8576
*/

0 commit comments

Comments
 (0)