use of org.eclipse.smarthome.automation.Trigger 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;
}
use of org.eclipse.smarthome.automation.Trigger 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;
}
use of org.eclipse.smarthome.automation.Trigger in project smarthome by eclipse.
the class ModuleTypeResourceBundleProvider method createLocalizedTriggerType.
/**
* Utility method for localization of TriggerTypes.
*
* @param ct is a TriggerType for localization.
* @param bundle the bundle providing localization resources.
* @param moduleTypeUID is a TriggerType uid.
* @param locale represents a specific geographical, political, or cultural region.
* @param lconfigDescriptions are TriggerType localized config descriptions.
* @param llabel is a TriggerType localized label.
* @param ldescription is a TriggerType localized description.
* @return localized TriggerType.
*/
private TriggerType createLocalizedTriggerType(TriggerType tt, Bundle bundle, String moduleTypeUID, Locale locale, List<ConfigDescriptionParameter> lconfigDescriptions, String llabel, String ldescription) {
List<Output> outputs = ModuleTypeI18nUtil.getLocalizedOutputs(i18nProvider, tt.getOutputs(), bundle, moduleTypeUID, locale);
TriggerType ltt = null;
if (tt instanceof CompositeTriggerType) {
List<Trigger> modules = ModuleI18nUtil.getLocalizedModules(i18nProvider, ((CompositeTriggerType) tt).getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale);
ltt = new CompositeTriggerType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, tt.getTags(), tt.getVisibility(), outputs, modules);
} else {
ltt = new TriggerType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, tt.getTags(), tt.getVisibility(), outputs);
}
return ltt;
}
use of org.eclipse.smarthome.automation.Trigger 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);
}
use of org.eclipse.smarthome.automation.Trigger in project smarthome by eclipse.
the class ReferenceResolverUtilTest method testModuleConfigurationResolving.
@Test
public void testModuleConfigurationResolving() {
// test trigger configuration..
Module trigger = new Trigger(null, null, new Configuration(moduleConfiguration));
ReferenceResolverUtil.updateModuleConfiguration(trigger, context);
Assert.assertEquals(trigger.getConfiguration(), new Configuration(expectedModuleConfiguration));
// test condition configuration..
Module condition = new Condition(null, null, new Configuration(moduleConfiguration), null);
ReferenceResolverUtil.updateModuleConfiguration(condition, context);
Assert.assertEquals(condition.getConfiguration(), new Configuration(expectedModuleConfiguration));
// test action configuration..
Module action = new Action(null, null, new Configuration(moduleConfiguration), null);
ReferenceResolverUtil.updateModuleConfiguration(action, context);
Assert.assertEquals(action.getConfiguration(), new Configuration(expectedModuleConfiguration));
}
Aggregations