[JSRule] Add original input from the event that triggered a rule to the JS event Object passed to file based rules
Description
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 the event Object passed into file based rules. Managed script actions and script condition always get the original and not the converted JS event Object.
For a usage example, to access the property foo passed from a calling rule, use event.raw.foo or event.raw['foo'].
Testing
To test I created a JS Rule that dumps the event Object.
and verified that event.raw.foo is "bar" and event.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 contains thingID, oldStatus, oldDetail, newStatus, newDetail and thing 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.
[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