From 926a7f50dc5ca703b8aca05900d43acfcc071078 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 18 Mar 2016 16:38:18 -0500 Subject: [PATCH] Finished adding dim versus on, utf-8 and track state and return on api calls. --- pom.xml | 2 +- .../HABridge/api/hue/DeviceResponse.java | 12 +- .../HABridge/api/hue/DeviceState.java | 2 +- .../HABridge/dao/DeviceDescriptor.java | 62 +++++++++- .../HABridge/dao/DeviceRepository.java | 112 +++--------------- .../devicemanagmeent/DeviceResource.java | 25 ++-- .../bwssystems/HABridge/hue/HueMulator.java | 51 ++++---- .../com/bwssystems/NestBridge/NestItem.java | 11 +- .../bwssystems/harmony/HarmonyActivity.java | 10 ++ .../com/bwssystems/harmony/HarmonyDevice.java | 10 ++ src/main/resources/public/scripts/app.js | 89 ++++++-------- .../resources/public/views/configuration.html | 2 + .../resources/public/views/editdevice.html | 11 ++ src/main/resources/public/views/editor.html | 11 ++ .../resources/public/views/veradevice.html | 11 ++ 15 files changed, 224 insertions(+), 197 deletions(-) diff --git a/pom.xml b/pom.xml index 08e134e1..65070e51 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 1.4.1c + 1.4.1d jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java index 767231b0..984828ef 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java @@ -1,5 +1,7 @@ package com.bwssystems.HABridge.api.hue; +import com.bwssystems.HABridge.dao.DeviceDescriptor; + /** * Created by arm on 4/14/15. */ @@ -68,18 +70,18 @@ public void setSwversion(String swversion) { this.swversion = swversion; } - public static DeviceResponse createResponse(String name, String id){ + public static DeviceResponse createResponse(DeviceDescriptor device){ DeviceState deviceState = new DeviceState(); DeviceResponse response = new DeviceResponse(); response.setState(deviceState); - deviceState.setOn(false); + deviceState.setOn(device.getDeviceState()); deviceState.setReachable(true); deviceState.setEffect("none"); deviceState.setAlert("none"); - deviceState.setBri(254); + deviceState.setBri(device.getDeviceSetValue()); - response.setName(name); - response.setUniqueid(id); + response.setName(device.getName()); + response.setUniqueid(device.getId()); response.setManufacturername("Philips"); response.setType("Dimmable light"); response.setModelid("LWB004"); diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java index fbff709c..3ce5c19f 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java @@ -6,7 +6,7 @@ */ public class DeviceState { private boolean on; - private int bri = 255; + private int bri = 0; private String effect; private String alert; private boolean reachable; diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java index cb26eeac..1cfe6b14 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java @@ -1,21 +1,55 @@ package com.bwssystems.HABridge.dao; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + /* * Object to handle the device configuration */ public class DeviceDescriptor{ - private String id; + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose private String name; + @SerializedName("mapId") + @Expose private String mapId; + @SerializedName("mapType") + @Expose private String mapType; + @SerializedName("deviceType") + @Expose private String deviceType; + @SerializedName("targetDevice") + @Expose private String targetDevice; + @SerializedName("offUrl") + @Expose private String offUrl; + @SerializedName("dimUrl") + @Expose + private String dimUrl; + @SerializedName("onUrl") + @Expose private String onUrl; + @SerializedName("httpVerb") + @Expose private String httpVerb; + @SerializedName("contentType") + @Expose private String contentType; + @SerializedName("contentBody") + @Expose private String contentBody; + @SerializedName("contentBodyOff") + @Expose private String contentBodyOff; + private boolean deviceState; + private int deviceSetValue; + public String getName() { return name; } @@ -64,7 +98,15 @@ public void setOffUrl(String offUrl) { this.offUrl = offUrl; } - public String getOnUrl() { + public String getDimUrl() { + return dimUrl; + } + + public void setDimUrl(String dimUrl) { + this.dimUrl = dimUrl; + } + + public String getOnUrl() { return onUrl; } @@ -111,6 +153,22 @@ public String getContentBodyOff() { public void setContentBodyOff(String contentBodyOff) { this.contentBodyOff = contentBodyOff; } + + public boolean getDeviceState() { + return deviceState; + } + + public void setDeviceState(boolean deviceState) { + this.deviceState = deviceState; + } + + public int getDeviceSetValue() { + return deviceSetValue; + } + + public void setDeviceSetValue(int deviceSetValue) { + this.deviceSetValue = deviceSetValue; + } } diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java index a4af2109..06e5a8d0 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java @@ -2,7 +2,6 @@ import java.io.IOException; -import java.io.StringReader; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; @@ -18,22 +17,26 @@ import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.util.BackupHandler; import com.bwssystems.util.JsonTransformer; -import com.google.gson.stream.JsonReader; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import java.util.List; -import java.util.ListIterator; /* * This is an in memory list to manage the configured devices and saves the list as a JSON string to a file for later * loading. */ public class DeviceRepository extends BackupHandler { - Map devices; - Path repositoryPath; - final Random random = new Random(); - final Logger log = LoggerFactory.getLogger(DeviceRepository.class); + private Map devices; + private Path repositoryPath; + private Gson gson; + final private Random random = new Random(); + private Logger log = LoggerFactory.getLogger(DeviceRepository.class); public DeviceRepository(String deviceDb) { super(); + gson = + new GsonBuilder() + .create(); repositoryPath = null; repositoryPath = Paths.get(deviceDb); setupParams(repositoryPath, ".bk", "device.db-"); @@ -50,15 +53,11 @@ private void _loadRepository(Path aPath){ if(jsonContent != null) { - List list = readJsonStream(jsonContent); - ListIterator theIterator = list.listIterator(); - DeviceDescriptor theDevice = null; - while (theIterator.hasNext()) { - theDevice = theIterator.next(); - put(theDevice.getId(), theDevice); + DeviceDescriptor list[] = gson.fromJson(jsonContent, DeviceDescriptor[].class); + for(int i = 0; i < list.length; i++) { + put(list[i].getId(), list[i]); } - } - + } } public List findAll() { @@ -89,8 +88,7 @@ public void save(DeviceDescriptor[] descriptors) { put(descriptors[i].getId(), descriptors[i]); theNames = theNames + " " + descriptors[i].getName() + ", "; } - JsonTransformer aRenderer = new JsonTransformer(); - String jsonValue = aRenderer.render(findAll()); + String jsonValue = gson.toJson(findAll()); repositoryWriter(jsonValue, repositoryPath); log.debug("Save device(s): " + theNames); } @@ -153,82 +151,4 @@ private String repositoryReader(Path filePath) { return content; } - - private List readJsonStream(String context) { - JsonReader reader = new JsonReader(new StringReader(context)); - List theDescriptors = null; - try { - theDescriptors = readDescriptorArray(reader); - } catch (IOException e) { - log.error("Error reading json array: " + context + " message: " + e.getMessage(), e); - } finally { - try { - reader.close(); - } catch (IOException e) { - log.error("Error closing json reader: " + context + " message: " + e.getMessage(), e); - } - } - return theDescriptors; - } - - public List readDescriptorArray(JsonReader reader) throws IOException { - List descriptors = new ArrayList(); - - reader.beginArray(); - while (reader.hasNext()) { - descriptors.add(readDescriptor(reader)); - } - reader.endArray(); - return descriptors; - } - - public DeviceDescriptor readDescriptor(JsonReader reader) throws IOException { - DeviceDescriptor deviceEntry = new DeviceDescriptor(); - - reader.beginObject(); - while (reader.hasNext()) { - String name = reader.nextName(); - if (name.equals("id")) { - deviceEntry.setId(reader.nextString()); - log.debug("Read a Device - device json id: " + deviceEntry.getId()); - } else if (name.equals("name")) { - deviceEntry.setName(reader.nextString()); - log.debug("Read a Device - device json name: " + deviceEntry.getName()); - } else if (name.equals("mapType")) { - deviceEntry.setMapType(reader.nextString()); - log.debug("Read a Device - device json name: " + deviceEntry.getMapType()); - } else if (name.equals("mapId")) { - deviceEntry.setMapId(reader.nextString()); - log.debug("Read a Device - device json name: " + deviceEntry.getMapId()); - } else if (name.equals("deviceType")) { - deviceEntry.setDeviceType(reader.nextString()); - log.debug("Read a Device - device json type:" + deviceEntry.getDeviceType()); - } else if (name.equals("targetDevice")) { - deviceEntry.setTargetDevice(reader.nextString()); - log.debug("Read a Device - device json type:" + deviceEntry.getTargetDevice()); - } else if (name.equals("offUrl")) { - deviceEntry.setOffUrl(reader.nextString()); - log.debug("Read a Device - device json off URL:" + deviceEntry.getOffUrl()); - } else if (name.equals("onUrl")) { - deviceEntry.setOnUrl(reader.nextString()); - log.debug("Read a Device - device json on URL:" + deviceEntry.getOnUrl()); - } else if (name.equals("httpVerb")) { - deviceEntry.setHttpVerb(reader.nextString()); - log.debug("Read a Device - device json httpVerb:" + deviceEntry.getHttpVerb()); - } else if (name.equals("contentType")) { - deviceEntry.setContentType(reader.nextString()); - log.debug("Read a Device - device json contentType:" + deviceEntry.getContentType()); - } else if (name.equals("contentBody")) { - deviceEntry.setContentBody(reader.nextString()); - log.debug("Read a Device - device json contentBody:" + deviceEntry.getContentBody()); - } else if (name.equals("contentBodyOff")) { - deviceEntry.setContentBodyOff(reader.nextString()); - log.debug("Read a Device - device json contentBodyOff:" + deviceEntry.getContentBodyOff()); - } else { - reader.skipValue(); - } - } - reader.endObject(); - return deviceEntry; - } -} +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index e5e58bb2..138ba6b8 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -115,35 +115,24 @@ private void setupEndpoints() { put (API_CONTEXT + "/:id", "application/json", (request, response) -> { log.debug("Edit a Device - request body: " + request.body()); DeviceDescriptor device = new Gson().fromJson(request.body(), DeviceDescriptor.class); - DeviceDescriptor deviceEntry = deviceRepository.findOne(request.params(":id")); - if(deviceEntry == null){ - log.debug("Could not save an edited Device Id: " + request.params(":id")); + if(deviceRepository.findOne(request.params(":id")) == null){ + log.debug("Could not save an edited device, Device Id not found: " + request.params(":id")); response.status(HttpStatus.SC_BAD_REQUEST); - return new ErrorMessage("Could not save an edited Device Id: " + request.params(":id") + " "); + return new ErrorMessage("Could not save an edited device, Device Id not found: " + request.params(":id") + " "); } else { - log.debug("Saving an edited Device: " + deviceEntry.getName()); + log.debug("Saving an edited Device: " + device.getName()); - deviceEntry.setName(device.getName()); if (device.getDeviceType() != null) - deviceEntry.setDeviceType(device.getDeviceType()); - deviceEntry.setMapId(device.getMapId()); - deviceEntry.setMapType(device.getMapType()); - deviceEntry.setTargetDevice(device.getTargetDevice()); - deviceEntry.setOnUrl(device.getOnUrl()); - deviceEntry.setOffUrl(device.getOffUrl()); - deviceEntry.setHttpVerb(device.getHttpVerb()); - deviceEntry.setContentType(device.getContentType()); - deviceEntry.setContentBody(device.getContentBody()); - deviceEntry.setContentBodyOff(device.getContentBodyOff()); + device.setDeviceType(device.getDeviceType()); DeviceDescriptor[] theDevices = new DeviceDescriptor[1]; - theDevices[0] = deviceEntry; + theDevices[0] = device; deviceRepository.save(theDevices); response.status(HttpStatus.SC_OK); } - return deviceEntry; + return device; }, new JsonTransformer()); get (API_CONTEXT, "application/json", (request, response) -> { diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index af89be19..de23c2c2 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -101,7 +101,7 @@ public void setupServer() { List deviceList = repository.findAll(); Map deviceResponseMap = new HashMap<>(); for (DeviceDescriptor device : deviceList) { - DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId()); + DeviceResponse deviceResponse = DeviceResponse.createResponse(device); deviceResponseMap.put(device.getId(), deviceResponse); } response.type("application/json; charset=utf-8"); @@ -225,7 +225,7 @@ public void setupServer() { Map deviceList = new HashMap<>(); descriptorList.forEach(descriptor -> { - DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor.getName(), descriptor.getId()); + DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor); deviceList.put(descriptor.getId(), deviceResponse); } ); @@ -249,7 +249,7 @@ public void setupServer() { } else { log.debug("found device named: " + device.getName()); } - DeviceResponse lightResponse = DeviceResponse.createResponse(device.getName(), device.getId()); + DeviceResponse lightResponse = DeviceResponse.createResponse(device); response.type("application/json; charset=utf-8"); response.status(HttpStatus.SC_OK); @@ -296,28 +296,34 @@ public void setupServer() { return responseString; } - if (state.isOn()) { - responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":true}}"; - url = device.getOnUrl(); - } else if (request.body().contains("false")) { - responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":false}}"; - url = device.getOffUrl(); - } - + responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":"; if(request.body().contains("bri")) { - if(url == null) - { + url = device.getDimUrl(); + + if(url == null || url.length() == 0) url = device.getOnUrl(); - responseString = "["; - } - else - responseString = responseString + ","; - responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}]"; + responseString = responseString + "true}},{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}]"; } else - responseString = responseString + "]"; + { + if (state.isOn()) { + responseString = responseString + "true}}]"; + url = device.getOnUrl(); + state.setBri(255); + } else if (request.body().contains("false")) { + responseString = responseString + "false}}]"; + url = device.getOffUrl(); + state.setBri(0); + } + } + + if (url == null) { + log.warn("Could not find url: " + lightId + " for hue state change request: " + userId + " from " + request.ip() + " body: " + request.body()); + responseString = "[{\"error\":{\"type\": 3, \"address\": \"/lights/" + lightId + "\",\"description\": \"Could not find url\", \"resource\": \"/lights/" + lightId + "\"}}]"; + return responseString; + } if(device.getDeviceType().toLowerCase().contains("activity") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyActivity"))) { @@ -337,7 +343,6 @@ public void setupServer() { else { log.warn("Should not get here, no harmony configured"); responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Should not get here, no harmony configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]"; - } } else if(device.getDeviceType().toLowerCase().contains("button") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyButton"))) @@ -456,7 +461,11 @@ else if(url.startsWith("udp://")) responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling url to change device state\", \"parameter\": \"/lights/" + lightId + "state\"}}]"; } } - + + if(!responseString.contains("[{\"error\":")) { + device.setDeviceSetValue(state.getBri()); + device.setDeviceState(state.isOn()); + } return responseString; }); } diff --git a/src/main/java/com/bwssystems/NestBridge/NestItem.java b/src/main/java/com/bwssystems/NestBridge/NestItem.java index fd803303..0f7e0207 100644 --- a/src/main/java/com/bwssystems/NestBridge/NestItem.java +++ b/src/main/java/com/bwssystems/NestBridge/NestItem.java @@ -1,5 +1,7 @@ package com.bwssystems.NestBridge; +import java.io.UnsupportedEncodingException; + public class NestItem { private String name; private String id; @@ -9,7 +11,14 @@ public String getName() { return name; } public void setName(String name) { - this.name = name; + byte ptext[]; + String theLabel = new String(name); + try { + ptext = theLabel.getBytes("ISO-8859-1"); + this.name = new String(ptext, "UTF-8"); + } catch (UnsupportedEncodingException e) { + this.name = theLabel; + } } public String getId() { return id; diff --git a/src/main/java/com/bwssystems/harmony/HarmonyActivity.java b/src/main/java/com/bwssystems/harmony/HarmonyActivity.java index 5b65a71f..2c6647d2 100644 --- a/src/main/java/com/bwssystems/harmony/HarmonyActivity.java +++ b/src/main/java/com/bwssystems/harmony/HarmonyActivity.java @@ -1,5 +1,7 @@ package com.bwssystems.harmony; +import java.io.UnsupportedEncodingException; + import net.whistlingfish.harmony.config.Activity; public class HarmonyActivity { @@ -15,6 +17,14 @@ public Activity getActivity() { return activity; } public void setActivity(Activity activity) { + byte ptext[]; + String theLabel = activity.getLabel(); + try { + ptext = theLabel.getBytes("ISO-8859-1"); + activity.setLabel(new String(ptext, "UTF-8")); + } catch (UnsupportedEncodingException e) { + activity.setLabel(theLabel); + } this.activity = activity; } diff --git a/src/main/java/com/bwssystems/harmony/HarmonyDevice.java b/src/main/java/com/bwssystems/harmony/HarmonyDevice.java index 7deaac66..39ef4e35 100644 --- a/src/main/java/com/bwssystems/harmony/HarmonyDevice.java +++ b/src/main/java/com/bwssystems/harmony/HarmonyDevice.java @@ -1,5 +1,7 @@ package com.bwssystems.harmony; +import java.io.UnsupportedEncodingException; + import net.whistlingfish.harmony.config.Device; public class HarmonyDevice { @@ -9,6 +11,14 @@ public Device getDevice() { return device; } public void setDevice(Device device) { + byte ptext[]; + String theLabel = device.getLabel(); + try { + ptext = theLabel.getBytes("ISO-8859-1"); + device.setLabel(new String(ptext, "UTF-8")); + } catch (UnsupportedEncodingException e) { + device.setLabel(theLabel); + } this.device = device; } public String getHub() { diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 88225877..ef6f706d 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -47,27 +47,25 @@ app.service('bridgeService', function ($http, $window, ngToast) { this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, habridgeversion: ""}; this.displayWarn = function(errorTitle, error) { - if(error == null || typeof(error) != 'undefined') { - error = {status: 200, statusText: "OK", data: []}; - error.data = {message: "success"}; - } + var toastContent = errorTitle; + if(error != null && typeof(error) != 'undefined') + toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status; ngToast.create({ className: "warning", dismissButton: true, dismissOnTimeout: false, - content: errorTitle + error.data.message + " with status: " + error.statusText + " - " + error.status}); + content: toastContent}); }; this.displayError = function(errorTitle, error) { - if(error == null || typeof(error) != 'undefined') { - error = {status: 200, statusText: "OK", data: []}; - error.data = {message: "success"}; - } + var toastContent = errorTitle; + if(error != null && typeof(error) != 'undefined') + toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status; ngToast.create({ className: "danger", dismissButton: true, dismissOnTimeout: false, - content: errorTitle + error.data.message + " with status: " + error.statusText + " - " + error.status}); + content: toastContent}); }; this.displayErrorMessage = function(errorTitle, errorMessage) { @@ -101,6 +99,7 @@ app.service('bridgeService', function ($http, $window, ngToast) { self.state.device.mapId = null; self.state.device.name = ""; self.state.device.onUrl = ""; + self.state.device.dimUrl = ""; self.state.device.deviceType = "custom"; self.state.device.targetDevice = null; self.state.device.offUrl = ""; @@ -108,7 +107,7 @@ app.service('bridgeService', function ($http, $window, ngToast) { self.state.device.contentType = null; self.state.device.contentBody = null; self.state.device.contentBodyOff = null; - self.state.bridge.olddevicename = ""; + self.state.olddevicename = ""; }; this.getHABridgeVersion = function () { @@ -303,27 +302,16 @@ app.service('bridgeService', function ($http, $window, ngToast) { ); }; - this.addDevice = function (device) { + this.addDevice = function (aDevice) { + var device = {}; + angular.extend(device, aDevice ); if(device.httpVerb != null && device.httpVerb != "") device.deviceType = "custom"; if(device.targetDevice == null || device.targetDevice == "") device.targetDevice = "Encapsulated"; if (device.id) { var putUrl = this.state.base + "/" + device.id; - return $http.put(putUrl, { - id: device.id, - name: device.name, - mapId: device.mapId, - mapType: device.mapType, - deviceType: device.deviceType, - targetDevice: device.targetDevice, - onUrl: device.onUrl, - offUrl: device.offUrl, - httpVerb: device.httpVerb, - contentType: device.contentType, - contentBody: device.contentBody, - contentBodyOff: device.contentBodyOff - }).then( + return $http.put(putUrl, device).then( function (response) { }, function (error) { @@ -333,19 +321,7 @@ app.service('bridgeService', function ($http, $window, ngToast) { } else { if(device.deviceType == null || device.deviceType == "") device.deviceType = "custom"; - return $http.post(this.state.base, { - name: device.name, - mapId: device.mapId, - mapType: device.mapType, - deviceType: device.deviceType, - targetDevice: device.targetDevice, - onUrl: device.onUrl, - offUrl: device.offUrl, - httpVerb: device.httpVerb, - contentType: device.contentType, - contentBody: device.contentBody, - contentBodyOff: device.contentBodyOff - }).then( + return $http.post(this.state.base, device).then( function (response) { }, function (error) { @@ -523,11 +499,11 @@ app.service('bridgeService', function ($http, $window, ngToast) { var msgDescription = "unknown"; var testUrl = this.state.huebase + "/test/lights/" + device.id + "/state"; var testBody = "{\"on\":"; - if(type == "on") { - testBody = testBody + "true"; + if(type == "off") { + testBody = testBody + "false"; } else { - testBody = testBody + "false"; + testBody = testBody + "true"; } if(value) { testBody = testBody + ",\"bri\":" + value; @@ -683,12 +659,15 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, $scope.imgBkUrl = "glyphicon glyphicon-plus"; $scope.testUrl = function (device, type) { var dialogNeeded = false; - if((type == "on" && (bridgeService.aContainsB(device.onUrl, "${intensity..byte}") || + if((type == "on" && (bridgeService.aContainsB(device.onUrl, "${intensity.byte}") || bridgeService.aContainsB(device.onUrl, "${intensity.percent}") || bridgeService.aContainsB(device.onUrl, "${intensity.math("))) || - (type == "off" && (bridgeService.aContainsB(device.offUrl, "${intensity..byte}") || + (type == "off" && (bridgeService.aContainsB(device.offUrl, "${intensity.byte}") || bridgeService.aContainsB(device.offUrl, "${intensity.percent}") || - bridgeService.aContainsB(device.offUrl, "${intensity.math(")))) { + bridgeService.aContainsB(device.offUrl, "${intensity.math("))) || + (type == "dim" && (bridgeService.aContainsB(device.dimUrl, "${intensity.byte}") || + bridgeService.aContainsB(device.dimUrl, "${intensity.percent}") || + bridgeService.aContainsB(device.dimUrl, "${intensity.math(")))) { $scope.bridge.device = device; $scope.bridge.type = type; ngDialog.open({ @@ -792,15 +771,18 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi $scope.device.mapType = "veraDevice"; $scope.device.mapId = veradevice.id; if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) - $scope.device.onUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + $scope.device.dimUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&DeviceNum=" + veradevice.id + "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=" + dim_control; else - $scope.device.onUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + $scope.device.dimUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + veradevice.id; + $scope.device.onUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + + veradevice.id; $scope.device.offUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=" + veradevice.id; @@ -999,8 +981,8 @@ app.controller('NestController', function ($scope, $location, $http, bridgeServi $scope.device.targetDevice = nestitem.location; $scope.device.mapType = "nestThermoSet"; $scope.device.mapId = nestitem.id + "-SetTemp"; - $scope.device.onUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; - $scope.device.offUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; + $scope.device.dimUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}"; }; $scope.buildNestHeatUrls = function (nestitem) { @@ -1090,7 +1072,7 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi $scope.device_dim_control = ""; $scope.bulk = { devices: [] }; var veraList = angular.fromJson($scope.bridge.settings.veraaddress); - if(veraList != null) + if(veraList != null && veraList.length > 0) $scope.vera = {base: "http://" + veraList.devices[0].ip, port: "3480", id: ""}; else $scope.vera = {base: "http://", port: "3480", id: ""}; @@ -1110,15 +1092,18 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi $scope.device.mapType = "veraDevice"; $scope.device.mapId = $scope.vera.id; if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) - $scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port + $scope.device.dimUrl = $scope.vera.base + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&DeviceNum=" + $scope.vera.id + "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=" + dim_control; else - $scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port + $scope.device.dimUrl = $scope.vera.base + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + $scope.vera.id; + $scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + + $scope.vera.id; $scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=" + $scope.vera.id; diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index de0f7f10..843db526 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -36,6 +36,8 @@

Current devices ({{bridge.devices.length}})

+ +

+
+ + +
+ +
+
+
+
+
+ + +
+ +
+
+