diff --git a/src/main/java/com/bwssystems/HABridge/HABridge.java b/src/main/java/com/bwssystems/HABridge/HABridge.java index 1ae6daf..7e67655 100644 --- a/src/main/java/com/bwssystems/HABridge/HABridge.java +++ b/src/main/java/com/bwssystems/HABridge/HABridge.java @@ -10,6 +10,7 @@ import com.bwssystems.HABridge.hue.HueMulator; import com.bwssystems.HABridge.upnp.UpnpListener; import com.bwssystems.HABridge.upnp.UpnpSettingsResource; import com.bwssystems.NestBridge.NestHome; +import com.bwssystems.hal.HalHome; import com.bwssystems.harmony.HarmonyHome; import com.bwssystems.hue.HueHome; @@ -36,6 +37,7 @@ public class HABridge { HarmonyHome harmonyHome; NestHome nestHome; HueHome hueHome; + HalHome halHome; HueMulator theHueMulator; UpnpSettingsResource theSettingResponder; UpnpListener theUpnpListener; @@ -66,8 +68,10 @@ public class HABridge { nestHome = new NestHome(bridgeSettings.getBridgeSettingsDescriptor()); //setup the hue passtrhu configuration if available hueHome = new HueHome(bridgeSettings.getBridgeSettingsDescriptor()); + //setup the hal configuration if available + halHome = new HalHome(bridgeSettings.getBridgeSettingsDescriptor()); // setup the class to handle the resource setup rest api - theResources = new DeviceResource(bridgeSettings.getBridgeSettingsDescriptor(), harmonyHome, nestHome, hueHome); + theResources = new DeviceResource(bridgeSettings.getBridgeSettingsDescriptor(), harmonyHome, nestHome, hueHome, halHome); // setup the class to handle the hue emulator rest api theHueMulator = new HueMulator(bridgeSettings.getBridgeSettingsDescriptor(), theResources.getDeviceRepository(), harmonyHome, nestHome, hueHome); theHueMulator.setupServer(); diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index d29681f..cd0fdc6 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -44,7 +44,7 @@ public class DeviceResource { private HalHome halHome; private static final Set supportedVerbs = new HashSet<>(Arrays.asList("get", "put", "post")); - public DeviceResource(BridgeSettingsDescriptor theSettings, HarmonyHome theHarmonyHome, NestHome aNestHome, HueHome aHueHome) { + public DeviceResource(BridgeSettingsDescriptor theSettings, HarmonyHome theHarmonyHome, NestHome aNestHome, HueHome aHueHome, HalHome aHalHome) { this.deviceRepository = new DeviceRepository(theSettings.getUpnpDeviceDb()); if(theSettings.isValidVera()) @@ -68,7 +68,7 @@ public class DeviceResource { this.hueHome = null; if(theSettings.isValidHal()) - this.hueHome = aHueHome; + this.halHome = aHalHome; else this.halHome = null; diff --git a/src/main/java/com/bwssystems/hal/HalHome.java b/src/main/java/com/bwssystems/hal/HalHome.java index 0c50d5f..ddfc1b3 100644 --- a/src/main/java/com/bwssystems/hal/HalHome.java +++ b/src/main/java/com/bwssystems/hal/HalHome.java @@ -21,7 +21,7 @@ public class HalHome { hals = new HashMap(); if(!bridgeSettings.isValidHal()) return; - Iterator theList = bridgeSettings.getHarmonyAddress().getDevices().iterator(); + Iterator theList = bridgeSettings.getHaladdress().getDevices().iterator(); while(theList.hasNext()) { NamedIP aHal = theList.next(); try { diff --git a/src/main/java/com/bwssystems/util/TextStringFormatter.java b/src/main/java/com/bwssystems/util/TextStringFormatter.java index 9566401..28b8293 100644 --- a/src/main/java/com/bwssystems/util/TextStringFormatter.java +++ b/src/main/java/com/bwssystems/util/TextStringFormatter.java @@ -221,6 +221,9 @@ public final class TextStringFormatter { public static String forQuerySpace(String aURL) { return aURL.replace(" ", "\u0020"); } + public static String forQuerySpaceUrl(String aURL) { + return aURL.replace(" ", "%20"); + } /** * Synonym for URLEncoder.encode(String, "UTF-8"). * diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index be266f5..b9adc82 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -48,6 +48,18 @@ app.run( function (bridgeService) { bridgeService.getHABridgeVersion(); }); +String.prototype.replaceAll = function(search, replace) +{ + //if replace is not sent, return original string otherwise it will + //replace search string with 'undefined'. + if (replace === undefined) { + return this.toString(); + } + + return this.replace(new RegExp('[' + search + ']', 'g'), replace); +}; + + app.service('bridgeService', function ($http, $window, ngToast) { var self = this; 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: [], mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, habridgeversion: ""}; @@ -1323,35 +1335,38 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic $scope.buildDeviceUrls = function (haldevice, dim_control) { bridgeService.clearDevice(); + $scope.device = $scope.bridge.device; $scope.device.deviceType = "switch"; $scope.device.name = haldevice.haldevicename; $scope.device.targetDevice = haldevice.halname; $scope.device.mapType = "halDevice"; $scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname; if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) - $scope.device.dimUrl = "http://" + haldevice.veraaddress + $scope.device.dimUrl = "http://" + haldevice.haladdress + "/DeviceService!DeviceName=" - + haldevice.haldevicename + + haldevice.haldevicename.replaceAll(" ", "%20") + "!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent=" + dim_control + "?Token=" + $scope.bridge.settings.haltoken; else - $scope.device.dimUrl = "http://" + veradevice.veraaddress + $scope.device.dimUrl = "http://" + haldevice.haladdress + "/DeviceService!DeviceName=" - + haldevice.haldevicename + + haldevice.haldevicename.replaceAll(" ", "%20") + "!DeviceCmd=SetDevice!DeviceValue=On?Token=" + $scope.bridge.settings.haltoken; - $scope.device.onUrl = "http://" + veradevice.veraaddress + $scope.device.onUrl = "http://" + haldevice.haladdress + "/DeviceService!DeviceName=" - + haldevice.haldevicename + + haldevice.haldevicename.replaceAll(" ", "%20") + "!DeviceCmd=SetDevice!DeviceValue=On?Token=" - + $scope.bridge.settings.haltoken;; - $scope.device.offUrl = "http://" + veradevice.veraaddress + + $scope.bridge.settings.haltoken; + $scope.device.offUrl = "http://" + haldevice.haladdress + "/DeviceService!DeviceName=" - + haldevice.haldevicename + + haldevice.haldevicename.replaceAll(" ", "%20") + "!DeviceCmd=SetDevice!DeviceValue=Off?Token=" - + $scope.bridge.settings.haltoken;; + + $scope.bridge.settings.haltoken; + + }; $scope.addDevice = function () { @@ -1373,9 +1388,9 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic $scope.bulkAddDevices = function(dim_control) { var devicesList = []; 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); + for(var x = 0; x < bridgeService.state.haldevices.length; x++) { + if(bridgeService.state.haldevices[x].id == $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control); devicesList[i] = { name: $scope.device.name, mapId: $scope.device.mapId, @@ -1396,7 +1411,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic bridgeService.bulkAddDevice(devicesList); $scope.clearDevice(); bridgeService.viewDevices(); - bridgeService.HalVeraDevices(); + bridgeService.viewHalDevices(); $scope.bulk = { devices: [] }; }; @@ -1664,6 +1679,34 @@ app.filter('unavailableHueDeviceId', function(bridgeService) { } }); +app.filter('availableHalDeviceId', function(bridgeService) { + return function(input) { + var out = []; + if(input == null) + return out; + for (var i = 0; i < input.length; i++) { + if(!bridgeService.findDeviceByMapId(input[i].id, input[i].haldevicename, "halDevice")){ + out.push(input[i]); + } + } + return out; + } +}); + +app.filter('unavailableHalDeviceId', function(bridgeService) { + return function(input) { + var out = []; + if(input == null) + return out; + for (var i = 0; i < input.length; i++) { + if(bridgeService.findDeviceByMapId(input[i].id, input[i].haldevicename, "halDevice")){ + out.push(input[i]); + } + } + return out; + } +}); + app.filter('configuredButtons', function() { return function(input) { var out = []; diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index 6a090f6..f935106 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -199,7 +199,7 @@ HAL Token + ng-model="bridge.settings.haltoken" placeholder="thetoken"> Nest Username