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 5f38ad008a7..a49e6ba85b4 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 @@ -150,9 +150,13 @@ class RulesJvmModelInferrer extends ScriptJvmModelInferrer { 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) - parameters += rule.toParameter(VAR_PREVIOUS_STATE, stateTypeRef) + if (containsThingStateChangedEventTrigger(rule)) { + val thingRef = ruleModel.newTypeRef(String) + parameters += rule.toParameter(VAR_TRIGGERING_THING, thingRef) + val oldStatusRef = ruleModel.newTypeRef(String) + parameters += rule.toParameter(VAR_PREVIOUS_STATUS, oldStatusRef) + val newStatusRef = ruleModel.newTypeRef(String) + parameters += rule.toParameter(VAR_NEW_STATUS, newStatusRef) } if ((containsStateChangeTrigger(rule) || containsStateUpdateTrigger(rule)) && !containsParam(parameters, VAR_NEW_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 d6634bddf54..cc3733fb9b8 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 @@ -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; @@ -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; } 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 d7e08a52f60..a8a92f7e1b9 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 @@ -61,6 +61,15 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer { /** Variable name for the triggering channel in a "trigger event" rule */ public static final String VAR_TRIGGERING_CHANNEL = "triggeringChannel"; + /** Variable name for the triggering thing in a "thing status trigger" rule */ + public static final String VAR_TRIGGERING_THING = "triggeringThing"; + + /** Variable name for the previous status of the triggering thing in a "thing status trigger" rule */ + public static final String VAR_PREVIOUS_STATUS = "previousStatus"; + + /** Variable name for the new status of the triggering thing in a "thing status trigger" rule */ + public static final String VAR_NEW_STATUS = "newStatus"; + /** * conveninence API to build and initialize JvmTypes and their members. */ @@ -124,6 +133,12 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer { parameters += script.toParameter(VAR_RECEIVED_EVENT, eventTypeRef) val channelRef = script.newTypeRef(String) parameters += script.toParameter(VAR_TRIGGERING_CHANNEL, channelRef) + val thingRef = script.newTypeRef(String) + parameters += script.toParameter(VAR_TRIGGERING_THING, thingRef) + val oldThingStatusRef = script.newTypeRef(String) + parameters += script.toParameter(VAR_PREVIOUS_STATUS, oldThingStatusRef) + val newThingStatusRef = script.newTypeRef(String) + parameters += script.toParameter(VAR_NEW_STATUS, newThingStatusRef) val stateTypeRef2 = script.newTypeRef(State) parameters += script.toParameter(VAR_NEW_STATE, stateTypeRef2) body = script