Add lock id to device, adding download of backups

This commit is contained in:
BWS Systems
2019-06-10 16:35:10 -05:00
parent a05b933e43
commit e86b700e93
8 changed files with 174 additions and 102 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>5.2.next_c</version>
<version>5.2.next_d</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

View File

@@ -86,7 +86,10 @@ public class DeviceDescriptor{
@SerializedName("onWhenDimPresent")
@Expose
private boolean onWhenDimPresent;
@SerializedName("lockDeviceId")
@Expose
private boolean lockDeviceId;
public String getName() {
return name;
}
@@ -333,4 +336,12 @@ public class DeviceDescriptor{
}
return color;
}
public boolean isLockDeviceId() {
return lockDeviceId;
}
public void setLockDeviceId(boolean lockDeviceId) {
this.lockDeviceId = lockDeviceId;
}
}

View File

@@ -143,7 +143,8 @@ public class DeviceRepository extends BackupHandler {
if (light.getOnUrl() != null)
callItems = aGsonBuilder.fromJson(light.getOnUrl(), CallItem[].class);
} catch (JsonSyntaxException e) {
log.warn("Could not decode Json for url items to get Hue state for device: {}", light.getName());
log.warn("Could not decode Json for url items to get Hue state for device: {}",
light.getName());
callItems = null;
}
@@ -201,7 +202,7 @@ public class DeviceRepository extends BackupHandler {
List<DeviceDescriptor> list = new ArrayList<DeviceDescriptor>(devices.values());
Iterator<DeviceDescriptor> deviceIterator = list.iterator();
Map<String, DeviceDescriptor> newdevices = new HashMap<String, DeviceDescriptor>();
;
nextId = seedId;
String hexValue;
Integer newValue;
@@ -209,17 +210,19 @@ public class DeviceRepository extends BackupHandler {
log.debug("Renumber devices with seed: {}", seedId);
while (deviceIterator.hasNext()) {
theDevice = deviceIterator.next();
theDevice.setId(String.valueOf(nextId));
newValue = nextId % 256;
if (newValue <= 0)
newValue = 1;
else if (newValue > 255)
newValue = 255;
hexValue = HexLibrary.encodeUsingBigIntegerToString(newValue.toString());
if (!theDevice.isLockDeviceId()) {
theDevice.setId(String.valueOf(nextId));
newValue = nextId % 256;
if (newValue <= 0)
newValue = 1;
else if (newValue > 255)
newValue = 255;
hexValue = HexLibrary.encodeUsingBigIntegerToString(newValue.toString());
theDevice.setUniqueid("00:17:88:5E:D3:" + hexValue + "-" + hexValue);
theDevice.setUniqueid("00:17:88:5E:D3:" + hexValue + "-" + hexValue);
nextId++;
}
newdevices.put(theDevice.getId(), theDevice);
nextId++;
}
devices = newdevices;
String jsonValue = gson.toJson(findAll());

View File

@@ -385,6 +385,22 @@ public class DeviceResource {
return deviceRepository.getBackups();
}, new JsonTransformer());
// http://ip_address:port/api/devices/backup/download CORS request
options(API_CONTEXT + "/backup/download", "application/json", (request, response) -> {
response.status(HttpStatus.SC_OK);
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.header("Access-Control-Allow-Methods", "PUT");
response.header("Access-Control-Allow-Headers", request.headers("Access-Control-Request-Headers"));
response.header("Content-Type", "text/html; charset=utf-8");
return "";
});
put (API_CONTEXT + "/backup/download", "application/json", (request, response) -> {
log.debug("Create download: {}", request.body());
BackupFilename aFilename = new Gson().fromJson(request.body(), BackupFilename.class);
String backupContent = deviceRepository.downloadBackup(aFilename.getFilename());
return backupContent;
}, new JsonTransformer());
// http://ip_address:port/api/devices/backup/create CORS request
options(API_CONTEXT + "/backup/create", "application/json", (request, response) -> {
response.status(HttpStatus.SC_OK);

View File

@@ -92,4 +92,21 @@ public abstract class BackupHandler {
return theFilenames;
}
public String downloadBackup(String aFilename) {
Path filePath = FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename);
String content = null;
if (Files.notExists(filePath) || !Files.isReadable(filePath)) {
log.warn("Error reading the file: {} - Does not exist or is not readable. continuing...", aFilename);
return null;
}
try {
content = new String(Files.readAllBytes(filePath));
} catch (IOException e) {
log.error("Error reading the file: {} message: {}", aFilename, e.getMessage(), e);
}
return content;
}
}

View File

@@ -1279,6 +1279,22 @@ app.service('bridgeService', function ($rootScope, $http, $base64, $location, ng
);
};
this.downloadBackup = function (afilename) {
return $http.put(this.state.base + "/backup/download", {
filename: afilename
}).then(
function (response) {
self.state.backupContent = response.data;
},
function (error) {
if (error.status === 401)
$rootScope.$broadcast('securityReinit', 'done');
else
self.displayWarn("Download Backup Db File Error:", error);
}
);
};
this.checkForBridge = function () {
return $http.get(this.state.bridgelocation + "/description.xml").then(
function (response) {
@@ -2256,6 +2272,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
bridgeService.viewBackups();
$scope.bridge = bridgeService.state;
$scope.optionalbackupname = "";
$scope.bridge.backupContent = undefined;
$scope.visible = false;
$scope.imgUrl = "glyphicon glyphicon-plus";
$scope.visibleBk = false;
@@ -2320,6 +2337,9 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
$scope.deleteBackup = function (backupname) {
bridgeService.deleteBackup(backupname);
};
$scope.downloadBackup = function (backupname) {
bridgeService.downloadBackup(backupname);
};
$scope.toggle = function () {
$scope.visible = !$scope.visible;
if ($scope.visible)

View File

@@ -1,4 +1,3 @@
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="active"><a href="#!/">Bridge Devices</a></li>
<li role="presentation"><a href="#!/system">Bridge Control</a></li>
@@ -25,94 +24,97 @@
<li ng-if="bridge.showHomeGenie" role="presentation"><a href="#!/homegeniedevices">HomeGenie Devices</a></li>
<li role="presentation"><a href="#!/editdevice">Add/Edit</a></li>
</ul>
<div postrender-action="goToRow()">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Current devices ({{bridge.devices.length}})</h1>
</div>
<div class="panel-body">
<div postrender-action="goToRow()">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Current devices ({{bridge.devices.length}})</h1>
</div>
<div class="panel-body">
<div class="form-group">
<button class="btn btn-primary" type="submit" ng-click="renumberDevices()">Renumber Devices</button>
<button ng-if="bridge.securityInfo.useLinkButton" class="btn btn-primary" type="submit" ng-click="pushLinkButton()">Link</button>
<button ng-if="bridge.securityInfo.useLinkButton" class="btn btn-primary" type="submit"
ng-click="pushLinkButton()">Link</button>
<button class="btn btn-primary" type="submit" ng-click="manageLinksButton()">Manage Links</button>
<label for="device-ip-filter">Show devices visible to: </label>
<input type="text" id="device-ip-filter" style="width:150px"
ng-model="bridge.state.filterDevicesByIpAddress" placeholder="">
<input type="checkbox" id="device-ip-filter-mode" ng-model="bridge.state.filterDevicesOnlyFiltered" ng-true-value=true ng-false-value=false style="margin-right: 3px">Must contain filter
ng-model="bridge.state.filterDevicesByIpAddress" placeholder="">
<input type="checkbox" id="device-ip-filter-mode" ng-model="bridge.state.filterDevicesOnlyFiltered"
ng-true-value=true ng-false-value=false style="margin-right: 3px">Must contain filter
<label for="device-type-filter" style="margin-left:50px">Filter device type: </label>
<select name="device-type" id="device-type-filter"
ng-model="bridge.state.filterDeviceType">
<option value="">---No Filter---</option>
<!-- not selected / blank option -->
<option value="custom">Custom</option>
<option value="UDP">UDP</option>
<option value="TCP">TCP</option>
<option value="exec">Execute Script/Program</option>
<option value="switch">Switch</option>
<option value="scene">Scene</option>
<option value="macro">Macro</option>
<option value="group">Group</option>
<option value="activity">Activity</option>
<option value="button">Button</option>
<option value="thermo">Thermo</option>
<option value="passthru">Pass Thru</option>
</select>
<select name="device-type" id="device-type-filter" ng-model="bridge.state.filterDeviceType">
<option value="">---No Filter---</option>
<!-- not selected / blank option -->
<option value="custom">Custom</option>
<option value="UDP">UDP</option>
<option value="TCP">TCP</option>
<option value="exec">Execute Script/Program</option>
<option value="switch">Switch</option>
<option value="scene">Scene</option>
<option value="macro">Macro</option>
<option value="group">Group</option>
<option value="activity">Activity</option>
<option value="button">Button</option>
<option value="thermo">Thermo</option>
<option value="passthru">Pass Thru</option>
</select>
</div>
<scrollable-table watch="bridge.devices">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Row</th>
<th sortable-header col="id" comparator-fn="comparatorUniqueId">ID</th>
<th sortable-header col="name">Name</th>
<th sortable-header col="description">Description</th>
<th sortable-header col="devicestate">Device State</th>
<th sortable-header col="deviceType">Type</th>
<th sortable-header col="targetDevice">Target</th>
<th sortable-header col="inactive">Inactive</th>
<th sortable-header col="noState">No State</th>
<th>Actions</th>
</tr>
</thead>
<tr ng-repeat="device in bridge.devices | filterDevicesByRequester:bridge.state.filterDevicesByIpAddress:bridge.state.filterDevicesOnlyFiltered:bridge.state.filterDeviceType" row-id="{{device.id}}" ng-class="{info: bridge.viewDevId == device.id}" >
<td>{{$index+1}}</td>
<td>{{device.id}}</td>
<td>{{device.name}}</td>
<td class="cr">{{device.description}}</td>
<td class="cr">on={{device.deviceState.on}},bri={{device.deviceState.bri}},hue={{device.deviceState.hue}},sat={{device.deviceState.sat}},effect={{device.deviceState.effect}},ct={{device.deviceState.ct}},alert={{device.deviceState.alert}},colormode={{device.deviceState.colormode}},reachable={{device.deviceState.reachable}},XYList={{device.deviceState.xy}}</td>
<td>{{device.deviceType}}</td>
<td>{{device.targetDevice}}</td>
<td>{{device.inactive}}</td>
<td>{{device.noState}}</td>
<td>
<p>
<button class="btn btn-info" type="submit"
ng-click="testUrl(device, 'on')">Test ON</button>
<button class="btn btn-info" type="submit"
ng-click="testUrl(device, 'dim')">Test Dim</button>
<button class="btn btn-info" type="submit"
ng-click="testUrl(device, 'off')">Test OFF</button>
<button class="btn btn-info" type="submit"
ng-click="testUrl(device, 'color')">Test Color</button>
<button class="btn btn-warning" type="submit"
ng-click="editDevice(device)">Edit/Copy</button>
<button class="btn btn-danger" type="submit"
ng-click="deleteDevice(device)">Delete</button>
</p>
</td>
</tr>
</table>
</scrollable-table>
<scrollable-table watch="bridge.devices">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Row</th>
<th sortable-header col="id" comparator-fn="comparatorUniqueId">ID</th>
<th sortable-header col="name">Name</th>
<th sortable-header col="description">Description</th>
<th sortable-header col="devicestate">Device State</th>
<th sortable-header col="deviceType">Type</th>
<th sortable-header col="targetDevice">Target</th>
<th sortable-header col="inactive">Inactive</th>
<th sortable-header col="noState">No State</th>
<th>Actions</th>
</tr>
</thead>
<tr ng-repeat="device in bridge.devices | filterDevicesByRequester:bridge.state.filterDevicesByIpAddress:bridge.state.filterDevicesOnlyFiltered:bridge.state.filterDeviceType"
row-id="{{device.id}}" ng-class="{info: bridge.viewDevId == device.id}">
<td>{{$index+1}}</td>
<td>{{device.id}}</td>
<td>{{device.name}}</td>
<td class="cr">{{device.description}}</td>
<td class="cr">
on={{device.deviceState.on}},bri={{device.deviceState.bri}},hue={{device.deviceState.hue}},sat={{device.deviceState.sat}},effect={{device.deviceState.effect}},ct={{device.deviceState.ct}},alert={{device.deviceState.alert}},colormode={{device.deviceState.colormode}},reachable={{device.deviceState.reachable}},XYList={{device.deviceState.xy}}
</td>
<td>{{device.deviceType}}</td>
<td>{{device.targetDevice}}</td>
<td>{{device.inactive}}</td>
<td>{{device.noState}}</td>
<td>
<p>
<button class="btn btn-info" type="submit" ng-click="testUrl(device, 'on')">Test
ON</button>
<button class="btn btn-info" type="submit" ng-click="testUrl(device, 'dim')">Test
Dim</button>
<button class="btn btn-info" type="submit" ng-click="testUrl(device, 'off')">Test
OFF</button>
<button class="btn btn-info" type="submit" ng-click="testUrl(device, 'color')">Test
Color</button>
<button class="btn btn-warning" type="submit"
ng-click="editDevice(device)">Edit/Copy</button>
<button class="btn btn-danger" type="submit"
ng-click="deleteDevice(device)">Delete</button>
</p>
</td>
</tr>
</table>
</scrollable-table>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">
Bridge Device DB Backup <a ng-click="toggleBk()"><span
class={{imgBkUrl}} aria-hidden="true"></span></a>
Bridge Device DB Backup <a ng-click="toggleBk()"><span class={{imgBkUrl}} aria-hidden="true"></span></a>
</h1>
</div>
<div ng-if="visibleBk" class="panel-body">
@@ -123,11 +125,10 @@
File Name</label>
<div class="col-xs-8 col-sm-7">
<input id="backup-name" class="form-control" type="text"
ng-model="optionalbackupname" placeholder="Optional">
<input id="backup-name" class="form-control" type="text" ng-model="optionalbackupname"
placeholder="Optional">
</div>
<button type="submit" class="btn btn-primary"
ng-click="backupDeviceDb(optionalbackupname)">Backup
<button type="submit" class="btn btn-primary" ng-click="backupDeviceDb(optionalbackupname)">Backup
Device DB</button>
</div>
</form>
@@ -139,12 +140,10 @@
</tr>
</thead>
<tr ng-repeat="backup in bridge.backups">
<td>{{backup}}</td>
<td><button type="button" ng-click="downloadBackup(backup)">{{backup}}</button></td>
<td>
<button class="btn btn-danger" type="submit"
ng-click="restoreBackup(backup)">Restore</button>
<button class="btn btn-warning" type="submit"
ng-click="deleteBackup(backup)">Delete</button>
<button class="btn btn-danger" type="submit" ng-click="restoreBackup(backup)">Restore</button>
<button class="btn btn-warning" type="submit" ng-click="deleteBackup(backup)">Delete</button>
</td>
</tr>
</table>
@@ -152,7 +151,7 @@
</div>
<script type="text/ng-template" id="valueDialog">
<div class="ngdialog-message">
<div class="ngdialog-message">
<h2>Select value</h2>
<p>
<input type="radio" ng-model="valueType" value="percentage" ng-change="changeScale()"> Percentage
@@ -167,7 +166,7 @@
</div>
</script>
<script type="text/ng-template" id="colorDialog">
<div class="ngdialog-message">
<div class="ngdialog-message">
<h2>Select Color</h2>
<p>
<input colorpicker="rgb" ng-model="rgbPicker.color" type="text">
@@ -178,7 +177,7 @@
</div>
</script>
<script type="text/ng-template" id="deleteDialog">
<div class="ngdialog-message">
<div class="ngdialog-message">
<h2>Device to Delete?</h2>
<p>{{device.name}}</p>
<p>Are you Sure?</p>
@@ -186,4 +185,4 @@
<div class="ngdialog-buttons mt">
<button type="button" class="ngdialog-button ngdialog-button-error" ng-click="deleteDevice(device)">Delete</button>
</div>
</script>
</script>

View File

@@ -78,6 +78,12 @@
<td><input type="text" class="form-control" id="device-comments"
ng-model="device.comments" placeholder="Device Comments"></td>
</tr>
<tr>
<td><label>Lock Device ID</label></td>
<td><input type="checkbox"
ng-model="device.lockDeviceId" ng-true-value=true
ng-false-value=false> {{device.lockDeviceId}}</td>
</tr>
<tr>
<td><label>Inactive</label></td>
<td><input type="checkbox"