Added Sensor

This commit is contained in:
Dawit Gulino 20013954
2018-06-05 14:51:40 +02:00
parent 4695b9ddfc
commit 7e1feb6939
4 changed files with 66 additions and 32 deletions

View File

@@ -12,31 +12,58 @@ public class Sensor {
Logger logger = LoggerFactory.getLogger(Sensor.class); Logger logger = LoggerFactory.getLogger(Sensor.class);
// sample RaZberry IP address // sample RaZberry IP address
String ipAddress = "http://172.30.1.137:8083"; public String ipAddress = "172.30.1.137";
// sample username and password // sample username and password
String username = "admin"; public String username = "admin";
String password = "raz4reti2"; public String password = "raz4reti2";
IZWayApi zwayApi; public IZWayApi zwayApi;
DeviceList allZWaveDevices;
DeviceList devices;
public Sensor() { public Sensor() {
// create an instance of the Z-Way library; all the params are mandatory (we are not going to use the remote service/id) this(null);
zwayApi = new ZWayApiHttp(ipAddress, 8083, "http", username, password, 0, false, new ZWaySimpleCallback());
} }
// get all the Z-Wave devices public Sensor (Integer nodeId) {
DeviceList allDevices = zwayApi.getDevices(); // create an instance of the Z-Way library; all the params are mandatory (we are not going to use the remote service/id)
zwayApi = new ZWayApiHttp(ipAddress, 8083, "http", username, password, 0, false, new ZWaySimpleCallback());
public boolean IsLowLuminescence(int Luminescence) { // get all the Z-Wave devices
for (Device dev : allDevices.getAllDevices()) { allZWaveDevices = zwayApi.getDevices();
if (dev.getDeviceType().equalsIgnoreCase("SensorMultilevel"))
if (dev.getProbeType().equalsIgnoreCase("luminescence")) if(nodeId != null)
useNode(nodeId);
else
devices = allZWaveDevices;
}
public void useNode(int nodeId) {
devices = new DeviceList();
for (Device devi : allZWaveDevices.getAllDevices())
if(devi.getNodeId() == nodeId)
devices.addDevice(devi);
}
public int luminiscenceLevel() {
for (Device device : devices.getAllDevices())
if (device.getMetrics().getProbeTitle().equalsIgnoreCase("luminiscence"))
return Integer.parseInt(device.getMetrics().getLevel());
return -99;
}
synchronized public void update(int nodeId) throws InterruptedException {
for (Device device : devices.getAllDevices())
device.update();
wait(10000);
}
/*public boolean IsLowLuminescence(int Luminescence) {
if (dev.getProbeType().equalsIgnoreCase("Luminescence"))
if (Integer.parseInt(dev.getMetrics().getLevel()) < Luminescence) if (Integer.parseInt(dev.getMetrics().getLevel()) < Luminescence)
return true; return true;
else else
return false; return false;
} return false;
return false; }*/
}
} }

View File

@@ -1,9 +1,6 @@
package manage; package manage;
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; import com.google.api.client.auth.oauth2.*;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.ClientParametersAuthentication;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.http.GenericUrl; import com.google.api.client.http.GenericUrl;

View File

@@ -26,16 +26,17 @@ public class TestLights {
lights.turnOn(); lights.turnOn();
for(int i=256; i>=0; i--) { for(int i=256; i>=0; i--) {
lights.setBrightness(i); lights.setBrightness(i);
this.wait(50); this.wait(25);
} }
for(int i=0; i<256; i++) { for(int i=0; i<256; i++) {
lights.setBrightness(i); lights.setBrightness(i);
this.wait(50); this.wait(25);
} }
lights.setBrightness(150);
lights.colorLoop(); lights.colorLoop();
this.wait(10000); // 10 sec this.wait(20000); // 10 sec
lights.turnOff(); lights.turnOff();
} }

View File

@@ -2,22 +2,31 @@ import device.Hue;
import device.Sensor; import device.Sensor;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue; import java.util.HashSet;
import java.util.Set;
public class TestSensor { public class TestSensor {
Sensor sensor = new Sensor(); Sensor sensor = new Sensor(5);
Hue hue = new Hue(); Hue lights = new Hue();
@Test @Test
public void firstTestSensor() { synchronized public void firstTestSensor() throws InterruptedException {
assertTrue(sensor.IsLowLuminescence(50)); sensor.update(5);
System.out.println(sensor.luminiscenceLevel());
} }
@Test @Test
public void secondTestSensor() { public void secondTestSensor() throws InterruptedException {
if(sensor.IsLowLuminescence(50)) { sensor.update(5);
hue.turnOn(); Set<String> toRemove = new HashSet<>();
hue.setBrightness(200); for(String str: lights.getNameLights())
if(!str.equals("4"))
toRemove.add(str);
lights.removeLights(toRemove);
if(sensor.luminiscenceLevel() < 100) {
lights.turnOn();
lights.setBrightness(200);
} }
} }
} }