Skip to content

Commit

Permalink
Added variable 'triggeringChannel' to DSL rules (#2567)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <[email protected]>
  • Loading branch information
cweitkamp authored Dec 2, 2021
1 parent e0544e2 commit 674db6c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 674db6c

Please sign in to comment.