diff --git a/README.md b/README.md index 158be68..977d3b7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ java -jar -Dvera.address=X.Y.Z.A ha-bridge-0.X.Y.jar ### -Dvera.address=`` The argument for the vera address should be given as it the system does not have a way to find the address. Supply -Dvera.address=X.Y.Z.A on the command line to provide it. If a vera is not used, do not set it. ### -Dupnp.config.address=`` -The server defaults to the first available address on the host. Replace the -Dupnp.config.address=`` value with the server ipv4 address you would like to use. +The server defaults to the first available address on the host. Replace the -Dupnp.config.address=`` value with the server ipv4 address you would like to use as the address that any upnp device will call after discovery. ### -Dserver.port=`` The server defaults to running on port 8080. If you're already running a server (like openHAB) on 8080, -Dserver.port=`` on the command line. ### -Dupnp.device.db=`` @@ -45,7 +45,7 @@ POST http://host:8080/api/devices } ``` ## Dimming and value passing control -Dimming is also supported by using the expressions ${intensity.percent} for 0-100 or ${intensity.byte} for 0-255 or $intensity{match()} i.e. "$intensity.math(X/4)}". +Dimming is also supported by using the expressions ${intensity.percent} for 0-100 or ${intensity.byte} for 0-255 or custom values using ${intensity.math()} i.e. "{$intensity.math(X/4)}". e.g. ``` { diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java index 1a541ce..de29383 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java @@ -107,10 +107,14 @@ public class DeviceRepository { } try { - Path target = FileSystems.getDefault().getPath("data", "device.db.old"); - Files.move(filePath, target); + Path target = null; + if(Files.exists(filePath)) { + target = FileSystems.getDefault().getPath(filePath.getParent().toString(), "device.db.old"); + Files.move(filePath, target); + } Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE); - Files.delete(target); + if(target != null) + Files.delete(target); } catch (IOException e) { log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e); } @@ -120,7 +124,7 @@ public class DeviceRepository { String content = null; if(Files.notExists(filePath) || !Files.isReadable(filePath)){ - log.error("Error reading the file: " + filePath + " - Does not exist or is not readable. "); + log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing..."); return null; } diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 686b877..16d2eec 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -257,7 +257,7 @@ public class HueMulator { log.debug("Math eval is: " + mathDescriptor + ", Where " + INTENSITY_MATH_VALUE + " is: " + String.valueOf(intensity)); Expression exp = new Expression(mathDescriptor); BigDecimal result = exp.eval(variables); - Integer endResult = result.intValue(); + Integer endResult = Math.round(result.floatValue()); request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, endResult.toString()); } catch (Exception e) { log.error("Could not execute Math: " + mathDescriptor, e); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index f7c80c5..8d3b264 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -26,6 +26,7 @@ app.config(function ($routeProvider) { app.run( function (bridgeService) { bridgeService.loadBridgeSettings(); + bridgeService.updateShowVera(); }); app.factory('BridgeSettings', function() { @@ -75,7 +76,7 @@ app.factory('BridgeSettings', function() { app.service('bridgeService', function ($http, $window, BridgeSettings) { var self = this; self.BridgeSettings = BridgeSettings; - this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], device: [], error: ""}; + this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], device: [], error: "", showVera: false}; this.viewDevices = function () { this.state.error = ""; @@ -107,6 +108,10 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { self.BridgeSettings.settraceupnp(response.data.traceupnp); self.BridgeSettings.setupnpstrict(response.data.upnpstrict); self.BridgeSettings.setvtwocompatibility(response.data.vtwocompatibility); + if(self.BridgeSettings.veraaddress == "1.1.1.1" || self.BridgeSettings.veraaddress == "") + self.state.showVera = false; + else + self.state.showVera = true; }, function (error) { if (error.data) { @@ -119,6 +124,14 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { ); }; + this.updateShowVera = function () { + if(self.BridgeSettings.veraaddress == "1.1.1.1" || self.BridgeSettings.veraaddress == "") + this.state.showVera = false; + else + this.state.showVera = true; + return; + } + this.viewVeraDevices = function () { this.state.error = ""; if(BridgeSettings.veraaddress == "1.1.1.1" || BridgeSettings.veraaddress == "") @@ -232,9 +245,7 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, $scope.BridgeSettings = bridgeService.BridgeSettings; bridgeService.viewDevices(); $scope.bridge = bridgeService.state; - $scope.showVera = true; - if(BridgeSettings.veraaddress == "1.1.1.1" || BridgeSettings.veraaddress == "") - $scope.showVera = false; + bridgeService.updateShowVera(); $scope.predicate = ''; $scope.reverse = true; $scope.order = function(predicate) { @@ -306,12 +317,10 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer $scope.vera = {base: "", port: "3480", id: ""}; $scope.vera.base = "http://" + BridgeSettings.veraaddress; bridgeService.device = $scope.device; - $scope.showVera = true; - if(BridgeSettings.veraaddress == "1.1.1.1" || BridgeSettings.veraaddress == "") - $scope.showVera = false; bridgeService.viewVeraDevices(); bridgeService.viewVeraScenes(); $scope.bridge = bridgeService.state; + bridgeService.updateShowVera(); $scope.device = bridgeService.state.device; $scope.predicate = ''; $scope.reverse = true; diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index 293d79d..c3a2c3b 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -1,7 +1,7 @@ diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 15aa52a..5e21f74 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -1,7 +1,7 @@ diff --git a/src/main/resources/public/views/editor.html b/src/main/resources/public/views/editor.html index 3be2182..753eff5 100644 --- a/src/main/resources/public/views/editor.html +++ b/src/main/resources/public/views/editor.html @@ -1,7 +1,7 @@