openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[Groovy] Default preset does not include OnOffType #17247

Closed dilyanpalauzov closed 1 month ago

dilyanpalauzov commented 2 months ago

https://www.openhab.org/docs/configuration/jsr223.html#default-preset-importpreset-not-required says that the OnOffType is available in Groovy, as part of the Default preset.

I create a file in openhab/automation/jsr223/onoff.groovy with content:

OnOffType v = ON

Loading it fails:

2024-08-12 20:53:31.386 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script '/etc/openhab/automation/jsr223/onoff.groovy': org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/etc/openhab/automation/jsr223/onoff.groovy: 2: unable to resolve class OnOffType
 @ line 2, column 11.
   OnOffType v = ON
             ^

1 error

If I change onoff.groovy to:

import org.openhab.core.library.types.OnOffType
OnOffType v = ON

there is no error on loading.

So in OpenHAB 4.2.1 the Default preset for Groovy does not include OnOffType, contrary to the statement at https://www.openhab.org/docs/configuration/jsr223.html#default-preset-importpreset-not-required.

lsiepel commented 2 months ago

Are you aware of the last version that worked? Maybe @wborn can comment as most groovyscripting PR’s are his. I’m also interested in how this mechanism is setup, to provide future support

dilyanpalauzov commented 2 months ago

Are you aware of the last version that worked?

No, this is the first version I tried (OH 4.2.1).

wborn commented 1 month ago

I don't think it ever worked but I figured out a way for importing these additional classes in scripts with #17383.