diff --git a/.gitignore b/.gitignore index 5540674..2ae46c9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ .mtj.tmp/ # Package Files # -*.jar +# *.jar // need zway lib *.war *.ear *.zip @@ -22,9 +22,17 @@ hs_err_pid* /bin/ +# Mi sono rotto di intellij e gradle +# anche se comunque per qualche ragione non funziona +# Perche' cointiunua a darmi i file di queste due cartelle?? +.idea/ +.idea/*.xml +.gradle/ + # eclipse things # .classpath .project +.settings .gradle /build/ diff --git a/.gradle/4.4/fileChanges/last-build.bin b/.gradle/4.4/fileChanges/last-build.bin deleted file mode 100644 index f76dd23..0000000 Binary files a/.gradle/4.4/fileChanges/last-build.bin and /dev/null differ diff --git a/.gradle/4.4/fileHashes/fileHashes.bin b/.gradle/4.4/fileHashes/fileHashes.bin deleted file mode 100644 index 642c384..0000000 Binary files a/.gradle/4.4/fileHashes/fileHashes.bin and /dev/null differ diff --git a/.gradle/4.4/fileHashes/fileHashes.lock b/.gradle/4.4/fileHashes/fileHashes.lock deleted file mode 100644 index 69ec864..0000000 Binary files a/.gradle/4.4/fileHashes/fileHashes.lock and /dev/null differ diff --git a/.gradle/4.4/taskHistory/taskHistory.bin b/.gradle/4.4/taskHistory/taskHistory.bin deleted file mode 100644 index 618b096..0000000 Binary files a/.gradle/4.4/taskHistory/taskHistory.bin and /dev/null differ diff --git a/.gradle/4.4/taskHistory/taskHistory.lock b/.gradle/4.4/taskHistory/taskHistory.lock deleted file mode 100644 index 6c1c7a6..0000000 Binary files a/.gradle/4.4/taskHistory/taskHistory.lock and /dev/null differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock deleted file mode 100644 index 34f85cf..0000000 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and /dev/null differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index 2d5c495..0000000 --- a/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Tue May 22 10:21:31 CEST 2018 -gradle.version=4.4 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin deleted file mode 100644 index b654629..0000000 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and /dev/null differ diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index eddea76..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 4b49563..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 1cde275..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,1115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1527511421271 - - - 1527518149240 - - - 1527522377670 - - - 1527610693612 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No facets are configured - - - - - - - - - - - - - - - 9 - - - - - - - - SeniorAssistant_test|SeniorAssistant - - - - - - - - - - - - - - - Gradle: com.fasterxml.jackson.core:jackson-core:2.1.3 - - - - - - - - \ No newline at end of file diff --git a/SeniorAssistant.iml b/SeniorAssistant.iml new file mode 100644 index 0000000..306ea4c --- /dev/null +++ b/SeniorAssistant.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 78f527d..b6edeb2 100644 --- a/build.gradle +++ b/build.gradle @@ -13,15 +13,19 @@ repositories { dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' - // compile "com.sparkjava:spark-core:2.5.5" - compile "org.slf4j:slf4j-simple:1.7.21" +// compile "com.sparkjava:spark-core:2.5.5" +// compile "org.slf4j:slf4j-simple:1.7.21" compile "com.google.code.gson:gson:2.8.0" - // compile "org.xerial:sqlite-jdbc:3.15.1" +// compile "org.xerial:sqlite-jdbc:3.15.1" compile 'org.apache.httpcomponents:httpclient:4.5.3' 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' - compile files('zway-lib-0.2.8-SNAPSHOT.jar') + +// 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' //already up there 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' @@ -30,6 +34,5 @@ dependencies { 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/lib/zway-lib-0.2.9-SNAPSHOT.jar b/lib/zway-lib-0.2.9-SNAPSHOT.jar new file mode 100644 index 0000000..741b75f Binary files /dev/null and b/lib/zway-lib-0.2.9-SNAPSHOT.jar differ diff --git a/src/main/java/device/Hue.java b/src/main/java/device/Hue.java index 17f4106..1ee4c98 100644 --- a/src/main/java/device/Hue.java +++ b/src/main/java/device/Hue.java @@ -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 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 getNameLights() { + return allLights.keySet(); + } + + public void removeLights(Set toRemove) { + for(String string : toRemove) + allLights.remove(string); + } + public void turnOn() { for (String light : allLights.keySet()) { String callURL = lightsURL + light + "/state"; @@ -42,12 +53,20 @@ public class Hue { } } - public void setAttribute(String attribute, String value){ + /*public void setAttribute(String attribute, String value){ for (String light : allLights.keySet()) { String callURL = lightsURL + light + "/state"; String body = "{ \""+attribute+"\" : "+value+" }"; Rest.put(callURL, body, "application/json"); } + }*/ + + public void colorLoop() { + for (String light : allLights.keySet()) { + String callURL = lightsURL + light + "/state"; + String body = "{ \"on\" : true, \"effect\" : \"colorloop\" }"; + Rest.put(callURL, body, "application/json"); + } } 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); + } + } +}