Open wertzui opened 3 months ago
IMO JSRule should rather return nothing, I don’t see a usecase where the return value is needed.
My use case is that I want to get the generated UID after creating the rule.
I would rather manually set the UID of the rule than getting it afterwards.
And I would rather rely on the library to ensure valid and unique names 😉
Those names are however „unpredictable“ which indeed is a problem when using the UI to manually trigger the rule.
The thing is, I don’t want do document the return value of JSRule because I don’t want to encourage users to use the returned object. Without having a translation layer from Java to JS, users are likely to run into type problems and I don’t want to maintain this additional code.
I would instead propose to have JSRule just return the UID of the created rule.
Returning the UID would be fine for my use case, but it might not be for others.
What about writing a wrapper around the Java Rule
interface, just as Item
is a wrapper around the Java Item
interface?
That would probably break less peoples code, because the wrappers methods could still have the same names as the Java Rule
interface.
What about writing a wrapper around the Java Rule interface, just as Item is a wrapper around the Java Item interface?
As said above: I don’t want to maintain this additional code, which use case I consider fairly limited.
The raw Java rule provides:
getActions: JSRules have only one action, and this is the execute callback. getConditions: JSRules don’t have conditions. getConfiguration: JSRule does not set configuration, nothing to get here. getConfigurationDescriptions: same as above getDescription: This is what you set as descriptions, instead of getting it afterwards memorise it. getModule: Gets a action/condition/trigger by id. See explanation above for them. getName: same as getDescription getTags: same as getDescription getTemplateUid: should not be set for JSRules. getTriggers: see above. getUid: only useful method. getVisibility: is always visible, method not useful.
So as you can see it is only the UID getter that is useful.
rules.JsRule({...});
returns aHostRule
, butHostRule
is only defined asobject
with a documentation link to https://www.openhab.org/javadoc/latest/org/openhab/core/automation/rule.It would be good if the complete type for
HostRule
would be provided.