-
Notifications
You must be signed in to change notification settings - Fork 21
/
HueEventsTestRun.java
47 lines (39 loc) · 1.54 KB
/
HueEventsTestRun.java
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
package io.github.zeroone3010.yahueapi.v2;
import io.github.zeroone3010.yahueapi.v2.domain.event.ButtonEvent;
import io.github.zeroone3010.yahueapi.v2.domain.event.MotionEvent;
import java.util.concurrent.TimeUnit;
/**
* This class demonstrates a simple example of an application that listens to and logs
* button events from the Bridge for ten minutes.
*/
public class HueEventsTestRun {
/**
* Displays a stream of events from the given Bridge for ten minutes.
*
* @param args IP address of the Bridge, API key
*/
public static void main(final String... args) throws InterruptedException {
final String ip = args[0];
final String apiKey = args[1];
if (args.length != 2) {
System.out.println("This class requires two arguments: first the IP address of the Bridge, then the API key.");
System.exit(1);
}
final Hue hue = new Hue(ip, apiKey);
final HueEventSource hueEventSource = hue.subscribeToEvents(new HueEventListener() {
@Override
public void receiveButtonEvent(final ButtonEvent event) {
System.out.println("Button event received: " + event);
}
@Override
public void receiveMotionEvent(final MotionEvent event) {
System.out.println("Motion event received: " + event);
}
});
System.out.println(hueEventSource.getState());
TimeUnit.SECONDS.sleep(1);
System.out.println(hueEventSource.getState());
// Don't do this in real projects, this is only good for preventing this test-app from closing immediately:
TimeUnit.MINUTES.sleep(10);
}
}