lampadine funzionano

This commit is contained in:
f19stefano96
2018-05-29 10:39:16 +02:00
parent 0949ce4299
commit b79a7615d2
8 changed files with 206 additions and 280 deletions

View File

@@ -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";

View File

@@ -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);
}
}
}

View 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);
}
}
}