I would like to move some logic from my rule files to standard java code, which can be unit tested.
Is it possible to put a simple pojo jar file into openhab2 and use that code in rules - as you would use for example the DateTime object.
So far, I have no idea to achieve this. “bundle:install” didn’t work either.
Time cron ...
var OpenHabAirControl obj = new OpenHabAirControl()
var String newState = obj.compute
I don’t know the direct answer to your question but suspect it is potentially possible. I would look to see how to build an add-on, which is essentially what you would be writing, for how to deploy it. In particular, look to see how to write an Action.
Another alternative would be to use the Exec binding and/or executeCommandLine, to call your external code. For example, your rule above would become:
val newState = executeCommandLine("java OpenHabAirControl 1 2", 5000)
- correct paths to java and OpenHabAirControl.class need to be right
- the script returns a String that can be easily parsed into a state itemAirControl supports
3 ways to reach my goal - very good. Thanks you.
JSR233 were indeed a cool solution. But so long I could help myself with the exec workaround.
I looked also into developing a virtual binding, but that would mean a lot of overhead. And all this stuff within Eclipse knocks me out … ;-(