From 998450af4e47315eea183d3351fef08ad57d6311 Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 31 May 2017 16:32:33 -0500 Subject: [PATCH] Updating HAL changes --- pom.xml | 2 +- .../HABridge/BridgeSettingsDescriptor.java | 6 +- .../HABridge/plugins/hal/HalHome.java | 9 +- .../HABridge/plugins/hal/HalInfo.java | 5 +- src/main/resources/public/scripts/app.js | 98 ++++++------------- 5 files changed, 45 insertions(+), 75 deletions(-) diff --git a/pom.xml b/pom.xml index 7917216..43d074c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 4.5.1 + 4.5.1a jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java index 319f5c0..797f7b9 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java @@ -385,8 +385,10 @@ public class BridgeSettingsDescriptor { List devicesList = this.getHaladdress().getDevices(); if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS)) return false; - if(this.getHaltoken() == null || this.getHaltoken().equals("")) - return false; + if(devicesList.get(0).getPassword() == null || devicesList.get(0).getPassword().trim().isEmpty()) { + if(this.getHaltoken() == null || this.getHaltoken().equals("")) + return false; + } return true; } public Boolean isValidMQTT() { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java index adb7b98..ecafb89 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java @@ -129,10 +129,9 @@ public class HalHome implements Home { + (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": " + anItem.getItem().getAsString()); - String anUrl = intermediate; + String anUrl = null; - anUrl = BrightnessDecode.calculateReplaceIntensityValue(anUrl, - intensity, targetBri, targetBriInc, false); + anUrl = BrightnessDecode.calculateReplaceIntensityValue(intermediate, intensity, targetBri, targetBriInc, false); anUrl = DeviceDataDecode.replaceDeviceData(anUrl, device); anUrl = TimeDecode.replaceTimeValue(anUrl); @@ -143,6 +142,10 @@ public class HalHome implements Home { anUrl = "https://" + anUrl; else anUrl = "http://" + anUrl; + + if(!anUrl.contains("?Token=")) + anUrl = anUrl + "?Token=" + entry.getValue().getHalAddress().getPassword(); + if (entry.getValue().deviceCommand(anUrl) == null) { log.warn("Error on calling hal to change device state: " + anUrl); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java index 19ff8fd..0110dcc 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java @@ -125,7 +125,10 @@ public class HalInfo { HalDevice aNewHalDevice = new HalDevice(); aNewHalDevice.setHaldevicetype(deviceType); aNewHalDevice.setHaldevicename(theDevice.getDeviceName()); - aNewHalDevice.setHaladdress(halAddress); + NamedIP theaddress = new NamedIP(); + theaddress.setIp(halAddress.getIp()); + theaddress.setName(halAddress.getName()); + aNewHalDevice.setHaladdress(theaddress); deviceList.add(aNewHalDevice); } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 1f1a929..9fbf7ab 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -248,7 +248,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (error.status === 401) $rootScope.$broadcast('securityReinit', 'done'); else - self.displayWarn("Cannot get testuser: ", error); + self.displayWarn("Cannot get testuser: ", error); } ); } @@ -263,7 +263,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (error.status === 401) $rootScope.$broadcast('securityReinit', 'done'); else - self.displayWarn("Cannot get a user: ", error); + self.displayWarn("Cannot get a user: ", error); } ); }; @@ -1134,6 +1134,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.testUrl = function (device, type, value) { var msgDescription = "unknown"; + self.getTestUser(); var testUrl = this.state.huebase + "/" + this.state.testuser + "/lights/" + device.id + "/state"; var testBody = "{\"on\":"; if (type === "off") { @@ -1151,8 +1152,13 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n msgDescription = "success " + angular.toJson(response.data); } if (typeof(response.data[0].error) !== 'undefined') { - msgDescription = "error " + angular.toJson(response.data[0].error); - self.displayErrorMessage("Request Error, Pleae look in your habridge log: ", msgDescription); + if(reponse.data[0].error.indexOf("unauthorized") > -1) { + self.displayWarn("Authorization error, please retry...", null); + } + else { + msgDescription = "error " + angular.toJson(response.data[0].error); + self.displayErrorMessage("Request Error, Please look in your habridge log: ", msgDescription); + } return; } @@ -2202,11 +2208,6 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi var preOffCmd = ""; var nameCmd = ""; var aDeviceType; - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; if(haldevice.haldevicetype === "Group") { aDeviceType = "group"; preOnCmd = "/GroupService!GroupCmd=On"; @@ -2235,24 +2236,20 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi + preDimCmd + dim_control + nameCmd - + haldevice.haldevicename.replaceAll(" ", "%20") - + postCmd; + + haldevice.haldevicename.replaceAll(" ", "%20"); else dimpayload = "http://" + haldevice.haladdress.ip + preOnCmd + nameCmd - + haldevice.haldevicename.replaceAll(" ", "%20") - + postCmd; + + haldevice.haldevicename.replaceAll(" ", "%20"); onpayload = "http://" + haldevice.haladdress.ip + preOnCmd + nameCmd - + haldevice.haldevicename.replaceAll(" ", "%20") - + postCmd; + + haldevice.haldevicename.replaceAll(" ", "%20"); offpayload = "http://" + haldevice.haladdress.ip + preOffCmd + nameCmd - + haldevice.haldevicename.replaceAll(" ", "%20") - + postCmd; + + haldevice.haldevicename.replaceAll(" ", "%20"); bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name, haldevice.haldevicename, haldevice.haladdress.name, aDeviceType, "halDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2264,13 +2261,8 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildButtonUrls = function (haldevice, onbutton, offbutton, buildonly) { var actionOn = angular.fromJson(onbutton); var actionOff = angular.fromJson(offbutton); - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; - onpayload = "http://" + haldevice.haladdress.ip + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOn.DeviceName.replaceAll(" ", "%20") + postCmd; - offpayload = "http://" + haldevice.haladdress.ip + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOff.DeviceName.replaceAll(" ", "%20") + postCmd; + onpayload = "http://" + haldevice.haladdress.ip + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOn.DeviceName.replaceAll(" ", "%20"); + offpayload = "http://" + haldevice.haladdress.ip + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOff.DeviceName.replaceAll(" ", "%20"); bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-" + actionOn.DeviceName, haldevice.haldevicename, haldevice.haladdress.name, "button", "halButton", null, null); $scope.device = bridgeService.state.device; @@ -2281,13 +2273,8 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALHomeUrls = function (haldevice, buildonly) { - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; - onpayload = "http://" + haldevice.haladdress.ip + "/ModeService!ModeCmd=Set!ModeName=Home" + postCmd; - offpayload = "http://" + haldevice.haladdress.ip + "/ModeService!ModeCmd=Set!ModeName=Away" + postCmd; + onpayload = "http://" + haldevice.haladdress.ip + "/ModeService!ModeCmd=Set!ModeName=Home"; + offpayload = "http://" + haldevice.haladdress.ip + "/ModeService!ModeCmd=Set!ModeName=Away"; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-HomeAway", haldevice.haldevicename, haldevice.haladdress.name, "home", "halHome", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2297,23 +2284,18 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALHeatUrls = function (haldevice, buildonly) { - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; onpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Heat" + postCmd; + + "!HVACMode=Heat"; dimpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Heat!HeatSpValue=${intensity.percent}" + postCmd; + + "!HVACMode=Heat!HeatSpValue=${intensity.percent}"; offpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Off" + postCmd; + + "!HVACMode=Off"; bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetHeat", haldevice.haldevicename + " Heat", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2323,23 +2305,18 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALCoolUrls = function (haldevice, buildonly) { - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; onpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Cool" + postCmd; + + "!HVACMode=Cool"; dimpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Cool!CoolSpValue=${intensity.percent}" + postCmd; + + "!HVACMode=Cool!CoolSpValue=${intensity.percent}"; offpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Off" + postCmd; + + "!HVACMode=Off"; bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetCool", haldevice.haldevicename + " Cool", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2349,19 +2326,14 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALAutoUrls = function (haldevice, buildonly) { - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; onpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Auto" + postCmd; + + "!HVACMode=Auto"; offpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Off" + postCmd; + + "!HVACMode=Off"; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetAuto", haldevice.haldevicename + " Auto", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2371,19 +2343,14 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALOffUrls = function (haldevice, buildonly) { - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; onpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Auto" + postCmd; + + "!HVACMode=Auto"; offpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!HVACMode=Off" + postCmd; + + "!HVACMode=Off"; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-TurnOff", haldevice.haldevicename + " Thermostat", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2393,19 +2360,14 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALFanUrls = function (haldevice, buildonly) { - var postCmd = "?Token="; - if(haldevice.haladdress.password === undefined || haldevice.haladdress.password === null || haldevice.haladdress.password.lenght === 0) - postCmd = postCmd + $scope.bridge.settings.haltoken; - else - postCmd = postCmd + haldevice.haladdress.password; onpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!FanMode=On" + postCmd; + + "!FanMode=On"; offpayload = "http://" + haldevice.haladdress.ip + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") - + "!FanMode=Auto" + postCmd; + + "!FanMode=Auto"; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetFan", haldevice.haldevicename + " Fan", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) {