From 674db6c74420da31a3c0378a1f32b37122d544f1 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Thu, 2 Dec 2021 22:08:17 +0100 Subject: [PATCH] Added variable 'triggeringChannel' to DSL rules (#2567) Signed-off-by: Christoph Weitkamp --- .../core/model/rule/jvmmodel/RulesJvmModelInferrer.xtend | 2 ++ .../script/runtime/internal/engine/DSLScriptEngine.java | 2 ++ .../core/model/script/jvmmodel/ScriptJvmModelInferrer.xtend | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/jvmmodel/RulesJvmModelInferrer.xtend b/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/jvmmodel/RulesJvmModelInferrer.xtend index 691101f36d8..22af6d24b4d 100644 --- a/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/jvmmodel/RulesJvmModelInferrer.xtend +++ b/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/jvmmodel/RulesJvmModelInferrer.xtend @@ -147,6 +147,8 @@ class RulesJvmModelInferrer extends ScriptJvmModelInferrer { if (containsEventTrigger(rule)) { val eventTypeRef = ruleModel.newTypeRef(String) parameters += rule.toParameter(VAR_RECEIVED_EVENT, eventTypeRef) + val channelRef = ruleModel.newTypeRef(String) + parameters += rule.toParameter(VAR_TRIGGERING_CHANNEL, channelRef) } if (containsThingStateChangedEventTrigger(rule) && !containsParam(parameters, VAR_PREVIOUS_STATE)) { val stateTypeRef = ruleModel.newTypeRef(State) diff --git a/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/DSLScriptEngine.java b/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/DSLScriptEngine.java index 489bd6e4636..bcf0b6d88d5 100644 --- a/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/DSLScriptEngine.java +++ b/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/DSLScriptEngine.java @@ -165,6 +165,8 @@ private DefaultEvaluationContext createEvaluationContext(Script script, IEvaluat if (value instanceof ChannelTriggeredEvent) { ChannelTriggeredEvent event = (ChannelTriggeredEvent) value; evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_RECEIVED_EVENT), event.getEvent()); + evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_CHANNEL), + event.getChannel().getAsString()); } if (value instanceof ItemEvent) { ItemEvent event = (ItemEvent) value; diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/jvmmodel/ScriptJvmModelInferrer.xtend b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/jvmmodel/ScriptJvmModelInferrer.xtend index 2dae0191e6a..538c3b082ee 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/jvmmodel/ScriptJvmModelInferrer.xtend +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/jvmmodel/ScriptJvmModelInferrer.xtend @@ -58,6 +58,9 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer { /** Variable name for the received event in a "trigger event" rule */ public static final String VAR_RECEIVED_EVENT = "receivedEvent"; + /** Variable name for the triggering channel in a "trigger event" rule */ + public static final String VAR_TRIGGERING_CHANNEL = "triggeringChannel"; + /** * conveninence API to build and initialize JvmTypes and their members. */ @@ -119,6 +122,8 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer { parameters += script.toParameter(VAR_PREVIOUS_STATE, stateTypeRef) val eventTypeRef = script.newTypeRef(String) parameters += script.toParameter(VAR_RECEIVED_EVENT, eventTypeRef) + val channelRef = script.newTypeRef(String) + parameters += script.toParameter(VAR_TRIGGERING_CHANNEL, channelRef) val stateTypeRef2 = script.newTypeRef(State) parameters += script.toParameter(VAR_NEW_STATE, stateTypeRef2) body = script