Skip to content

Commit

Permalink
Add triggeringThing name to DSL rules (openhab#2756)
Browse files Browse the repository at this point in the history
* Add triggeringThing name to DSL rules
* Include previous and new statuses

Signed-off-by: James Melville <[email protected]>
GitOrigin-RevId: 805f223
  • Loading branch information
jamesmelville authored and splatch committed Jul 12, 2023
1 parent 8550c06 commit efd00ca
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.openhab.core.model.script.jvmmodel.ScriptJvmModelInferrer;
import org.openhab.core.model.script.runtime.DSLScriptContextProvider;
import org.openhab.core.thing.events.ChannelTriggeredEvent;
import org.openhab.core.thing.events.ThingStatusInfoChangedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -173,6 +174,15 @@ private DefaultEvaluationContext createEvaluationContext(Script script, IEvaluat
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_ITEM_NAME),
event.getItemName());
}
if (value instanceof ThingStatusInfoChangedEvent) {
ThingStatusInfoChangedEvent event = (ThingStatusInfoChangedEvent) value;
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_THING),
event.getThingUID().toString());
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_PREVIOUS_STATUS),
event.getOldStatusInfo().getStatus().toString());
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_NEW_STATUS),
event.getStatusInfo().getStatus().toString());
}

return evalContext;
}
Expand Down

0 comments on commit efd00ca

Please sign in to comment.