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:
Dawit Gulino 20013954
2018-06-01 21:36:47 +02:00
committed by Giacomo Bertolazzi 20015159
parent fc135908f5
commit 9d995e093e
20 changed files with 352 additions and 1159 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";
@@ -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");
}
}

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

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

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