diff --git a/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/actions/Things.java b/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/actions/Things.java index 628136e0800..47fa0c0cf24 100644 --- a/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/actions/Things.java +++ b/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/actions/Things.java @@ -12,6 +12,9 @@ */ package org.eclipse.smarthome.model.script.actions; +import java.util.Map; + +import org.eclipse.smarthome.config.core.validation.ConfigValidationException; import org.eclipse.smarthome.core.thing.ThingStatusInfo; import org.eclipse.smarthome.core.thing.binding.ThingActions; import org.eclipse.smarthome.model.script.internal.engine.action.ThingActionService; @@ -22,7 +25,7 @@ * * @author Maoliang Huang - Initial contribution * @author Kai Kreuzer - Extended for general thing access - * + * @author Christoph Weitkamp - Added methods to retrieve and update thing configurations */ public class Things { @@ -36,6 +39,28 @@ public static ThingStatusInfo getThingStatusInfo(String thingUid) { return ThingActionService.getThingStatusInfo(thingUid); } + /** + * Retrieves the configuration of a Thing + * + * @param thingUid The uid of the thing + * @return a map of configuration parameters + */ + public static Map getThingConfiguration(String thingUid) { + return ThingActionService.getThingConfiguration(thingUid); + } + + /** + * Updates the configuration of a Thing + * + * @param thingUid The uid of the thing + * @param configurationParameters map of changed configuration parameters + * @throws ConfigValidationException if one or more of the given configuration parameters do not match their + * declarations in the configuration description + */ + public static void updateThingConfiguration(String thingUid, Map configurationParameters) { + ThingActionService.updateThingConfiguration(thingUid, configurationParameters); + } + /** * Get the actions instance for a Thing of a given scope * diff --git a/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/internal/engine/action/ThingActionService.java b/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/internal/engine/action/ThingActionService.java index 41c7723e160..bf0d774a8ce 100644 --- a/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/internal/engine/action/ThingActionService.java +++ b/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/internal/engine/action/ThingActionService.java @@ -34,7 +34,7 @@ * * @author Maoliang Huang - Initial contribution * @author Kai Kreuzer - Extended for general thing access - * + * @author Christoph Weitkamp - Added methods to retrieve and update thing configurations */ @Component(immediate = true) public class ThingActionService implements ActionService { @@ -72,6 +72,25 @@ public static ThingStatusInfo getThingStatusInfo(String thingUid) { } } + public static Map getThingConfiguration(String thingUid) { + Thing thing = thingRegistry.get(new ThingUID(thingUid)); + Map propertiesMap = new HashMap<>(); + if (thing != null) { + propertiesMap.putAll(thing.getConfiguration().getProperties()); + } + return propertiesMap; + } + + public static void updateThingConfiguration(String thingUid, Map configurationParameters) { + Thing thing = thingRegistry.get(new ThingUID(thingUid)); + if (thing != null) { + ThingHandler handler = thing.getHandler(); + if (handler != null) { + handler.handleConfigurationUpdate(configurationParameters); + } + } + } + public static ThingActions getActions(String scope, String thingUid) { ThingUID uid = new ThingUID(thingUid); Thing thing = thingRegistry.get(uid);