How to use `itemRegistry` within a jython-**module**?

from openhab.jsr223 import scope
item = scope.itemRegistry.getItem("TEST")

Some context… the JSR223 script scope variables are mostly script-independent. There are types (e.g., SimpleRule) and global-ish objects like itemRegistry (an instance of the ‘ItemRegistry’ type). These objects are safe to import normally into Jython modules. However, the automationManager scope instance is per-script. You can’t import this into a module because the module instance will be the one associated with the first script that imports the module and will be invalid for other script imports. The get_automation_manager function avoids this problem because the module queries the scope for the script-specific automation manager each time it is used.

1 Like