Search in sources :

Example 26 with Trigger

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

the class TimerModuleHandlerFactory method internalCreate.

@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
    logger.trace("create {} -> {}", module.getId(), module.getTypeUID());
    String moduleTypeUID = module.getTypeUID();
    if (GenericCronTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
        return new GenericCronTriggerHandler((Trigger) module);
    } else if (TimeOfDayTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
        return new TimeOfDayTriggerHandler((Trigger) module);
    } else if (DayOfWeekConditionHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Condition) {
        return new DayOfWeekConditionHandler((Condition) module);
    } else {
        logger.error("The module handler type '{}' is not supported.", moduleTypeUID);
    }
    return null;
}
Also used : GenericCronTriggerHandler(org.eclipse.smarthome.automation.module.timer.handler.GenericCronTriggerHandler) Condition(org.eclipse.smarthome.automation.Condition) Trigger(org.eclipse.smarthome.automation.Trigger) DayOfWeekConditionHandler(org.eclipse.smarthome.automation.module.timer.handler.DayOfWeekConditionHandler) TimeOfDayTriggerHandler(org.eclipse.smarthome.automation.module.timer.handler.TimeOfDayTriggerHandler)

Example 27 with Trigger

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

the class ScriptedAutomationManager method addRule.

public Rule addRule(Rule element) {
    Rule rule = element.getUID() == null ? new Rule(generateUID()) : new Rule(element.getUID());
    String name = element.getName();
    if (name == null || name.isEmpty()) {
        name = element.getClass().getSimpleName();
        if (name.contains("$")) {
            name = name.substring(0, name.indexOf('$'));
        }
    }
    rule.setName(name);
    rule.setDescription(element.getDescription());
    rule.setTags(element.getTags());
    // used for numbering the modules of the rule
    int moduleIndex = 1;
    try {
        ArrayList<Condition> conditions = new ArrayList<>();
        for (Condition cond : element.getConditions()) {
            Condition toAdd = cond;
            if (cond.getId() == null || cond.getId().isEmpty()) {
                toAdd = new Condition(Integer.toString(moduleIndex++), cond.getTypeUID(), cond.getConfiguration(), cond.getInputs());
            }
            conditions.add(toAdd);
        }
        rule.setConditions(conditions);
    } catch (Exception ex) {
    // conditions are optional
    }
    try {
        ArrayList<Trigger> triggers = new ArrayList<>();
        for (Trigger trigger : element.getTriggers()) {
            Trigger toAdd = trigger;
            if (trigger.getId() == null || trigger.getId().isEmpty()) {
                toAdd = new Trigger(Integer.toString(moduleIndex++), trigger.getTypeUID(), trigger.getConfiguration());
            }
            triggers.add(toAdd);
        }
        rule.setTriggers(triggers);
    } catch (Exception ex) {
    // triggers are optional
    }
    ArrayList<Action> actions = new ArrayList<>();
    actions.addAll(element.getActions());
    if (element instanceof SimpleRuleActionHandler) {
        String privId = addPrivateActionHandler(new SimpleRuleActionHandlerDelegate((SimpleRuleActionHandler) element));
        Action scriptedAction = new Action(Integer.toString(moduleIndex++), "jsr223.ScriptedAction", new Configuration(), null);
        scriptedAction.getConfiguration().put("privId", privId);
        actions.add(scriptedAction);
    }
    rule.setActions(actions);
    ruleRegistryDelegate.add(rule);
    return rule;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Configuration(org.eclipse.smarthome.config.core.Configuration) SimpleRuleActionHandlerDelegate(org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandlerDelegate) ArrayList(java.util.ArrayList) Trigger(org.eclipse.smarthome.automation.Trigger) Rule(org.eclipse.smarthome.automation.Rule) SimpleRuleActionHandler(org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandler)

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