I have been working for 25 years in Java, so I was thinking of writing openHAB rules in Groovy in pure Java syntax, but the helper libraries currently only support Jython very well.
So I am very thrilled of discovering your JRules.
It is a great idea, great work and an amazing enhancement to openHAB for programmers.
Still, even if the idea seems perfect to me, not everything is perfect yet, please allow me to give some feedback:
is the org.openhab.automation.jrule.rules.user package necessary or would another or the default package be sufficient?
The runtime would have to watch everything below jrule/rules
The protected String getRuleLogName() seems unnecessary bloat
why not just an optional annotation @Logger(“MY_TEST”) ?
I don’t like the underline in front of the item class name,
the package suffices as name space.
pure-annotation based Rules without inheritance
public class MySwitchRule extends JRule
couldn’t that be
@Rule
public class MySwitchRule
The rules should be pure-annotation based, no need for inheritance.
why do you need generated item classes in the first place?
to have a strongly typed item reference?
@JRuleWhen(item = _MyTestSwitch.ITEM, trigger = _MyTestSwitch.TRIGGER_CHANGED_TO_ON)
If you’d use the item String id as item reference, there’d be no need for the item classes, everything could be done in the runtime using the item and thing registries. I find it natural to use the item id in Java rules, too.
And no need for an ever changing items.jar in Eclipse or Maven.
@When(item = “MyTestSwitch”, trigger = JRULE.TRIGGER_ON)
The runtime can look up what TRIGGER_ON means for MyTestSwitch.
All (verbose!) compiler output should go into the log
2021-10-20 10:23:21.071 [INFO ] [rule.internal.compiler.JRuleCompiler] - Error on line 3 in file:///home/openhab/test/openhab-3.1.0/conf/automation/jrule/rules/org/openhab/automation/jrule/rules/user/MySwitchRule.java
(this is caused by the JRuleOnOffValue.ON import)
Or what about creating in the source folder a compiler output file in the spirit of JBoss’s .failed files?
MySwitchRule.java.failed containing all compiler output
additional classes in the rules package?
You cannot simply add additional classes that are no rules, can you? I don’t see them getting compiled.
Like
class MyDTO
and in the rule
String s = MyDTO.name;
With an @Rule annotation the JRules runtime can see what are rules and what are not.
The toplevel readme.md should show the minimal maven pom to build the rule.
I’d like a line about how to trigger the rule
In the Gui switch on the item, or …
Or what about a MySwitchRule.trigger file that changes in MySwitchRule.done or MySwitchRule.failed containing Exception stacktrace?
remote debugging
A huge advantage of Java rules is that you can remote debug them from Eclipse, this should go in the readme.
Greetings,
Jürgen