Search in sources :

Example 11 with Trigger

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;
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) ArrayList(java.util.ArrayList)

Example 12 with Trigger

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;
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 13 with 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;
}
Also used : CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) TriggerType(org.eclipse.smarthome.automation.type.TriggerType) CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) Trigger(org.eclipse.smarthome.automation.Trigger) Output(org.eclipse.smarthome.automation.type.Output)

Example 14 with Trigger

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

Example 15 with Trigger

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));
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) Module(org.eclipse.smarthome.automation.Module) Test(org.junit.Test)

Aggregations

Trigger (org.eclipse.smarthome.automation.Trigger)27 Action (org.eclipse.smarthome.automation.Action)14 Configuration (org.eclipse.smarthome.config.core.Configuration)14 ArrayList (java.util.ArrayList)8 Condition (org.eclipse.smarthome.automation.Condition)8 Rule (org.eclipse.smarthome.automation.Rule)8 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 Set (java.util.Set)4 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)4 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 TriggerHandler (org.eclipse.smarthome.automation.handler.TriggerHandler)3 TriggerType (org.eclipse.smarthome.automation.type.TriggerType)3 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)3 Event (org.eclipse.smarthome.core.events.Event)3 EventFilter (org.eclipse.smarthome.core.events.EventFilter)3 EventSubscriber (org.eclipse.smarthome.core.events.EventSubscriber)3