Accessing groups in library modules

Tags: #<Tag:0x00007f61789acac8> #<Tag:0x00007f61789ac9b0> #<Tag:0x00007f61789ac848>

I have the following items file:

Group  LIGHT_DEFAULTS "Group for light default settings"
Dimmer LIGHT_DEFAULT_ILUT  "Default for Ilumination Threshold [%d %%]" (LIGHT_DEFAULTS)
Switch LIGHT_DEFAULT_ALLD  "Default for all day light [%d %%]" (LIGHT_DEFAULTS)
Switch LIGHT_DEFAULT_ALIL  "Default for no ilimination limit [%d %%]" (LIGHT_DEFAULTS)
Dimmer LIGHT_DEFAULT_TIMO  "Default for timeout motion [%d %%]" (LIGHT_DEFAULTS)
Dimmer LIGHT_DEFAULT_TOFL  "Default for timeout forgot light [%d %%]" (LIGHT_DEFAULTS)
Dimmer LIGHT_DEFAULT_MIDI  "Default for minimum dim value [%d %%]" (LIGHT_DEFAULTS)
Dimmer LIGHT_DEFAULT_MADI  "Default for maximum dim value [%d %%]" (LIGHT_DEFAULTS)
Dimmer LIGHT_DEFAULT_BTDI  "Default for bed time dim value [%d %%]" (LIGHT_DEFAULTS)
Dimmer LIGHT_DEFAULT_DIST  "Default for dim step [%d %%]" (LIGHT_DEFAULTS)

here the snippet from my library modules class:

from core.triggers import ChannelEventTrigger
from core.log import logging, LOG_PREFIX
from threading import Timer
import yaml
from core.jsr223.scope import events, items, groups


log = logging.getLogger(LOG_PREFIX + ".this.is.my.log")



class light(object):

    def __init__(self, attrJsn, trigJsn):
        log.info("<<<items>>>")
        log.info(items)
        log.info("<<<groups>>>")
        log.info(groups)
        self.attr_default = 1
        self.all_attr = yaml.safe_load(attrJsn)
        self.all_trig = yaml.safe_load(trigJsn)

the log when class is loaded:

2020-02-17 11:18:19.973 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/openhab/conf/automation/jsr223/python/personal/lightControl.py
2020-02-17 11:18:20.191 [INFO ] [jsr223.jython.this.is.my.log        ] - <<<items>>>
2020-02-17 11:18:20.195 [INFO ] [jsr223.jython.this.is.my.log        ] - {LIGHT_DEFAULT_MIDI: NULL, LIGHT_DEFAULT_TOFL: NULL, LIGHT_DEFAULT_TIMO: NULL, testGU10L: 0, LIGHT_DEFAULT_ILUT: NULL, testGU10M: 0, LIGHT_DEFAULT_ALIL: NULL, LIGHT_DEFAULTS: NULL, LIGHT_DEFAULT_ALLD: NULL, LIGHT_DEFAULT_BTDI: NULL, LIGHT_DEFAULT_MADI: NULL, LIGHT_DEFAULT_DIST: NULL}
2020-02-17 11:18:20.199 [INFO ] [jsr223.jython.this.is.my.log        ] - <<<groups>>>
2020-02-17 11:18:20.203 [INFO ] [jsr223.jython.this.is.my.log        ] - None

how I see it the group in “items” is null and the “groups” do not contain anything either.

How do I traverse the group defined in items?
Am I totally overseeing something?

This is everything in the default script scope. There is no groups. The documentation has a whole section for examples of group operations, including iterating over a groups members…

for item in itemRegistry.getItem("LIGHT_DEFAULTS").members:
    # do stuff

To do this in a module, you will need to import itemRegistry

from core.jsr223.scope import itemRegistry