Search in sources :

Example 6 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class RuleTemplateRegistry method copyConditions.

private List<Condition> copyConditions(List<Condition> conditions) {
    List<Condition> res = new ArrayList<Condition>(11);
    if (conditions != null) {
        for (Condition c : conditions) {
            Configuration conf = new Configuration();
            conf.setProperties(c.getConfiguration().getProperties());
            Condition condition = new Condition(c.getId(), c.getTypeUID(), conf, new HashMap<String, String>(c.getInputs()));
            condition.setLabel(c.getLabel());
            condition.setDescription(c.getDescription());
            res.add(condition);
        }
    }
    return res;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Configuration(org.eclipse.smarthome.config.core.Configuration) ArrayList(java.util.ArrayList)

Example 7 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class CompositeConditionHandler method isSatisfied.

/**
 * The method calls handlers of child modules and return true only when they all are satisfied.
 *
 * @see org.eclipse.smarthome.automation.handler.ConditionHandler#isSatisfied(java.util.Map)
 */
@Override
public boolean isSatisfied(Map<String, Object> context) {
    List<Condition> children = getChildren();
    Map<String, Object> compositeContext = getCompositeContext(context);
    for (Condition child : children) {
        Map<String, Object> childContext = Collections.unmodifiableMap(getChildContext(child, compositeContext));
        ConditionHandler childHandler = moduleHandlerMap.get(child);
        boolean isSatisfied = childHandler.isSatisfied(childContext);
        if (!isSatisfied) {
            return false;
        }
    }
    return true;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) ConditionHandler(org.eclipse.smarthome.automation.handler.ConditionHandler)

Example 8 with Condition

use of org.eclipse.smarthome.automation.Condition 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 9 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class ModuleI18nUtil method createLocalizedCondition.

private static Condition createLocalizedCondition(Condition module, String label, String description) {
    Condition condition = new Condition(module.getId(), module.getTypeUID(), module.getConfiguration(), module.getInputs());
    condition.setLabel(label);
    condition.setDescription(description);
    return condition;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition)

Example 10 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class AirConditionerRuleTemplate method initialize.

public static AirConditionerRuleTemplate initialize() {
    // initialize triggers
    List<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(new Trigger(TRIGGER_ID, AirConditionerTriggerType.UID, null));
    // initialize conditions
    // here the tricky part is the giving a value to the condition configuration parameter.
    Configuration conditionConfig = new Configuration();
    conditionConfig.put(StateConditionType.CONFIG_STATE, "on");
    // here the tricky part is the referring into the condition input - trigger output.
    // The syntax is a similar to the JUEL syntax.
    Map<String, String> conditionInputs = new HashMap<String, String>();
    conditionInputs.put(StateConditionType.INPUT_CURRENT_STATE, TRIGGER_ID + "." + StateConditionType.INPUT_CURRENT_STATE);
    Condition stateCondition = new Condition("AirConditionerStateCondition", StateConditionType.UID, conditionConfig, conditionInputs);
    // here the tricky part is the referring into the condition configuration parameter - the
    // template configuration parameter. The syntax is a similar to the JUEL syntax.
    conditionConfig = new Configuration();
    conditionConfig.put(TemperatureConditionType.CONFIG_TEMPERATURE, "$" + CONFIG_TARGET_TEMPERATURE);
    conditionConfig.put(TemperatureConditionType.CONFIG_OPERATOR, "$" + CONFIG_OPERATION);
    // here the tricky part is the referring into the condition input - trigger output.
    // The syntax is a similar to the JUEL syntax.
    conditionInputs = new HashMap<String, String>();
    conditionInputs.put(TemperatureConditionType.INPUT_CURRENT_TEMPERATURE, TRIGGER_ID + "." + TemperatureConditionType.INPUT_CURRENT_TEMPERATURE);
    Condition temperatureCondition = new Condition("AirConditionerTemperatureCondition", TemperatureConditionType.UID, conditionConfig, conditionInputs);
    List<Condition> conditions = new ArrayList<Condition>();
    conditions.add(stateCondition);
    conditions.add(temperatureCondition);
    // initialize actions - here the tricky part is the referring into the action configuration parameter - the
    // template configuration parameter. The syntax is a similar to the JUEL syntax.
    Configuration actionConfig = new Configuration();
    actionConfig.put(WelcomeHomeActionType.CONFIG_DEVICE, "$" + WelcomeHomeRulesProvider.CONFIG_UNIT);
    actionConfig.put(WelcomeHomeActionType.CONFIG_RESULT, "$" + WelcomeHomeRulesProvider.CONFIG_EXPECTED_RESULT);
    List<Action> actions = new ArrayList<Action>();
    actions.add(new Action("AirConditionerSwitchOnAction", WelcomeHomeActionType.UID, actionConfig, null));
    // initialize configDescriptions
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<ConfigDescriptionParameter>();
    final ConfigDescriptionParameter device = ConfigDescriptionParameterBuilder.create(WelcomeHomeRulesProvider.CONFIG_UNIT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Device").withDescription("Device description").build();
    final ConfigDescriptionParameter result = ConfigDescriptionParameterBuilder.create(WelcomeHomeRulesProvider.CONFIG_EXPECTED_RESULT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Result").withDescription("Result description").build();
    final ConfigDescriptionParameter temperature = ConfigDescriptionParameterBuilder.create(CONFIG_TARGET_TEMPERATURE, Type.INTEGER).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Target temperature").withDescription("Indicates the target temperature.").build();
    final ConfigDescriptionParameter operation = ConfigDescriptionParameterBuilder.create(CONFIG_OPERATION, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Heating/Cooling").withDescription("Indicates Heating or Cooling is set.").build();
    configDescriptions.add(device);
    configDescriptions.add(result);
    configDescriptions.add(temperature);
    configDescriptions.add(operation);
    // initialize tags
    Set<String> tags = new HashSet<String>();
    tags.add("AirConditioner");
    tags.add("LivingRoom");
    // create the template
    return new AirConditionerRuleTemplate(tags, triggers, conditions, actions, configDescriptions);
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Trigger(org.eclipse.smarthome.automation.Trigger) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) HashSet(java.util.HashSet)

Aggregations

Condition (org.eclipse.smarthome.automation.Condition)21 Action (org.eclipse.smarthome.automation.Action)10 Configuration (org.eclipse.smarthome.config.core.Configuration)10 Trigger (org.eclipse.smarthome.automation.Trigger)9 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 Rule (org.eclipse.smarthome.automation.Rule)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)3 Set (java.util.Set)2 Module (org.eclipse.smarthome.automation.Module)2 RuleStatus (org.eclipse.smarthome.automation.RuleStatus)2 ConditionHandler (org.eclipse.smarthome.automation.handler.ConditionHandler)2 CompareConditionHandler (org.eclipse.smarthome.automation.module.core.handler.CompareConditionHandler)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1