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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations