I've had a few users who want to use my rule templates but who also want to use .js files and JSRule for all their other rules. This means that they have a rule that gets called from a UI rule and when called data is passed to the called rule.
I UI rules one can simply use the passed in variables by name. Clearly that won't work with JSRule.
If not, would it be acceptable to do one of the following?
if there is no rule trigger (i.e. it was manually triggered), stuff data with anything extra that's in input
no matter how the rule is triggered, add anything extra in input to data
add input itself to data as raw
With option 1 and 2, if the calling rule passes a variable foo the callee rule would access that via event.foo.
With option 3, if the calling rule passed a variable foo the callee rule would access that via event.raw.foo (or something more appropriate if raw is the wrong name).
Before I go too far down the rabbit hole researching and prepare a PR I want to make sure it would be accepted in the first place. I'm inclined to use approach 3 as the least likely to cause problems now and in the long run.
I've had a few users who want to use my rule templates but who also want to use .js files and JSRule for all their other rules. This means that they have a rule that gets called from a UI rule and when called data is passed to the called rule.
I UI rules one can simply use the passed in variables by name. Clearly that won't work with JSRule.
I've looked at how the
event
Object is created: https://github.com/openhab/openhab-js/blob/523d874a192d97444f502c271e3ed32b8bc45c63/src/rules/rules.js#L358 and it's not clear to me what the last line of that function is doing. What's"module"
and does that contain the additional passed in data?If not, would it be acceptable to do one of the following?
data
with anything extra that's ininput
input
todata
input
itself todata
asraw
With option 1 and 2, if the calling rule passes a variable
foo
the callee rule would access that viaevent.foo
.With option 3, if the calling rule passed a variable
foo
the callee rule would access that viaevent.raw.foo
(or something more appropriate ifraw
is the wrong name).Or maybe
module
already does option 3? I assume this is the result from https://www.openhab.org/javadoc/latest/org/openhab/core/automation/rule#getModules() and the docs forModule
talk aboutInputs
but as far as I can tell this is not what I'm looking for.Before I go too far down the rabbit hole researching and prepare a PR I want to make sure it would be accepted in the first place. I'm inclined to use approach 3 as the least likely to cause problems now and in the long run.
Your Environment
openhab-js 5.0.0 is my current environment.