Search in sources :

Example 16 with Trigger

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

the class ModuleI18nUtil method createLocalizedTrigger.

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

Example 17 with Trigger

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

the class SampleHandlerFactory method internalCreate.

@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
    ModuleHandler moduleHandler = null;
    if (SUPPORTED_TRIGGER.equals(module.getTypeUID())) {
        moduleHandler = new SampleTriggerHandler((Trigger) module, ruleUID);
        createdTriggerHandler.add((TriggerHandler) moduleHandler);
    } else if (SUPPORTED_CONDITION.equals(module.getTypeUID())) {
        moduleHandler = new SampleConditionHandler((Condition) module);
    } else if (SUPPORTED_ACTION.equals(module.getTypeUID())) {
        moduleHandler = new SampleActionHandler((Action) module);
    } else {
        logger.error(MODULE_HANDLER_FACTORY_NAME + "Not supported moduleHandler: {}", module.getTypeUID());
    }
    return moduleHandler;
}
Also used : ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger)

Example 18 with Trigger

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

the class SampleJavaDemo method addRule.

void addRule() {
    final Configuration triggerConfig = new Configuration();
    triggerConfig.put("itemName", "DemoSwitch");
    final Trigger ruleTrigger = new Trigger("RuleTrigger", "ItemStateChangeTrigger", triggerConfig);
    final Configuration actionConfig = new Configuration();
    actionConfig.put("itemName", "DemoDimmer");
    actionConfig.put("command", "ON");
    final Action ruleAction = new Action("RuleAction", "ItemPostCommandAction", actionConfig, null);
    final ArrayList<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(ruleTrigger);
    final ArrayList<Action> actions = new ArrayList<Action>();
    actions.add(ruleAction);
    final Rule r = new Rule(RULE_UID, triggers, null, actions, null, null, null, Visibility.VISIBLE);
    r.setName("DemoRule");
    ruleRegistry.add(r);
}
Also used : Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) ArrayList(java.util.ArrayList) Rule(org.eclipse.smarthome.automation.Rule)

Example 19 with Trigger

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

the class WelcomeHomeRulesProvider method createLightsRule.

/**
 * This method creates a rule from scratch by using trigger, condition, action, configDescriptions and
 * configuration, tags.
 *
 * @return the created rule
 */
private Rule createLightsRule() {
    // initialize the trigger
    String triggerId = "LightsSwitchOnRuleTrigger";
    List<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(new Trigger(triggerId, LightsTriggerType.UID, null));
    // initialize the condition - here the tricky part is the referring into the condition input - trigger output.
    // The syntax is a similar to the JUEL syntax.
    Configuration config = new Configuration();
    config.put(StateConditionType.CONFIG_STATE, "on");
    List<Condition> conditions = new ArrayList<Condition>();
    Map<String, String> inputs = new HashMap<String, String>();
    inputs.put(StateConditionType.INPUT_CURRENT_STATE, triggerId + "." + StateConditionType.INPUT_CURRENT_STATE);
    conditions.add(new Condition("LightsStateCondition", StateConditionType.UID, config, inputs));
    // initialize the action - 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.
    config = new Configuration();
    config.put(WelcomeHomeActionType.CONFIG_DEVICE, "Lights");
    config.put(WelcomeHomeActionType.CONFIG_RESULT, "Lights are switched on");
    List<Action> actions = new ArrayList<Action>();
    actions.add(new Action("LightsSwitchOnAction", WelcomeHomeActionType.UID, config, null));
    // initialize the 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();
    configDescriptions.add(device);
    configDescriptions.add(result);
    // initialize the configuration
    config = new Configuration();
    config.put(CONFIG_UNIT, "Lights");
    config.put(CONFIG_EXPECTED_RESULT, "The lights are switched on.");
    // create the rule
    Rule lightsSwitchOn = new Rule(L_UID);
    lightsSwitchOn.setTriggers(triggers);
    lightsSwitchOn.setConfigurationDescriptions(configDescriptions);
    lightsSwitchOn.setConditions(conditions);
    lightsSwitchOn.setActions(actions);
    // initialize the tags
    Set<String> tags = new HashSet<String>();
    tags.add("lights");
    // set the tags
    lightsSwitchOn.setTags(tags);
    return lightsSwitchOn;
}
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) Rule(org.eclipse.smarthome.automation.Rule) HashSet(java.util.HashSet)

Example 20 with Trigger

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

the class RunRuleModuleTest method createOuterRule.

private Rule createOuterRule() {
    final Configuration outerRuleTriggerConfig = new Configuration(Collections.unmodifiableMap(Stream.of(new SimpleEntry<>("eventSource", "ruleTrigger"), new SimpleEntry<>("eventTopic", "smarthome/*"), new SimpleEntry<>("eventTypes", "ItemStateEvent")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))));
    final Configuration outerRuleActionConfig = new Configuration(Collections.unmodifiableMap(Stream.of(new SimpleEntry<>("ruleUIDs", "[exampleSceneRule]")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))));
    final Rule outerRule = new Rule("sceneActivationRule");
    outerRule.setTriggers(Arrays.asList(new Trigger[] { new Trigger("ItemStateChangeTrigger2", "core.GenericEventTrigger", outerRuleTriggerConfig) }));
    outerRule.setActions(Arrays.asList(new Action[] { new Action("RunRuleAction1", "core.RunRuleAction", outerRuleActionConfig, null) }));
    outerRule.setName("scene activator");
    return outerRule;
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) Arrays(java.util.Arrays) ProviderChangeListener(org.eclipse.smarthome.core.common.registry.ProviderChangeListener) ItemCommandEvent(org.eclipse.smarthome.core.items.events.ItemCommandEvent) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) ItemProvider(org.eclipse.smarthome.core.items.ItemProvider) EventFilter(org.eclipse.smarthome.core.events.EventFilter) EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) Configuration(org.eclipse.smarthome.config.core.Configuration) RuleRegistry(org.eclipse.smarthome.automation.RuleRegistry) Before(org.junit.Before) RuleStatus(org.eclipse.smarthome.automation.RuleStatus) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) Logger(org.slf4j.Logger) ItemEventFactory(org.eclipse.smarthome.core.items.events.ItemEventFactory) Collection(java.util.Collection) Set(java.util.Set) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) Test(org.junit.Test) Rule(org.eclipse.smarthome.automation.Rule) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException) Collectors(java.util.stream.Collectors) Item(org.eclipse.smarthome.core.items.Item) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) Stream(java.util.stream.Stream) Action(org.eclipse.smarthome.automation.Action) Queue(java.util.Queue) Assert(org.junit.Assert) Event(org.eclipse.smarthome.core.events.Event) Collections(java.util.Collections) Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) SimpleEntry(java.util.AbstractMap.SimpleEntry) Rule(org.eclipse.smarthome.automation.Rule)

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