-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventBusExamples.java
More file actions
41 lines (26 loc) · 1.14 KB
/
EventBusExamples.java
File metadata and controls
41 lines (26 loc) · 1.14 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
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
import org.openhab.automation.javascripting.scriptsupport.Script;
import org.openhab.core.items.Item;
import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.types.DecimalType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EventBusExamples extends Script {
private Logger logger = LoggerFactory.getLogger("org.openhab.automation.javascripting.eventbus");
@Override
protected Object onLoad() {
logger.info("Java onLoad()");
events.sendCommand("Livingroom_Light", "OFF");
Item item = itemRegistry.get("Morning_Temperature");
((NumberItem) item).setState(new DecimalType(0.0f));
events.postUpdate(item, 37.2f);
Number state = (Number) item.getState();
logger.info("new State: {}", state.floatValue());
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
state = (Number) item.getState();
logger.info("new State again: {}", state.floatValue());
logger.info("eventbus done");
return null;
}
}