Skip to content

Commit

Permalink
Merge pull request eclipse-archived#988 from cdjackson/channel_dto_co…
Browse files Browse the repository at this point in the history
…nfig

Add configuration object to ChannelDTO
  • Loading branch information
kaikreuzer committed Feb 6, 2016
2 parents c81b447 + 17c8d3f commit 93b5027
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
*/
package org.eclipse.smarthome.core.thing.dto;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.smarthome.config.core.Configuration;

/**
* This is a data transfer object that is used to serialize channels.
*
* @author Dennis Nobel - Initial contribution
* @author Chris Jackson - Added properties
* @author Chris Jackson - Added properties and configuration
*/
public class ChannelDTO {

Expand All @@ -23,17 +26,31 @@ public class ChannelDTO {
public String channelTypeUID;
public String itemType;
public Map<String, String> properties;
public Map<String, Object> configuration;

public ChannelDTO() {
}

public ChannelDTO(String id, String channelTypeUID, String itemType, List<String> linkedItems,
Map<String, String> properties) {
Map<String, String> properties, Configuration configuration) {
this.id = id;
this.channelTypeUID = channelTypeUID;
this.itemType = itemType;
this.linkedItems = linkedItems;
this.properties = properties;
this.configuration = toMap(configuration);
}

private Map<String, Object> toMap(Configuration configuration) {

if (configuration == null) {
return null;
}

Map<String, Object> configurationMap = new HashMap<>(configuration.keySet().size());
for (String key : configuration.keySet()) {
configurationMap.put(key, configuration.get(key));
}
return configurationMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public static ChannelDTO map(Channel channel) {
ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
String channelTypeUIDValue = channelTypeUID != null ? channelTypeUID.toString() : null;
return new ChannelDTO(channel.getUID().getId(), channelTypeUIDValue, channel.getAcceptedItemType().toString(),
linkedItemNames, channel.getProperties());
linkedItemNames, channel.getProperties(), channel.getConfiguration());
}
}

0 comments on commit 93b5027

Please sign in to comment.