Skip to content

Commit

Permalink
Updated math to use Math.round to help get better values. Updated code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bwssytems committed Oct 13, 2015
1 parent c5fbd5d commit 7c1d6e4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
Expand Down Expand Up @@ -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.
```
{
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ private void repositoryWriter(String content, Path filePath) {
}

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);
}
Expand All @@ -120,7 +124,7 @@ private String repositoryReader(Path filePath) {

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected String replaceIntensityValue(String request, int intensity){
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);
Expand Down
23 changes: 16 additions & 7 deletions src/main/resources/public/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ app.config(function ($routeProvider) {

app.run( function (bridgeService) {
bridgeService.loadBridgeSettings();
bridgeService.updateShowVera();
});

app.factory('BridgeSettings', function() {
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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) {
Expand All @@ -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 == "")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/public/views/configuration.html
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/public/views/editdevice.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/public/views/editor.html
Original file line number Diff line number Diff line change
@@ -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>

Expand Down

0 comments on commit 7c1d6e4

Please sign in to comment.