Search in sources :

Example 21 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class RuleUtils method getTriggersCopy.

/**
 * This method creates deep copy of list of triggers
 *
 * @param triggers list of triggers
 * @return deep copy of list of triggers or empty list when parameter is null.
 */
public static List<Trigger> getTriggersCopy(List<Trigger> triggers) {
    List<Trigger> res = new ArrayList<Trigger>();
    if (triggers != null) {
        for (Trigger t : triggers) {
            Trigger trigger = new Trigger(t.getId(), t.getTypeUID(), new Configuration(t.getConfiguration().getProperties()));
            trigger.setLabel(t.getLabel());
            trigger.setDescription(t.getDescription());
            res.add(trigger);
        }
    }
    return res;
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) ArrayList(java.util.ArrayList)

Example 22 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class TriggerDTOMapper method mapDto.

public static Trigger mapDto(final TriggerDTO triggerDto) {
    final Trigger trigger = new Trigger(triggerDto.id, triggerDto.type, new Configuration(triggerDto.configuration));
    trigger.setLabel(triggerDto.label);
    trigger.setDescription(triggerDto.description);
    return trigger;
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 23 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class ConditionDTOMapper method mapDto.

public static Condition mapDto(final ConditionDTO conditionDto) {
    final Condition condition = new Condition(conditionDto.id, conditionDto.type, new Configuration(conditionDto.configuration), conditionDto.inputs);
    condition.setLabel(conditionDto.label);
    condition.setDescription(conditionDto.description);
    return condition;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 24 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class RuleDTOMapper method map.

public static Rule map(final RuleDTO ruleDto) {
    final Rule rule = new Rule(ruleDto.uid, TriggerDTOMapper.mapDto(ruleDto.triggers), ConditionDTOMapper.mapDto(ruleDto.conditions), ActionDTOMapper.mapDto(ruleDto.actions), ConfigDescriptionDTOMapper.map(ruleDto.configDescriptions), new Configuration(ruleDto.configuration), ruleDto.templateUID, ruleDto.visibility);
    rule.setTags(ruleDto.tags);
    rule.setName(ruleDto.name);
    rule.setDescription(ruleDto.description);
    return rule;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Rule(org.eclipse.smarthome.automation.Rule)

Example 25 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class ThingFactoryHelper method createChannelBuilder.

static ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelType channelType, ConfigDescriptionRegistry configDescriptionRegistry) {
    ChannelBuilder channelBuilder = // 
    ChannelBuilder.create(channelUID, channelType.getItemType()).withType(// 
    channelType.getUID()).withDefaultTags(// 
    channelType.getTags()).withKind(// 
    channelType.getKind()).withLabel(channelType.getLabel());
    String description = channelType.getDescription();
    if (description != null) {
        channelBuilder = channelBuilder.withDescription(description);
    }
    // Initialize channel configuration with default-values
    URI channelConfigDescriptionURI = channelType.getConfigDescriptionURI();
    if (configDescriptionRegistry != null && channelConfigDescriptionURI != null) {
        ConfigDescription cd = configDescriptionRegistry.getConfigDescription(channelConfigDescriptionURI);
        if (cd != null) {
            Configuration config = new Configuration();
            for (ConfigDescriptionParameter param : cd.getParameters()) {
                String defaultValue = param.getDefault();
                if (defaultValue != null) {
                    Object value = getDefaultValueAsCorrectType(param.getType(), defaultValue);
                    if (value != null) {
                        config.put(param.getName(), value);
                    }
                }
            }
            channelBuilder = channelBuilder.withConfiguration(config);
        }
    }
    return channelBuilder;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ChannelBuilder(org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder) URI(java.net.URI)

Aggregations

Configuration (org.eclipse.smarthome.config.core.Configuration)119 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 ArrayList (java.util.ArrayList)18 Thing (org.eclipse.smarthome.core.thing.Thing)18 Action (org.eclipse.smarthome.automation.Action)16 Trigger (org.eclipse.smarthome.automation.Trigger)16 Rule (org.eclipse.smarthome.automation.Rule)15 Before (org.junit.Before)14 Condition (org.eclipse.smarthome.automation.Condition)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 HashMap (java.util.HashMap)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)8 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 BigDecimal (java.math.BigDecimal)6 Consumes (javax.ws.rs.Consumes)6 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)6