Jython modules - how to import all the things available in a script?

I noticed that in a jython module, I have to import a whole bunch of things that are normally automatically available in a script. For example:

  • items
  • DecimalType, PercentType, etc

How can I “equalize” them and import all the same stuff that’s available in a script?

Hi Jim,

normally they should be included by default as state here.
Did you follow the setup instructions and were you able to see the logs of the hello world rule?

Regards,
Sebastian.

@sebk, Yes, they are available by default in a script but they don’t seem to be available in a module (i.e. the ones in automation/lib/python/personal/)

I can import individual stuff like items with
from core.jsr223.scope import items, ON, OFF, DecimalType, and so on.

I tried, within my module:

scriptExtension.importPreset(None)

but that didn’t work either.

Ah, you are right. I overlooked that you referred to modules.

If I understand what you are asking for, the best you can do is import scope from core.jsr223 and prefix everything you need with scope… scope.items, scope.ON, scope.PercentType, etc. Why can’t you specifically import what you need?

What did you expect would happen with this?

I’m hoping it would import the Default preset as per: JSR223 Scripting | openHAB

Because I’m writing a module that would eval() code that I would not know in advance wat it would use. So I’m trying to make it so the eval()'d code can refer to anything normally available within a script. Please don’t preach to me about the safety of eval(). I am very well aware of it.

If only I could do

from core.jsr223.scope import *

that would solve it wouldn’t it?