Thank’s for looking into it.
I installed the jar by putting it into the addons directory. I guess you put it there too?
I used the classes in my script and verified the the outputs:
bundle:list |grep 'Solved'
371 x Active x 80 x 1.0.0.202010221430 x Problem Solved
openhab> bundle:capabilities de.no3x.openhab-jython-java-lib-problem^C
openhab> bundle:capabilities de.no3x.openhab-jython-java-lib-problem
de.no3x.openhab-jython-java-lib-problem_1.0.0.202010221430 [371] provides:
--------------------------------------------------------------------------
osgi.wiring.bundle; de.no3x.openhab-jython-java-lib-problem 1.0.0.202010221430 [UNUSED]
osgi.wiring.host; de.no3x.openhab-jython-java-lib-problem 1.0.0.202010221430 [UNUSED]
osgi.identity; de.no3x.openhab-jython-java-lib-problem 1.0.0.202010221430 [UNUSED]
osgi.wiring.package; de.no3x.core 1.0.0 required by:
org.openhab.core.automation.module.script_2.5.0 [367]
osgi.wiring.package; de.no3x.core.history 1.0.0 required by:
org.openhab.core.automation.module.script_2.5.0 [367]
osgi.wiring.package; de.no3x.core.input 1.0.0 [UNUSED]
osgi.wiring.package; de.no3x.core.output 1.0.0 [UNUSED]
openhab> bundle:requirements de.no3x.openhab-jython-java-lib-problem
de.no3x.openhab-jython-java-lib-problem_1.0.0.202010221430 [371] requires:
--------------------------------------------------------------------------
osgi.wiring.package; (&(osgi.wiring.package=com.google.common.collect)(&(version>=27.1.0)(!(version>=28.0.0)))) resolved by:
osgi.wiring.package; com.google.common.collect 27.1.0 from com.google.guava_27.1.0.jre [22]
osgi.ee; (&(osgi.ee=JavaSE)(version=1.8)) resolved by:
osgi.ee; JavaSE [1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0, 1.7.0, 1.8.0] from org.eclipse.osgi_3.12.100.v20180210-1608 [0]
My script looks like this:
"""
This script uses a decorated cron rule that will generate logs every 10s and can be used to test your initial setup.
"""
from de.no3x.core.history import StringHolder
from de.no3x.core.history import History
from de.no3x.core.output import BrightnessConsumer
from de.no3x.core import LEDBrightnessCalculator
from core.actions import LogAction
s = StringHolder("fasa")
print "s:", s.getString()
LogAction.logInfo("HelloWorld", s.getString())
history = History.create()
class LogOutputDevice(BrightnessConsumer):
def output(self, brightness):
LogAction.logInfo("HelloWorld", str(brightness))
logOutputDevice = LogOutputDevice()
brightnessCalculator = LEDBrightnessCalculator(history, lambda x: True, logOutputDevice)
brightnessCalculator.start()
The output is:
Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/hello_world.py': ImportError: No module named de in <script> at line number 5
Were you able to actually import the classes?
Edit:
I forgot that StringHolder was actually not included in this minified github Example.
The Code executes without error:
"""
This script uses a decorated cron rule that will generate logs every 10s and can be used to test your initial setup.
"""
from de.no3x.core.history import History
from de.no3x.core.output import BrightnessConsumer
from de.no3x.core import LEDBrightnessCalculator
from core.actions import LogAction
history = History.create()
class LogOutputDevice(BrightnessConsumer):
def output(self, brightness):
LogAction.logInfo("HelloWorld", str(brightness))
logOutputDevice = LogOutputDevice()
brightnessCalculator = LEDBrightnessCalculator(history, lambda x: True, logOutputDevice)
brightnessCalculator.start()
But there is no Output. If you compare the behaviour with the Main class then it sould log the calculated brightness every second. But there is no output and no error.
So basically I tried to convert the Main class to jython
Java:
History history = History.create();
LEDBrightnessCalculator brightnessCalculator = new LEDBrightnessCalculator(history, () -> true, System.out::println);
brightnessCalculator.start();
Which prints the caclulated value every second. E.g. when I simply execute the Main:
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
Jython:
from de.no3x.core.history import History
from de.no3x.core.output import BrightnessConsumer
from de.no3x.core.output import DefaultBrightnessConsumer
from de.no3x.core import LEDBrightnessCalculator
from core.actions import LogAction
history = History.create()
class LogOutputDevice(BrightnessConsumer):
def output(self, brightness):
LogAction.logInfo("HelloWorld", str(brightness))
logOutputDevice = LogOutputDevice()
defaultBrightnessConsumer = DefaultBrightnessConsumer()
brightnessCalculator = LEDBrightnessCalculator(history, lambda x: True, defaultBrightnessConsumer)
brightnessCalculator.start()
No output. No error. Not sure what/if it’s doing something.