Upgrade to 2.5.5 and having issues with JSR223

  • Platform information:
    • Hardware: _CPUArchitecture/RAM/storage_RaspberriPi3
    • OS: what OS is used and which version
    • Java Runtime Environment: _which java platform is used and what version_jython-standalone-2.7.0
    • openHAB version:
      After upgrading from 2.4 to 2.5.5 Release build many issues most easily fixed from these forums thanks.
      Last issues all seem to be the same the error is
      2020-06-16 16:48:02.239 [INFO ] [me.core.service.AbstractWatchService] - Loading script ‘python/core/components/100_OsgiEventTrigger.py’

2020-06-16 16:48:02.712 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/python/core/components/100_OsgiEventTrigger.py’: ImportError: cannot import name bundle_context in at line number 8
They all seem similar here’s the beginning of the file
“”"
This rule trigger responds to events on the OSGi EventAdmin event bus.
“”"
import traceback
scriptExtension.importPreset(None)# fix for compatibility with Jython > 2.7.0
import core
import core.osgi.events
reload(core.osgi.events)
from core.osgi.events import OsgiEventAdmin, event_dict, OSGI_TRIGGERS
from core.log import logging, LOG_PREFIX

Thanks for any help

You can ignore these errors. Are your rules working? Are you using the beta Jython add-on? If not, how recent are the helper libraries?

Welcome to the forum!

Thanks for the help.
I put the new helper libraries in because of all the errors after upgrading. Some rules are working and some seem to not be. Since the error doesn’t matter I’ll look into it some more and let you know.
Thanks again

I’m getting the same error on the triggers
Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/testswitch.py’: ImportError: cannot import name bundle_context in at line number 4

from org.slf4j import LoggerFactory
scriptExtension.importPreset(“RuleSupport”)
scriptExtension.importPreset(“RuleSimple”)
from core.triggers import ItemCommandTrigger, ItemStateChangeTrigger, ItemStateUpdateTrigger, CronTrigger
from core.jsr223.scope import events, itemRegistry

and none of the triggers are firing. This is from a simple test script to check things etc.
All the files under automation were updated from openhab on github yesterday.
Rules not using triggers on updating are running ok.

Thanks…Greg

If this is a script, then don’t do this. events and itemRegistry are included in the default script scope. Modules are the only place you would need core.jsr223.scope.

I have not used extensions for a while. Why not use the when decorator? I merged some changes a few days ago, but I am not seeing this error. I have some more to merge though. I’ll do some more tests though…

even with a decorator I’d still need the imports correct. I did remove the trigger and the trigger is now firing.
I changed the import for audio from
from openhab.actions import Audio
to
from core.actions import Audio
It fails when going to play a sound.
I don’t want to waste your time is there documentation I missed on what the calls(Imports) where and are now.
Thanks again

I setup a new test environment and can reproduce this. It must be a bug that I recently introduced. Give me a few minutes and I’ll track it down…

You wouldn’t have this problem with the beta Jython addon :wink:

On line 29 of core.osgi.events, replace…

from core.osgi import bundle_context

… with…

from core.osgi import BUNDLE_CONTEXT

… then restart OH. I’ll merge a PR tonight with a real fix, but this should get you going again.

Thanks a lot. I downloaded your addon earlier and am installing it now.
It’ll be a lot easier for most to get up and running with it.

1 Like

I installed the jar in the addons and didn’t see anything in the logs. I do have other things installed thru the addons that are working.
Is there anything you’d like me to try?

Where is the core.osgi.events file located?
thanks…Greg

When I changed the file name to end in .org the jython addon now is working, but I’m still getting the same error as before with bundle_context.
So I can fix it if you tell where core.osgi.events is located.

Thanks again…Greg

In the core libraries… $OPENHAB_CONF/automation/lib/python/core/osgi/events.py

https://openhab-scripters.github.io/openhab-helper-libraries/Getting%20Started/File%20Locations.html

If you use the addon, remember to remove the Jython entries from your EXTRA_JAVA_OPTS.

Which file and why did you rename it?

Thanks I was way overthinking it. I was looking for a file called core.osgi.events.

I did remove it from the extra_java_opts yesterday and renamed the jython-standalone-2.7.0.jar and rebooted. No scripts ran.
I saw someone renamed org.openhab.core.automation.module.script.scriptenginefactory.jython-2.5.0-SNAPSHOT.jar.org by adding .org at the end.
When I did that after rebooting my scripts started running again

Where did you find that? Renaming the file will not change anything and could mess some things up.

Glad you got it all working!

I think you need to change
100_OsgiEventTrigger.py
line 10 from core.osgi.events import OsgiEventAdmin, event_dict, osgi_triggers #OSGI_TRIGGERS

I’m looking into why audio isn’t playing and will let you know what I find.

Thanks again for the help…Greg

Yes, but that wouldn’t prevent the loading of rules. I’m about the push the fix but it lured me into troubleshooting why the OsgiEventTrigger is not working!

OK… pushed!

Was this for the helper libraries?

Yes

FYI it was
org.openhab.core.library.types that was causing Audio.playSound to error