-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGroovyPort.java
More file actions
executable file
·57 lines (39 loc) · 1.57 KB
/
GroovyPort.java
File metadata and controls
executable file
·57 lines (39 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openhab.automation.javascripting.scriptsupport.Script;
import org.openhab.core.automation.Action;
import org.openhab.core.automation.Trigger;
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule;
import org.openhab.core.automation.util.TriggerBuilder;
import org.openhab.core.config.core.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* @author weberjn
*/
public class GroovyPort extends Script {
private Logger logger = LoggerFactory.getLogger("org.openhab.automation.javascripting.script");
public int counter = 1;
protected Object onLoad() {
SimpleRule sr = new SimpleRule() {
@Override
public Object execute(Action module, Map<String, ?> inputs) {
logger.info("Java execute {}, inputs: {} ", counter++, inputs);
return "";
}
};
sr.setName("Java-One");
List<Trigger> triggers = new ArrayList<Trigger>(1);
Map<String, Object> triggerConf = new HashMap<String, Object>();
triggerConf.put("cronExpression", "0 * * * * ?");
Trigger trigger = TriggerBuilder.create().withId("aTimerTrigger").withTypeUID("timer.GenericCronTrigger")
.withConfiguration(new Configuration(triggerConf)).build();
triggers.add(trigger);
sr.setTriggers(triggers);
automationManager.addRule(sr);
logger.info("onLoad() done");
return null;
}
}