lampadine funzionano
This commit is contained in:
@@ -1,23 +1,34 @@
|
||||
package device;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import manage.Rest;
|
||||
|
||||
public class Hue {
|
||||
//private String baseURL;// = "192.168.0.2";
|
||||
//private String username;// = "admin";
|
||||
//private String baseURL = "192.168.0.2";
|
||||
//private String username = "C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx";
|
||||
private String lightsURL;// = baseURL+"/api/"+username+"/lights/";
|
||||
|
||||
private Map<String, ?> allLights;
|
||||
|
||||
public Hue () {
|
||||
this("192.168.0.2/api/admin/lights/");
|
||||
this("http://172.30.1.138/api/C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx/lights/");
|
||||
}
|
||||
public Hue (String url) {
|
||||
lightsURL = url;
|
||||
allLights = Rest.get(lightsURL);
|
||||
}
|
||||
|
||||
public Set<String> getNameLights() {
|
||||
return allLights.keySet();
|
||||
}
|
||||
|
||||
public void removeLights(Set<String> toRemove) {
|
||||
for(String string : toRemove)
|
||||
allLights.remove(string);
|
||||
}
|
||||
|
||||
public void turnOn() {
|
||||
for (String light : allLights.keySet()) {
|
||||
String callURL = lightsURL + light + "/state";
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
src/test/java/TestLights.java
Normal file
38
src/test/java/TestLights.java
Normal file
@@ -0,0 +1,38 @@
|
||||
import device.Hue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestLights {
|
||||
|
||||
@Test
|
||||
synchronized public void firstTestLights() throws InterruptedException {
|
||||
//Hue lights = new Hue("http://localhost/api/newdeveloper/");
|
||||
Hue lights = new Hue();
|
||||
|
||||
Set<String> toRemove = new HashSet<String>();
|
||||
for(String str: lights.getNameLights())
|
||||
if(!str.equals("4"))
|
||||
toRemove.add(str);
|
||||
lights.removeLights(toRemove);
|
||||
|
||||
for(int i=0; i<10; i++) {
|
||||
lights.turnOn();
|
||||
this.wait(0b1111101000); // 1000
|
||||
lights.turnOff();
|
||||
this.wait(0b1111101000); // 1000
|
||||
}
|
||||
|
||||
lights.turnOn();
|
||||
for(int i=0; i<256; i++) {
|
||||
lights.setBrightness(i);
|
||||
this.wait(10);
|
||||
}
|
||||
|
||||
for(int i=256; i>=0; i--) {
|
||||
lights.setBrightness(i);
|
||||
this.wait(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user