Updated math to use Math.round to help get better values. Updated code

for determining if Vera is available so as to not show those screens.
Updated file handling as there were issues due to no checks for file
handling, this will improve for windows.
This commit is contained in:
Admin
2015-10-13 16:30:45 -05:00
parent c5fbd5d1f0
commit 7c1d6e40b8
7 changed files with 33 additions and 20 deletions

View File

@@ -15,7 +15,7 @@ java -jar -Dvera.address=X.Y.Z.A ha-bridge-0.X.Y.jar
### -Dvera.address=`<ip 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=`<ip address>`
The server defaults to the first available address on the host. Replace the -Dupnp.config.address=`<ip 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=`<ip 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=`<port>`
The server defaults to running on port 8080. If you're already running a server (like openHAB) on 8080, -Dserver.port=`<port>` on the command line.
### -Dupnp.device.db=`<filepath>`
@@ -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(<your expression using "X" as the value to operate on>)} 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(<your expression using "X" as the value to operate on>)} i.e. "{$intensity.math(X/4)}".
e.g.
```
{

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -1,7 +1,7 @@
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="active"><a href="#">Configuration</a></li>
<li ng-if="showVera" role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li ng-if="showVera" role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li ng-if="bridge.showVera" role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li ng-if="bridge.showVera" role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation"><a href="#/editor">Manual Add</a></li>
</ul>

View File

@@ -1,7 +1,7 @@
<ul class="nav nav-pills" role="tablist">
<li role="presentation"><a href="#">Configuration</a></li>
<li ng-if="showVera" role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li ng-if="showVera" role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li ng-if="bridge.showVera" role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li ng-if="bridge.showVera" role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation"><a href="#/editor">Manual Add</a></li>
<li role="presentation" class="active"><a href="#/editdevice">Edit Device</a></li>
</ul>

View File

@@ -1,7 +1,7 @@
<ul class="nav nav-pills" role="tablist">
<li role="presentation"><a href="#">Configuration</a></li>
<li ng-if="showVera" role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li ng-if="showVera" role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li ng-if="bridge.showVera" role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li ng-if="bridge.showVera" role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation" class="active"><a href="#/editor">Manual Add</a></li>
</ul>