diff --git a/.gradle/4.4/fileHashes/fileHashes.bin b/.gradle/4.4/fileHashes/fileHashes.bin
index 69df71d..a0e8d64 100644
Binary files a/.gradle/4.4/fileHashes/fileHashes.bin and b/.gradle/4.4/fileHashes/fileHashes.bin differ
diff --git a/.gradle/4.4/fileHashes/fileHashes.lock b/.gradle/4.4/fileHashes/fileHashes.lock
index 27a02ab..67087ea 100644
Binary files a/.gradle/4.4/fileHashes/fileHashes.lock and b/.gradle/4.4/fileHashes/fileHashes.lock differ
diff --git a/.idea/modules/SeniorAssistant_main.iml b/.idea/modules/SeniorAssistant_main.iml
index 01deee6..1b6e4e6 100644
--- a/.idea/modules/SeniorAssistant_main.iml
+++ b/.idea/modules/SeniorAssistant_main.iml
@@ -9,10 +9,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/SeniorAssistant_test.iml b/.idea/modules/SeniorAssistant_test.iml
index 508d79f..75dbc70 100644
--- a/.idea/modules/SeniorAssistant_test.iml
+++ b/.idea/modules/SeniorAssistant_test.iml
@@ -10,13 +10,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 9e9c42c..9aa30cf 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,7 +2,15 @@
+
+
+
+
+
+
+
+
@@ -21,11 +29,20 @@
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -33,17 +50,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
nameLights
@@ -64,7 +111,7 @@
@@ -239,9 +286,9 @@
@@ -430,6 +477,10 @@
+
+
+
+
@@ -443,9 +494,10 @@
-
-
-
+
+
+
+
@@ -453,7 +505,6 @@
-
@@ -466,35 +517,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -508,11 +530,16 @@
+
+
+
+
+
@@ -662,67 +689,41 @@
-
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -736,9 +737,6 @@
-
-
-
@@ -746,23 +744,110 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build.gradle b/build.gradle
index b6f218b..53a94e6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,5 +21,16 @@ dependencies {
compile 'com.google.api-client:google-api-client:1.23.0'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta'
-
+ // z-way-lib and all its dependencies (from https://github.com/pathec/ZWay-library-for-Java)
+ compile files('lib/zway-lib-0.2.9-SNAPSHOT.jar')
+ compile 'com.google.code.gson:gson:2.4'
+ compile 'org.apache.commons:commons-lang3:3.4'
+ compile 'org.eclipse.jetty:jetty-client:9.3.11.v20160721'
+ compile 'org.eclipse.jetty:jetty-http:9.3.11.v20160721'
+ compile 'org.eclipse.jetty:jetty-io:9.3.11.v20160721'
+ compile 'org.eclipse.jetty:jetty-util:9.3.11.v20160721'
+ compile 'org.eclipse.jetty.websocket:websocket-api:9.3.12.v20160915'
+ compile 'org.eclipse.jetty.websocket:websocket-client:9.3.12.v20160915'
+ compile 'org.eclipse.jetty.websocket:websocket-common:9.3.12.v20160915'
+ compile 'org.slf4j:slf4j-simple:1.7.21'
}
diff --git a/src/main/java/device/Sensor.java b/src/main/java/device/Sensor.java
new file mode 100644
index 0000000..ece2924
--- /dev/null
+++ b/src/main/java/device/Sensor.java
@@ -0,0 +1,42 @@
+package device;
+
+import de.fh_zwickau.informatik.sensor.IZWayApi;
+import de.fh_zwickau.informatik.sensor.ZWayApiHttp;
+import de.fh_zwickau.informatik.sensor.model.devices.Device;
+import de.fh_zwickau.informatik.sensor.model.devices.DeviceList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Sensor {
+ // init logger
+ Logger logger = LoggerFactory.getLogger(Sensor.class);
+
+ // sample RaZberry IP address
+ String ipAddress = "http://172.30.1.137:8083";
+
+ // sample username and password
+ String username = "admin";
+ String password = "raz4reti2";
+
+ IZWayApi zwayApi;
+
+ 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)
+ zwayApi = new ZWayApiHttp(ipAddress, 8083, "http", username, password, 0, false, new ZWaySimpleCallback());
+ }
+
+ // get all the Z-Wave devices
+ DeviceList allDevices = zwayApi.getDevices();
+
+ public boolean IsLowLuminescence(int Luminescence) {
+ for (Device dev : allDevices.getAllDevices()) {
+ if (dev.getDeviceType().equalsIgnoreCase("SensorMultilevel"))
+ if (dev.getProbeType().equalsIgnoreCase("luminescence"))
+ if (Integer.parseInt(dev.getMetrics().getLevel()) < Luminescence)
+ return true;
+ else
+ return false;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/device/ZWaySimpleCallback.java b/src/main/java/device/ZWaySimpleCallback.java
new file mode 100644
index 0000000..44a8d09
--- /dev/null
+++ b/src/main/java/device/ZWaySimpleCallback.java
@@ -0,0 +1,233 @@
+package device;
+
+import de.fh_zwickau.informatik.sensor.IZWayApiCallbacks;
+import de.fh_zwickau.informatik.sensor.model.devicehistory.DeviceHistory;
+import de.fh_zwickau.informatik.sensor.model.devicehistory.DeviceHistoryList;
+import de.fh_zwickau.informatik.sensor.model.devices.Device;
+import de.fh_zwickau.informatik.sensor.model.devices.DeviceList;
+import de.fh_zwickau.informatik.sensor.model.instances.Instance;
+import de.fh_zwickau.informatik.sensor.model.instances.InstanceList;
+import de.fh_zwickau.informatik.sensor.model.locations.Location;
+import de.fh_zwickau.informatik.sensor.model.locations.LocationList;
+import de.fh_zwickau.informatik.sensor.model.modules.ModuleList;
+import de.fh_zwickau.informatik.sensor.model.namespaces.NamespaceList;
+import de.fh_zwickau.informatik.sensor.model.notifications.Notification;
+import de.fh_zwickau.informatik.sensor.model.notifications.NotificationList;
+import de.fh_zwickau.informatik.sensor.model.profiles.Profile;
+import de.fh_zwickau.informatik.sensor.model.profiles.ProfileList;
+import de.fh_zwickau.informatik.sensor.model.zwaveapi.controller.ZWaveController;
+import de.fh_zwickau.informatik.sensor.model.zwaveapi.devices.ZWaveDevice;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Mandatory callback class for the Z-Way Library in use.
+ * Really trivial implementation: log all the responses at debug level.
+ *
+ * @author Luigi De Russis
+ * @version 1.0 (24/05/2017)
+ * @see Z-Way Library on GitHub for documentation about the used library
+ */
+public class ZWaySimpleCallback implements IZWayApiCallbacks {
+
+ @Override
+ public void getStatusResponse(String s) {
+ this.logMessage("Status response: " + s);
+ }
+
+ @Override
+ public void getRestartResponse(Boolean aBoolean) {
+ this.logMessage("Restart response: " + aBoolean);
+ }
+
+ @Override
+ public void getLoginResponse(String s) {
+ this.logMessage("Login response: " + s);
+ }
+
+ @Override
+ public void getNamespacesResponse(NamespaceList namespaceList) {
+ this.logMessage("Namespaces are: " + namespaceList);
+ }
+
+ @Override
+ public void getModulesResponse(ModuleList moduleList) {
+ this.logMessage("Modules are: " + moduleList);
+ }
+
+ @Override
+ public void getInstancesResponse(InstanceList instanceList) {
+ this.logMessage("Instances are: " + instanceList);
+ }
+
+ @Override
+ public void postInstanceResponse(Instance instance) {
+ this.logMessage("Received a POST for the instance: " + instance);
+ }
+
+ @Override
+ public void getInstanceResponse(Instance instance) {
+ this.logMessage("The instance is: " + instance);
+ }
+
+ @Override
+ public void putInstanceResponse(Instance instance) {
+ this.logMessage("Received a PUT for the instance: " + instance);
+ }
+
+ @Override
+ public void deleteInstanceResponse(boolean b) {
+ this.logMessage("The instance has been deleted? " + String.valueOf(b));
+ }
+
+ @Override
+ public void getDevicesResponse(DeviceList deviceList) {
+ this.logMessage("Devices are: " + deviceList);
+ }
+
+ @Override
+ public void putDeviceResponse(Device device) {
+ this.logMessage("Received a PUT for device: " + device);
+ }
+
+ @Override
+ public void getDeviceResponse(Device device) {
+ this.logMessage("The device is: " + device);
+ }
+
+ @Override
+ public void getDeviceCommandResponse(String s) {
+ this.logMessage("The device command is: " + s);
+ }
+
+ @Override
+ public void getLocationsResponse(LocationList locationList) {
+ this.logMessage("Locations are: " + locationList);
+ }
+
+ @Override
+ public void postLocationResponse(Location location) {
+ this.logMessage("Received a POST for location: " + location);
+ }
+
+ @Override
+ public void getLocationResponse(Location location) {
+ this.logMessage("The location is: " + location);
+ }
+
+ @Override
+ public void putLocationResponse(Location location) {
+ this.logMessage("Received a PUT for location: " + location);
+ }
+
+ @Override
+ public void deleteLocationResponse(boolean b) {
+ this.logMessage("Location has been deleted? " + b);
+ }
+
+ @Override
+ public void getProfilesResponse(ProfileList profileList) {
+ this.logMessage("Profiles are: " + profileList);
+ }
+
+ @Override
+ public void postProfileResponse(Profile profile) {
+ this.logMessage("Received a POST for profile: " + profile);
+ }
+
+ @Override
+ public void getProfileResponse(Profile profile) {
+ this.logMessage("The profile is: " + profile);
+ }
+
+ @Override
+ public void putProfileResponse(Profile profile) {
+ this.logMessage("Received a PUT for profile: " + profile);
+ }
+
+ @Override
+ public void deleteProfileResponse(boolean b) {
+ this.logMessage("Profile has been deleted? " + b);
+ }
+
+ @Override
+ public void getNotificationsResponse(NotificationList notificationList) {
+ this.logMessage("Notifications are: " + notificationList);
+ }
+
+ @Override
+ public void getNotificationResponse(Notification notification) {
+ this.logMessage("The notification is: " + notification);
+ }
+
+ @Override
+ public void putNotificationResponse(Notification notification) {
+ this.logMessage("Received a PUT for notification: " + notification);
+ }
+
+ @Override
+ public void getDeviceHistoriesResponse(DeviceHistoryList deviceHistoryList) {
+ this.logMessage("Device histories are: " + deviceHistoryList);
+ }
+
+ @Override
+ public void getDeviceHistoryResponse(DeviceHistory deviceHistory) {
+ this.logMessage("The device history is: " + deviceHistory);
+ }
+
+ @Override
+ public void getZWaveDeviceResponse(ZWaveDevice zWaveDevice) {
+ this.logMessage("The Z-Wave device is: " + zWaveDevice);
+ }
+
+ @Override
+ public void getZWaveControllerResponse(ZWaveController zWaveController) {
+ this.logMessage("The Z-Wave controller is: " + zWaveController);
+ }
+
+ @Override
+ public void apiError(String s, boolean b) {
+ this.logError("API Error: " + s);
+ }
+
+ @Override
+ public void httpStatusError(int i, String s, boolean b) {
+ this.logError("HTTP Status Error: " + i + s);
+ }
+
+ @Override
+ public void authenticationError() {
+ this.logError("Authentication Error");
+ }
+
+ @Override
+ public void responseFormatError(String s, boolean b) {
+ this.logError("Wrong format: " + s);
+ }
+
+ @Override
+ public void message(int i, String s) {
+ this.logMessage("You've got a message: " + i + " " + s);
+ }
+
+ /**
+ * Utility method to print the log messages of this class.
+ *
+ * @param message the {@link String} to print
+ */
+ private void logMessage(String message) {
+ Logger logger = LoggerFactory.getLogger(Sensor.class);
+ logger.debug(message);
+ }
+
+ /**
+ * Utility method to print the error messages of this class.
+ *
+ * @param error the {@link String} to print
+ */
+ private void logError(String error) {
+ Logger logger = LoggerFactory.getLogger(Sensor.class);
+ logger.error(error);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/TestSensor.java b/src/test/java/TestSensor.java
new file mode 100644
index 0000000..16fd220
--- /dev/null
+++ b/src/test/java/TestSensor.java
@@ -0,0 +1,23 @@
+import device.Hue;
+import device.Sensor;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestSensor {
+ Sensor sensor = new Sensor();
+ Hue hue = new Hue();
+
+ @Test
+ public void firstTestSensor() {
+ assertTrue(sensor.IsLowLuminescence(50));
+ }
+
+ @Test
+ public void secondTestSensor() {
+ if(sensor.IsLowLuminescence(50)) {
+ hue.turnOn();
+ hue.setBrightness(200);
+ }
+ }
+}