Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DSL][automation][WIP] Added methods to retrieve and update thing configurations via rules #583

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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<String, Object> 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<String, Object> configurationParameters) {
ThingActionService.updateThingConfiguration(thingUid, configurationParameters);
}

/**
* Get the actions instance for a Thing of a given scope
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -72,6 +72,25 @@ public static ThingStatusInfo getThingStatusInfo(String thingUid) {
}
}

public static Map<String, Object> getThingConfiguration(String thingUid) {
Thing thing = thingRegistry.get(new ThingUID(thingUid));
Map<String, Object> propertiesMap = new HashMap<>();
if (thing != null) {
propertiesMap.putAll(thing.getConfiguration().getProperties());
}
return propertiesMap;
}

public static void updateThingConfiguration(String thingUid, Map<String, Object> 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);
Expand Down