Branch #Dawit (this was a test)
* lampadine funzionano * Aggiunto classe Sensor e testSensor. NON SO se giusto * Aggiunto jar per Z-Wave * Removed .gradle .idea
This commit was merged in pull request #1.
This commit is contained in:
committed by
Giacomo Bertolazzi 20015159
parent
fc135908f5
commit
9d995e093e
10
.gitignore
vendored
10
.gitignore
vendored
@@ -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/
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +0,0 @@
|
||||
#Tue May 22 10:21:31 CEST 2018
|
||||
gradle.version=4.4
|
||||
Binary file not shown.
18
.idea/gradle.xml
generated
18
.idea/gradle.xml
generated
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="createEmptyContentRootDirectories" value="true" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="useAutoImport" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/misc.xml
generated
7
.idea/misc.xml
generated
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" project-jdk-name="9" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
1115
.idea/workspace.xml
generated
1115
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
13
SeniorAssistant.iml
Normal file
13
SeniorAssistant.iml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="SeniorAssistant" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="SeniorAssistant" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/out" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
15
build.gradle
15
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'
|
||||
}
|
||||
|
||||
BIN
lib/zway-lib-0.2.9-SNAPSHOT.jar
Normal file
BIN
lib/zway-lib-0.2.9-SNAPSHOT.jar
Normal file
Binary file not shown.
@@ -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";
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
42
src/main/java/device/Sensor.java
Normal file
42
src/main/java/device/Sensor.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
233
src/main/java/device/ZWaySimpleCallback.java
Normal file
233
src/main/java/device/ZWaySimpleCallback.java
Normal file
@@ -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 <a href="mailto:luigi.derussis@uniupo.it">Luigi De Russis</a>
|
||||
* @version 1.0 (24/05/2017)
|
||||
* @see <a href="https://github.com/pathec/ZWay-library-for-Java">Z-Way Library on GitHub</a> 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);
|
||||
}
|
||||
}
|
||||
23
src/test/java/TestSensor.java
Normal file
23
src/test/java/TestSensor.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user