From 5e59b33ed7ed2eda16a8829d3dea4117a2bb2c2f Mon Sep 17 00:00:00 2001 From: Admin Date: Thu, 23 Feb 2017 16:47:06 -0600 Subject: [PATCH] Fixed hex conversions. Added checks for formats. Finished Bulk add issues. Fixing Domoticz home and handler for user/pwd. --- pom.xml | 2 +- .../com/bwssystems/HABridge/HomeManager.java | 2 +- .../HABridge/hue/BrightnessDecode.java | 17 +-- .../plugins/domoticz/DomoticzHome.java | 33 +++++- .../HABridge/plugins/http/HTTPHome.java | 41 ++++--- .../HABridge/plugins/tcp/TCPHome.java | 72 ++++++------ .../HABridge/plugins/udp/UDPHome.java | 67 ++++++----- src/main/resources/public/scripts/app.js | 110 +++++++++++------- .../public/views/domoticzdevice.html | 2 +- .../resources/public/views/haldevice.html | 16 +-- .../resources/public/views/huedevice.html | 2 +- .../resources/public/views/lifxdevice.html | 2 +- .../resources/public/views/veradevice.html | 2 +- 13 files changed, 216 insertions(+), 152 deletions(-) diff --git a/pom.xml b/pom.xml index f0e5330..ca0a205 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 4.1.4b + 4.1.4c jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/HomeManager.java b/src/main/java/com/bwssystems/HABridge/HomeManager.java index 798fbc1..b11c76a 100644 --- a/src/main/java/com/bwssystems/HABridge/HomeManager.java +++ b/src/main/java/com/bwssystems/HABridge/HomeManager.java @@ -72,7 +72,6 @@ public class HomeManager { homeList.put(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome); - homeList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); //setup the tcp handler Home aHome = new TCPHome(bridgeSettings); homeList.put(DeviceMapTypes.TCP_DEVICE[DeviceMapTypes.typeIndex], aHome); @@ -87,6 +86,7 @@ public class HomeManager { resourceList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome); //setup the Domoticz configuration if available aHome = new DomoticzHome(bridgeSettings); + homeList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); resourceList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); //setup the Lifx configuration if available aHome = new LifxHome(bridgeSettings); diff --git a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java index 55da9dd..7c31f11 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java @@ -1,15 +1,10 @@ package com.bwssystems.HABridge.hue; import java.math.BigDecimal; -import java.math.BigInteger; import java.util.HashMap; import java.util.Map; - -import javax.xml.bind.DatatypeConverter; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import net.java.dev.eval.Expression; public class BrightnessDecode { @@ -49,9 +44,7 @@ public class BrightnessDecode { } if (request.contains(INTENSITY_BYTE)) { if (isHex) { - BigInteger bigInt = BigInteger.valueOf(intensity); - byte[] theBytes = bigInt.toByteArray(); - String hexValue = DatatypeConverter.printHexBinary(theBytes); + String hexValue = Integer.toHexString(intensity); request = request.replace(INTENSITY_BYTE, hexValue); } else { String intensityByte = String.valueOf(intensity); @@ -60,9 +53,7 @@ public class BrightnessDecode { } else if (request.contains(INTENSITY_PERCENT)) { int percentBrightness = (int) Math.round(intensity / 255.0 * 100); if (isHex) { - BigInteger bigInt = BigInteger.valueOf(percentBrightness); - byte[] theBytes = bigInt.toByteArray(); - String hexValue = DatatypeConverter.printHexBinary(theBytes); + String hexValue = Integer.toHexString(percentBrightness); request = request.replace(INTENSITY_PERCENT, hexValue); } else { String intensityPercent = String.valueOf(percentBrightness); @@ -81,9 +72,7 @@ public class BrightnessDecode { BigDecimal result = exp.eval(variables); Integer endResult = Math.round(result.floatValue()); if (isHex) { - BigInteger bigInt = BigInteger.valueOf(endResult); - byte[] theBytes = bigInt.toByteArray(); - String hexValue = DatatypeConverter.printHexBinary(theBytes); + String hexValue = Integer.toHexString(endResult); request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, hexValue); } else { request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, diff --git a/src/main/java/com/bwssystems/HABridge/plugins/domoticz/DomoticzHome.java b/src/main/java/com/bwssystems/HABridge/plugins/domoticz/DomoticzHome.java index ebc5af8..ce08ecf 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/domoticz/DomoticzHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/domoticz/DomoticzHome.java @@ -1,5 +1,6 @@ package com.bwssystems.HABridge.plugins.domoticz; +import java.net.InetAddress; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -13,8 +14,11 @@ import com.bwssystems.HABridge.BridgeSettingsDescriptor; import com.bwssystems.HABridge.Home; import com.bwssystems.HABridge.NamedIP; import com.bwssystems.HABridge.api.CallItem; +import com.bwssystems.HABridge.api.hue.HueError; +import com.bwssystems.HABridge.api.hue.HueErrorResponse; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.MultiCommandUtil; +import com.google.gson.Gson; public class DomoticzHome implements Home { private static final Logger log = LoggerFactory.getLogger(DomoticzHome.class); @@ -66,8 +70,28 @@ public class DomoticzHome implements Home { @Override public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity, Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) { - // Not a device handler - return null; + String responseString = null; + + String theUrl = anItem.getItem().getAsString(); + if(theUrl != null && !theUrl.isEmpty () && (theUrl.startsWith("http://") || theUrl.startsWith("https://"))) { + String intermediate = theUrl.substring(theUrl.indexOf("://") + 3); + String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); + String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1); + String hostAddr = null; + String port = null; + if (hostPortion.contains(":")) { + hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); + port = hostPortion.substring(intermediate.indexOf(':') + 1); + } else + hostAddr = hostPortion; + + } else { + log.warn("Domoticz Call to be presented as http(s)://(:)/payload, format of request unknown: " + theUrl); + responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, + "Error on calling url to change device state", "/lights/" + + lightId + "state", null, null).getTheErrors(), HueError[].class); + } + return responseString; } @Override @@ -90,6 +114,11 @@ public class DomoticzHome implements Home { return this; } + private DomoticzHandler findHandlerByAddress(String hostAddress) { + DomoticzHandler aHandler = null; + + return aHandler; + } @Override public void closeHome() { // noop diff --git a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java index 97cb753..985fd7e 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java @@ -29,23 +29,25 @@ public class HTTPHome implements Home { Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) { String responseString = null; - //Backwards Compatibility Items - if(anItem.getHttpVerb() == null || anItem.getHttpVerb().isEmpty()) - { - if(device.getHttpVerb() != null && !device.getHttpVerb().isEmpty()) - anItem.setHttpVerb(device.getHttpVerb()); - } + String theUrl = anItem.getItem().getAsString(); + if(theUrl != null && !theUrl.isEmpty () && (theUrl.startsWith("http://") || theUrl.startsWith("https://"))) { + //Backwards Compatibility Items + if(anItem.getHttpVerb() == null || anItem.getHttpVerb().isEmpty()) + { + if(device.getHttpVerb() != null && !device.getHttpVerb().isEmpty()) + anItem.setHttpVerb(device.getHttpVerb()); + } + + if(anItem.getHttpHeaders() == null || anItem.getHttpHeaders().isEmpty()) { + if(device.getHeaders() != null && !device.getHeaders().isEmpty() ) + anItem.setHttpHeaders(device.getHeaders()); + } + + log.debug("executing HUE api request to Http " + + (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": " + + anItem.getItem().getAsString()); - if(anItem.getHttpHeaders() == null || anItem.getHttpHeaders().isEmpty()) { - if(device.getHeaders() != null && !device.getHeaders().isEmpty() ) - anItem.setHttpHeaders(device.getHeaders()); - } - - log.debug("executing HUE api request to Http " - + (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": " - + anItem.getItem().getAsString()); - - String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(), + String anUrl = BrightnessDecode.calculateReplaceIntensityValue(theUrl, intensity, targetBri, targetBriInc, false); anUrl = TimeDecode.replaceTimeValue(anUrl); @@ -63,6 +65,13 @@ public class HTTPHome implements Home { "Error on calling url to change device state", "/lights/" + lightId + "state", null, null).getTheErrors(), HueError[].class); } + } else { + log.warn("HTTP Call to be presented as http(s)://(:)/payload, format of request unknown: " + theUrl); + responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, + "Error on calling url to change device state", "/lights/" + + lightId + "state", null, null).getTheErrors(), HueError[].class); + } + return responseString; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java index 52e94bc..5fb124b 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java @@ -32,41 +32,45 @@ public class TCPHome implements Home { public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity, Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) { log.debug("executing HUE api request to TCP: " + anItem.getItem().getAsString()); - String intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3); - String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); - String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1); - String hostAddr = null; - String port = null; - InetAddress IPAddress = null; - if (hostPortion.contains(":")) { - hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); - port = hostPortion.substring(intermediate.indexOf(':') + 1); + String theUrl = anItem.getItem().getAsString(); + if(theUrl != null && !theUrl.isEmpty () && theUrl.startsWith("tcp://")) { + String intermediate = theUrl.substring(theUrl.indexOf("://") + 3); + String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); + String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1); + String hostAddr = null; + String port = null; + InetAddress IPAddress = null; + if (hostPortion.contains(":")) { + hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); + port = hostPortion.substring(intermediate.indexOf(':') + 1); + } else + hostAddr = hostPortion; + try { + IPAddress = InetAddress.getByName(hostAddr); + } catch (UnknownHostException e) { + // noop + } + + theUrlBody = TimeDecode.replaceTimeValue(theUrlBody); + if (theUrlBody.startsWith("0x")) { + theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true); + sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); + } else { + theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false); + sendData = theUrlBody.getBytes(); + } + + try { + Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port)); + DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream()); + outToClient.write(sendData); + outToClient.flush(); + dataSendSocket.close(); + } catch (Exception e) { + // noop + } } else - hostAddr = hostPortion; - try { - IPAddress = InetAddress.getByName(hostAddr); - } catch (UnknownHostException e) { - // noop - } - - theUrlBody = TimeDecode.replaceTimeValue(theUrlBody); - if (theUrlBody.startsWith("0x")) { - theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true); - sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); - } else { - theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false); - sendData = theUrlBody.getBytes(); - } - - try { - Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port)); - DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream()); - outToClient.write(sendData); - outToClient.flush(); - dataSendSocket.close(); - } catch (Exception e) { - // noop - } + log.warn("Tcp Call to be presented as tcp://:/payload, format of request unknown: " + theUrl); return null; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java index 3669081..b93a72e 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java @@ -33,39 +33,44 @@ public class UDPHome implements Home { public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity, Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) { log.debug("executing HUE api request to UDP: " + anItem.getItem().getAsString()); - String intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3); - String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); - String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1); - String hostAddr = null; - String port = null; - InetAddress IPAddress = null; - if (hostPortion.contains(":")) { - hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); - port = hostPortion.substring(intermediate.indexOf(':') + 1); + String theUrl = anItem.getItem().getAsString(); + if(theUrl != null && !theUrl.isEmpty () && theUrl.startsWith("udp://")) { + String intermediate = theUrl.substring(theUrl.indexOf("://") + 3); + String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); + String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1); + String hostAddr = null; + String port = null; + InetAddress IPAddress = null; + if (hostPortion.contains(":")) { + hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); + port = hostPortion.substring(intermediate.indexOf(':') + 1); + } else + hostAddr = hostPortion; + try { + IPAddress = InetAddress.getByName(hostAddr); + } catch (UnknownHostException e) { + log.warn("Udp Call, unknown host, continuing..."); + return null; + } + + theUrlBody = TimeDecode.replaceTimeValue(theUrlBody); + if (theUrlBody.startsWith("0x")) { + theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true); + sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); + } else { + theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false); + sendData = theUrlBody.getBytes(); + } + try { + theUDPDatagramSender.sendUDPResponse(sendData, IPAddress, Integer.parseInt(port)); + } catch (NumberFormatException e) { + log.warn("Udp Call, Number format exception on port, continuing..."); + } catch (IOException e) { + log.warn("IO exception on udp call, continuing..."); + } } else - hostAddr = hostPortion; - try { - IPAddress = InetAddress.getByName(hostAddr); - } catch (UnknownHostException e) { - log.warn("Udp Call, unknown host, continuing..."); - return null; - } + log.warn("Udp Call to be presented as udp://:/payload, format of request unknown: " + theUrl); - theUrlBody = TimeDecode.replaceTimeValue(theUrlBody); - if (theUrlBody.startsWith("0x")) { - theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true); - sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); - } else { - theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false); - sendData = theUrlBody.getBytes(); - } - try { - theUDPDatagramSender.sendUDPResponse(sendData, IPAddress, Integer.parseInt(port)); - } catch (NumberFormatException e) { - log.warn("Udp Call, Number format exception on port, continuing..."); - } catch (IOException e) { - log.warn("IO exception on udp call, continuing..."); - } return null; } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index e8ea1f0..612162d 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -1227,7 +1227,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi $scope.device = bridgeService.state.device; }; - $scope.buildDeviceUrls = function (veradevice, dim_control) { + $scope.buildDeviceUrls = function (veradevice, dim_control, buildonly) { if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) { dimpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&DeviceNum=" @@ -1248,8 +1248,10 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, veradevice.id, veradevice.name, veradevice.veraname, "switch", "veraDevice", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; $scope.buildSceneUrls = function (verascene) { @@ -1268,10 +1270,11 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi $scope.bulkAddDevices = function(dim_control) { var devicesList = []; + $scope.clearDevice(); for(var i = 0; i < $scope.bulk.devices.length; i++) { for(var x = 0; x < bridgeService.state.veradevices.length; x++) { if(bridgeService.state.veradevices[x].id === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.veradevices[x],dim_control); + $scope.buildDeviceUrls(bridgeService.state.veradevices[x],dim_control,true); devicesList[i] = { name: $scope.device.name, mapId: $scope.device.mapId, @@ -1288,6 +1291,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; + $scope.clearDevice(); } } } @@ -1331,7 +1335,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi else { $scope.selectAll = true; for(var x = 0; x < bridgeService.state.veradevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.veradevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.veradevices[x].id, bridgeService.state.veradevices[x].veraname, "veraDevice")) + if($scope.bulk.devices.indexOf(bridgeService.state.veradevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.veradevices[x].id); } } @@ -1541,16 +1545,19 @@ app.controller('HueController', function ($scope, $location, $http, bridgeServic offpayload = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.huedeviceid +"\",\"hueName\":\"" + huedevice.huename + "\"}"; bridgeService.buildUrls(onpayload, null, offpayload, true, huedevice.device.uniqueid, huedevice.device.name, huedevice.huename, "passthru", "hueDevice", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; $scope.bulkAddDevices = function() { var devicesList = []; + $scope.clearDevice(); for(var i = 0; i < $scope.bulk.devices.length; i++) { for(var x = 0; x < bridgeService.state.huedevices.length; x++) { if(bridgeService.state.huedevices[x].device.uniqueid === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.huedevices[x]); + $scope.buildDeviceUrls(bridgeService.state.huedevices[x],true); devicesList[i] = { name: $scope.device.name, mapId: $scope.device.mapId, @@ -1567,6 +1574,7 @@ app.controller('HueController', function ($scope, $location, $http, bridgeServic contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; + $scope.clearDevice(); } } } @@ -1654,7 +1662,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic $scope.device = bridgeService.state.device; }; - $scope.buildDeviceUrls = function (haldevice, dim_control) { + $scope.buildDeviceUrls = function (haldevice, dim_control, buildonly) { var preOnCmd = ""; var preDimCmd = ""; var preOffCmd = ""; @@ -1709,11 +1717,13 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic + postCmd; bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname, haldevice.haldevicename, haldevice.halname, aDeviceType, "halDevice", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildButtonUrls = function (haldevice, onbutton, offbutton) { + $scope.buildButtonUrls = function (haldevice, onbutton, offbutton, buildonly) { var actionOn = angular.fromJson(onbutton); var actionOff = angular.fromJson(offbutton); onpayload = "http://" + haldevice.haladdress + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOn.DeviceName.replaceAll(" ", "%20") + "?Token=" + $scope.bridge.settings.haltoken; @@ -1721,20 +1731,24 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-" + actionOn.DeviceName, haldevice.haldevicename, haldevice.halname, "button", "halButton", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildHALHomeUrls = function (haldevice) { + $scope.buildHALHomeUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Home?Token=" + $scope.bridge.settings.haltoken; offpayload = "http://" + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Away?Token=" + $scope.bridge.settings.haltoken; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-HomeAway", haldevice.haldevicename, haldevice.halname, "home", "halHome", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildHALHeatUrls = function (haldevice) { + $scope.buildHALHeatUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") @@ -1752,11 +1766,13 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic + $scope.bridge.settings.haltoken; bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-SetHeat", haldevice.haldevicename + " Heat", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildHALCoolUrls = function (haldevice) { + $scope.buildHALCoolUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") @@ -1774,11 +1790,13 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic + $scope.bridge.settings.haltoken; bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-SetCool", haldevice.haldevicename + " Cool", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildHALAutoUrls = function (haldevice) { + $scope.buildHALAutoUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") @@ -1790,11 +1808,13 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic + "!HVACMode=Off?Token=" bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-SetAuto", haldevice.haldevicename + " Auto", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildHALOffUrls = function (haldevice) { + $scope.buildHALOffUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") @@ -1807,11 +1827,13 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic $scope.device.offUrl = "http://" + haldevice.haladdress bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-TurnOff", haldevice.haldevicename + " Thermostat", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.buildHALFanUrls = function (haldevice) { + $scope.buildHALFanUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") @@ -1824,21 +1846,24 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic + $scope.bridge.settings.haltoken; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-SetFan", haldevice.haldevicename + " Fan", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; $scope.bulkAddDevices = function(dim_control) { var devicesList = []; + $scope.clearDevice(); for(var i = 0; i < $scope.bulk.devices.length; i++) { for(var x = 0; x < bridgeService.state.haldevices.length; x++) { if(bridgeService.state.haldevices[x].haldevicename === $scope.bulk.devices[i]) { if(bridgeService.state.haldevices[x].haldevicetype === "HVAC") - $scope.buildHALAutoUrls(bridgeService.state.haldevices[x]); + $scope.buildHALAutoUrls(bridgeService.state.haldevices[x], true); else if(bridgeService.state.haldevices[x].haldevicetype === "HOME") - $scope.buildHALHomeUrls(bridgeService.state.haldevices[x]); + $scope.buildHALHomeUrls(bridgeService.state.haldevices[x], true); else - $scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control); + $scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control, true); devicesList[i] = { name: $scope.device.name, mapId: $scope.device.mapId, @@ -1855,6 +1880,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; + $scope.clearDevice(); } } } @@ -1897,7 +1923,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic else { $scope.selectAll = true; for(var x = 0; x < bridgeService.state.haldevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.haldevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.haldevices[x].haldevicename + "-" + bridgeService.state.haldevices[x].halname, bridgeService.state.haldevices[x].halname, "halDevice")) + if($scope.bulk.devices.indexOf(bridgeService.state.haldevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.haldevices[x].haldevicename); } } @@ -2191,7 +2217,7 @@ app.controller('DomoticzController', function ($scope, $location, $http, bridgeS bridgeService.viewHalDevices(); }, function (error) { - bridgeService.displayWarn("Error adding HAL devices in bulk.", error) + bridgeService.displayWarn("Error adding Domoticz devices in bulk.", error) } ); $scope.bulk = { devices: [] }; @@ -2223,8 +2249,8 @@ app.controller('DomoticzController', function ($scope, $location, $http, bridgeS else { $scope.selectAll = true; for(var x = 0; x < bridgeService.state.haldevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.haldevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.haldevices[x].haldevicename + "-" + bridgeService.state.haldevices[x].halname, bridgeService.state.haldevices[x].halname, "halDevice")) - $scope.bulk.devices.push(bridgeService.state.haldevices[x].haldevicename); + if($scope.bulk.devices.indexOf(bridgeService.state.domoticzdevices[x]) < 0) + $scope.bulk.devices.push(bridgeService.state.domoticzdevices[x].devicename); } } }; @@ -2281,6 +2307,7 @@ app.controller('LifxController', function ($scope, $location, $http, bridgeServi $scope.bulkAddDevices = function(dim_control) { var devicesList = []; + $scope.clearDevice(); for(var i = 0; i < $scope.bulk.devices.length; i++) { for(var x = 0; x < bridgeService.state.lifxdevices.length; x++) { if(bridgeService.state.lifxdevices[x].devicename === $scope.bulk.devices[i]) { @@ -2301,6 +2328,7 @@ app.controller('LifxController', function ($scope, $location, $http, bridgeServi contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; + $scope.clearDevice(); } } } @@ -2343,8 +2371,8 @@ app.controller('LifxController', function ($scope, $location, $http, bridgeServi else { $scope.selectAll = true; for(var x = 0; x < bridgeService.state.haldevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.haldevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.haldevices[x].haldevicename + "-" + bridgeService.state.haldevices[x].halname, bridgeService.state.haldevices[x].halname, "halDevice")) - $scope.bulk.devices.push(bridgeService.state.haldevices[x].haldevicename); + if($scope.bulk.devices.indexOf(bridgeService.state.lifxdevices[x]) < 0) + $scope.bulk.devices.push(bridgeService.state.lifxdevices[x].devicename); } } }; diff --git a/src/main/resources/public/views/domoticzdevice.html b/src/main/resources/public/views/domoticzdevice.html index 2359739..7f4f151 100644 --- a/src/main/resources/public/views/domoticzdevice.html +++ b/src/main/resources/public/views/domoticzdevice.html @@ -76,7 +76,7 @@ {{domoticzdevice.domoticzname}} + ng-click="buildDeviceUrls(domoticzdevice, device_dim_control,false)">Build Item diff --git a/src/main/resources/public/views/haldevice.html b/src/main/resources/public/views/haldevice.html index a185dbe..13878cf 100644 --- a/src/main/resources/public/views/haldevice.html +++ b/src/main/resources/public/views/haldevice.html @@ -89,27 +89,27 @@ + ng-click="buildDeviceUrls(haldevice, device_dim_control, false)">Build Item + ng-click="buildHALHomeUrls(haldevice, false)">Build Home/Away
  • + ng-click="buildHALHeatUrls(haldevice, false)">Heat + ng-click="buildHALCoolUrls(haldevice, false)">Cool + ng-click="buildHALAutoUrls(haldevice, false)">Auto

    + ng-click="buildHALOffUrls(haldevice, false)">Off + ng-click="buildHALFanUrls(haldevice, false)">Fan

diff --git a/src/main/resources/public/views/huedevice.html b/src/main/resources/public/views/huedevice.html index e3ae20d..7d9325c 100644 --- a/src/main/resources/public/views/huedevice.html +++ b/src/main/resources/public/views/huedevice.html @@ -65,7 +65,7 @@ {{huedevice.huename}} + ng-click="buildDeviceUrls(huedevice, false)">Build Item diff --git a/src/main/resources/public/views/lifxdevice.html b/src/main/resources/public/views/lifxdevice.html index 6278cea..465c557 100644 --- a/src/main/resources/public/views/lifxdevice.html +++ b/src/main/resources/public/views/lifxdevice.html @@ -59,7 +59,7 @@ {{lifxdev.type}} diff --git a/src/main/resources/public/views/veradevice.html b/src/main/resources/public/views/veradevice.html index cba365c..68105af 100644 --- a/src/main/resources/public/views/veradevice.html +++ b/src/main/resources/public/views/veradevice.html @@ -80,7 +80,7 @@ {{veradevice.veraname}} + ng-click="buildDeviceUrls(veradevice, device_dim_control, false)">Build Item