@vbier, there appears to be an issue with the classloader. It also looks like there has always been a problem with how the scope variables are loaded for the Groovy script engine. DecimalType is included in the default scope, Action and Configuration are in RuleSupport, and SimpleRule is in RuleSimple, so they should not have to be imported.
import org.openhab.core.automation.*
import org.openhab.core.automation.module.script.rulesupport.shared.simple.*
import org.eclipse.smarthome.config.core.Configuration
scriptExtension.importPreset("RuleSupport")
scriptExtension.importPreset("RuleSimple")
import org.slf4j.*
def log = LoggerFactory.getLogger('jsr223.groovy')
def testGroovyRule = new SimpleRule() {
Object execute(Action module, Map<String, ?> inputs) {
//log.warn("Hello World from Groovy")
log.warn("\n{}", (binding.variables as String).replace(",", ",\n"))
}
}
testGroovyRule.setTriggers([
TriggerBuilder.create()
.withId("aTimerTrigger")
.withTypeUID("timer.GenericCronTrigger")
.withConfiguration(new Configuration([cronExpression: "0/10 * * * * ?"]))
.build()
])
testGroovyRule.setName("Test Groovy: display binding variables")
automationManager.addRule(testGroovyRule)
This rule logs everything available in the context, and shows DecimalType is available, but everything that is a class is not accessible from Groovy. This just could be my inexperience with Groovy though. The NashornScriptEngineFactory has a JS specific workaround for this particular issue (compare this to what is used by Groovy and Jython), so maybe there is something similar that can be done for Groovy. Iāve had to work on some other things and havenāt had a chance to dig into this yet.
[voice:org.eclipse.smarthome.core.voice.internal.VoiceManagerImpl@bf01298,
DOWN:DOWN,
ActionType:class org.eclipse.smarthome.automation.type.ActionType,
Configuration:class org.eclipse.smarthome.config.core.Configuration,
FileUtils:class org.apache.commons.io.FileUtils,
StringType:class org.eclipse.smarthome.core.library.types.StringType,
rules:org.eclipse.smarthome.automation.core.internal.RuleRegistryImpl@1078852,
ruleRegistry:org.eclipse.smarthome.automation.module.script.rulesupport.shared.RuleSupportRuleRegistryDelegate@5306b84,
NextPreviousType:class org.eclipse.smarthome.core.library.types.NextPreviousType,
PLAY:PLAY,
ImperialUnits:class org.eclipse.smarthome.core.library.unit.ImperialUnits,
SimpleRule:class org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRule,
ModuleType:class org.eclipse.smarthome.automation.type.ModuleType,
Trigger:interface org.eclipse.smarthome.automation.Trigger,
INCREASE:INCREASE,
OpenClosedType:class org.eclipse.smarthome.core.library.types.OpenClosedType,
things:org.eclipse.smarthome.core.thing.internal.ThingRegistryImpl@49340cca,
UP:UP,
RawType:class org.eclipse.smarthome.core.library.types.RawType,
StringListType:class org.eclipse.smarthome.core.library.types.StringListType,
events:org.eclipse.smarthome.automation.module.script.defaultscope.internal.ScriptBusEvent@425bb3a6,
SIUnits:class org.eclipse.smarthome.core.library.unit.SIUnits,
itemRegistry:org.eclipse.smarthome.core.internal.items.ItemRegistryImpl@193c064d,
TriggerType:class org.eclipse.smarthome.automation.type.TriggerType,
NULL:NULL,
STOP:STOP,
UnDefType:class org.eclipse.smarthome.core.types.UnDefType,
ir:org.eclipse.smarthome.core.internal.items.ItemRegistryImpl@193c064d,
TriggerBuilder:class org.eclipse.smarthome.automation.core.util.TriggerBuilder,
RewindFastforwardType:class org.eclipse.smarthome.core.library.types.RewindFastforwardType,
DateTimeType:class org.eclipse.smarthome.core.library.types.DateTimeType,
QuantityType:class org.eclipse.smarthome.core.library.types.QuantityType,
State:interface org.eclipse.smarthome.core.types.State,
DecimalType:class org.eclipse.smarthome.core.library.types.DecimalType,
IncreaseDecreaseType:class org.eclipse.smarthome.core.library.types.IncreaseDecreaseType,
Visibility:class org.eclipse.smarthome.automation.Visibility,
Rule:interface org.eclipse.smarthome.automation.Rule,
File:class java.io.File,
items:[Virtual_Number_1:5],
actions:org.eclipse.smarthome.automation.module.script.defaultscope.internal.ScriptThingActions@7f23e6a7,
Action:interface org.eclipse.smarthome.automation.Action,
CLOSED:CLOSED,
ActionBuilder:class org.eclipse.smarthome.automation.core.util.ActionBuilder,
MetricPrefix:class org.eclipse.smarthome.core.library.unit.MetricPrefix,
DECREASE:DECREASE,
OFF:OFF,
StopMoveType:class org.eclipse.smarthome.core.library.types.StopMoveType,
PREVIOUS:PREVIOUS,
PAUSE:PAUSE,
se:org.eclipse.smarthome.automation.module.script.internal.ScriptExtensionManagerWrapper@10ffffa,
SimpleConditionHandler:class org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleConditionHandler,
StringUtils:class org.apache.commons.lang.StringUtils,
NEXT:NEXT,
REWIND:REWIND,
audio:org.eclipse.smarthome.core.audio.internal.AudioManagerImpl@67b87a8e,
URLEncoder:class java.net.URLEncoder,
HSBType:class org.eclipse.smarthome.core.library.types.HSBType,
SimpleTriggerHandler:class org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleTriggerHandler,
ON:ON,
Condition:interface org.eclipse.smarthome.automation.Condition,
SmartHomeUnits:class org.eclipse.smarthome.core.library.unit.SmartHomeUnits,
scriptExtension:org.eclipse.smarthome.automation.module.script.internal.ScriptExtensionManagerWrapper@10ffffa,
ModuleBuilder:class org.eclipse.smarthome.automation.core.util.ModuleBuilder,
UpDownType:class org.eclipse.smarthome.core.library.types.UpDownType,
PercentType:class org.eclipse.smarthome.core.library.types.PercentType,
FilenameUtils:class org.apache.commons.io.FilenameUtils,
OPEN:OPEN,
automationManager:org.eclipse.smarthome.automation.module.script.rulesupport.shared.ScriptedAutomationManager@440d61bf,
SimpleActionHandler:class org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleActionHandler,
ConditionBuilder:class org.eclipse.smarthome.automation.core.util.ConditionBuilder,
Command:interface org.eclipse.smarthome.core.types.Command,
OnOffType:class org.eclipse.smarthome.core.library.types.OnOffType,
MOVE:MOVE,
PlayPauseType:class org.eclipse.smarthome.core.library.types.PlayPauseType,
FASTFORWARD:FASTFORWARD,
PointType:class org.eclipse.smarthome.core.library.types.PointType,
ConfigDescriptionParameter:class org.eclipse.smarthome.config.core.ConfigDescriptionParameter,
UNDEF:UNDEF]
I saw the same results with 2.5.6 and 2.4.12. Out of curiosity, which version of Groovy are you using?