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