[rules] Add original input to event for file-based rules #334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[JSRule] Add original input from the event that triggered a rule to the JS
event
Object passed to file based rulesDescription
There are circumstances where one may need to access the raw Java Objects from the event passed to a rule or to access variables passed into the rule by a calling rule. This PR adds the original contents of all the input passed to the rule as a
raw
property on theevent
Object passed into file based rules. Managed script actions and script condition always get the original and not the converted JSevent
Object.For a usage example, to access the property
foo
passed from a calling rule, useevent.raw.foo
orevent.raw['foo']
.Testing
To test I created a JS Rule that dumps the
event
Object.I then tested by manually running the following from the -Scratchpad- Script:
and verified that
event.raw.foo
is"bar"
andevent.raw.baz
is"bim"
.Next I exercised it from a rule that uses Thing trigger by instantiating an instance of https://community.openhab.org/t/thing-status-reporting-4-0-0-0-4-9-9-9/143180/ that calls this rule when ever a Thing changes status with a number of properties passed in. I then verified that the
event.raw
containsthingID
,oldStatus
,oldDetail
,newStatus
,newDetail
andthing
and each is the expected value. This second test was to ensure that the data gets passed both when a rule is called from a manually triggered rule and from an event triggered rule.Solves #333