diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java index bf8f9405d9..f4c4d01b85 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java @@ -12,10 +12,7 @@ */ package org.openhab.core.automation.module.script.internal; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.CopyOnWriteArraySet; import javax.script.ScriptEngine; @@ -100,15 +97,18 @@ public class ScriptExtensionManager { } } - public void importPreset(String preset, ScriptEngineFactory engineProvider, ScriptEngine scriptEngine, + public Map importPreset(String preset, ScriptEngineFactory engineProvider, ScriptEngine scriptEngine, String scriptIdentifier) { + Map allValues = new HashMap<>(); for (ScriptExtensionProvider provider : scriptExtensionProviders) { if (provider.getPresets().contains(preset)) { Map scopeValues = provider.importPreset(scriptIdentifier, preset); engineProvider.scopeValues(scriptEngine, scopeValues); + allValues.putAll(scopeValues); } } + return allValues; } public void dispose(String scriptIdentifier) { diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManagerWrapper.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManagerWrapper.java index ffa2beb39e..247d600e9c 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManagerWrapper.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManagerWrapper.java @@ -13,9 +13,11 @@ package org.openhab.core.automation.module.script.internal; import java.util.List; +import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.automation.module.script.ScriptEngineContainer; +import org.openhab.core.automation.module.script.ScriptEngineFactory; import org.openhab.core.automation.module.script.ScriptExtensionProvider; /** @@ -56,7 +58,22 @@ public class ScriptExtensionManagerWrapper { return manager.getDefaultPresets(); } - public void importPreset(String preset) { - manager.importPreset(preset, container.getFactory(), container.getScriptEngine(), container.getIdentifier()); + /** + * Imports a collection of named host objects/classes into a script engine instance. Sets of objects are provided + * under their object name, and categorized by preset name. This method will import all named objects for a specific + * preset name. + * + * @implNote This call both returns the imported objects, and requests that the {@link ScriptEngineFactory} import them. + * The mechanism of how they are imported by the ScriptEngineFactory, or whether they are imported at all (aside from + * being returned by this call) is dependent of the implementation of the ScriptEngineFactory. + * + * @apiNote Objects may appear in multiple named presets. + * @see ScriptExtensionManager + * + * @param preset the name of the preset to import + * @return a map of host object names to objects + */ + public Map importPreset(String preset) { + return manager.importPreset(preset, container.getFactory(), container.getScriptEngine(), container.getIdentifier()); } }