Seems that the test for lights passes, tried with the emulator

This commit is contained in:
Giulia
2018-05-28 17:46:17 +02:00
parent b132736a8e
commit 0949ce4299
4 changed files with 168 additions and 44 deletions

View File

@@ -1,20 +1,28 @@
package device;
import java.util.Map;
import manage.rest;
import manage.Rest;
public class hue {
String baseURL = "192.168.0.2";
String username = "admin";
String lightsURL = baseURL+"/api/"+username+"/lights/";
public class Hue {
//private String baseURL;// = "192.168.0.2";
//private String username;// = "admin";
private String lightsURL;// = baseURL+"/api/"+username+"/lights/";
Map<String, ?> allLights = rest.get(lightsURL);
private Map<String, ?> allLights;
public Hue () {
this("192.168.0.2/api/admin/lights/");
}
public Hue (String url) {
lightsURL = url;
allLights = Rest.get(lightsURL);
}
public void turnOn() {
for (String light : allLights.keySet()) {
String callURL = lightsURL + light + "/state";
String body = "{ \"on\" : true }";
rest.put(callURL, body, "application/json");
Rest.put(callURL, body, "application/json");
}
}
@@ -22,7 +30,7 @@ public class hue {
for (String light : allLights.keySet()) {
String callURL = lightsURL + light + "/state";
String body = "{ \"on\" : false }";
rest.put(callURL, body, "application/json");
Rest.put(callURL, body, "application/json");
}
}
@@ -30,7 +38,7 @@ public class hue {
for (String light : allLights.keySet()) {
String callURL = lightsURL + light + "/state";
String body = "{ \"bri\" : "+num+" }";
rest.put(callURL, body, "application/json");
Rest.put(callURL, body, "application/json");
}
}
@@ -38,7 +46,7 @@ public class hue {
for (String light : allLights.keySet()) {
String callURL = lightsURL + light + "/state";
String body = "{ \""+attribute+"\" : "+value+" }";
rest.put(callURL, body, "application/json");
Rest.put(callURL, body, "application/json");
}
}

View File

@@ -19,7 +19,7 @@ import org.apache.http.util.EntityUtils;
* @author <a href="mailto:luigi.derussis@uniupo.it">Luigi De Russis</a>
* @version 1.0 (18/05/2017)
*/
public class rest {
public class Rest {
// init gson
private static final Gson gson = new Gson();

View File

@@ -0,0 +1,32 @@
package tests;
import device.Hue;
import org.junit.Test;
public class TestLights {
@Test
synchronized public void firstTestLights() throws InterruptedException {
Hue lights = new Hue("http://localhost/api/newdeveloper/");
for(int i=0; i<10; i++) {
lights.turnOn();
this.wait(0b11001000); // 200
lights.turnOff();
this.wait(0b11001000); // 200
}
lights.turnOn();
for(int i=0; i<256; i++) {
lights.setBrightness(i);
this.wait(50);
}
for(int i=256; i>=0; i--) {
lights.setBrightness(i);
this.wait(50);
}
}
}