Finished normalizing vera devices and scenes.

Separated device add and editng pages.
This commit is contained in:
Admin
2015-08-17 16:10:38 -05:00
parent b9076d1f2e
commit 8d9357cf9e
9 changed files with 291 additions and 80 deletions

View File

@@ -35,6 +35,7 @@ public class DeviceRepository {
repositoryPath = Paths.get(deviceDb); repositoryPath = Paths.get(deviceDb);
String jsonContent = repositoryReader(repositoryPath); String jsonContent = repositoryReader(repositoryPath);
devices = new HashMap<String, DeviceDescriptor>(); devices = new HashMap<String, DeviceDescriptor>();
if(jsonContent != null) if(jsonContent != null)
{ {
List<DeviceDescriptor> list = readJsonStream(jsonContent); List<DeviceDescriptor> list = readJsonStream(jsonContent);

View File

@@ -1,6 +1,9 @@
package com.bwssystems.vera; package com.bwssystems.vera;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
@@ -10,6 +13,10 @@ import org.apache.http.util.EntityUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.bwssystems.luupRequests.Categorie;
import com.bwssystems.luupRequests.Device;
import com.bwssystems.luupRequests.Room;
import com.bwssystems.luupRequests.Scene;
import com.bwssystems.luupRequests.Sdata; import com.bwssystems.luupRequests.Sdata;
import com.google.gson.Gson; import com.google.gson.Gson;
@@ -33,10 +40,36 @@ public class VeraInfo {
theData = doHttpGETRequest(theUrl); theData = doHttpGETRequest(theUrl);
Sdata theSdata = new Gson().fromJson(theData, Sdata.class); Sdata theSdata = new Gson().fromJson(theData, Sdata.class);
log.debug("GET sdata - full: " + theSdata.getFull() + ", version: " + theSdata.getVersion()); log.debug("GET sdata - full: " + theSdata.getFull() + ", version: " + theSdata.getVersion());
denormalizeSdata(theSdata);
return theSdata; return theSdata;
} }
// This function executes the url against the vera private void denormalizeSdata(Sdata theSdata) {
Map<String,Room> roomMap = new HashMap<String,Room>();
for (Room i : theSdata.getRooms()) roomMap.put(i.getId(),i);
Map<String,Categorie> categoryMap = new HashMap<String,Categorie>();
for (Categorie i : theSdata.getCategoriess()) categoryMap.put(i.getId(),i);
Categorie controllerCat = new Categorie();
controllerCat.setName("Controller");
controllerCat.setId("0");
categoryMap.put(controllerCat.getId(),controllerCat);
ListIterator<Device> theIterator = theSdata.getDevices().listIterator();
Device theDevice = null;
while (theIterator.hasNext()) {
theDevice = theIterator.next();
theDevice.setRoom(roomMap.get(theDevice.getRoom()).getName());
theDevice.setCategory(categoryMap.get(theDevice.getCategory()).getName());
}
ListIterator<Scene> theSecneIter = theSdata.getScenes().listIterator();
Scene theScene = null;
while (theSecneIter.hasNext()) {
theScene = theSecneIter.next();
theScene.setRoom(roomMap.get(theScene.getRoom()).getName());
}
}
// This function executes the url against the vera
protected String doHttpGETRequest(String url) { protected String doHttpGETRequest(String url) {
log.info("calling GET on URL: " + url); log.info("calling GET on URL: " + url);
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);

View File

@@ -41,6 +41,7 @@
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="http://www.bwssystems.com" target="_blank">Developed by BWS Systems</a></li> <li><a href="http://www.bwssystems.com" target="_blank">Developed by BWS Systems</a></li>
<li><a href="http://www.amazon.com/echo" target="_blank">Amazon Echo</a></li> <li><a href="http://www.amazon.com/echo" target="_blank">Amazon Echo</a></li>
<li><a href="#">HA Bridge Version 0.3.0</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@@ -9,6 +9,15 @@ app.config(function ($routeProvider) {
}).when('/editor', { }).when('/editor', {
templateUrl: 'views/editor.html', templateUrl: 'views/editor.html',
controller: 'AddingController' controller: 'AddingController'
}).when('/editdevice', {
templateUrl: 'views/editdevice.html',
controller: 'AddingController'
}).when('/veradevices', {
templateUrl: 'views/veradevice.html',
controller: 'AddingController'
}).when('/verascenes', {
templateUrl: 'views/verascene.html',
controller: 'AddingController'
}).otherwise({ }).otherwise({
templateUrl: 'views/configuration.html', templateUrl: 'views/configuration.html',
controller: 'ViewingController' controller: 'ViewingController'
@@ -16,7 +25,7 @@ app.config(function ($routeProvider) {
}); });
app.run( function (bridgeService) { app.run( function (bridgeService) {
bridgeService.viewBridgeSettings(); bridgeService.loadBridgeSettings();
}); });
app.factory('BridgeSettings', function() { app.factory('BridgeSettings', function() {
@@ -74,7 +83,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
); );
}; };
this.viewBridgeSettings = function () { this.loadBridgeSettings = function () {
this.state.error = ""; this.state.error = "";
return $http.get(this.state.upnpbase).then( return $http.get(this.state.upnpbase).then(
function (response) { function (response) {
@@ -88,7 +97,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
if (error.data) { if (error.data) {
self.state.error = error.data.message; self.state.error = error.data.message;
} else { } else {
self.state.error = "If you're not seeing any address, you may be running into problems with CORS. " + self.state.error = "If you're not seeing any settings, you may be running into problems with CORS. " +
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag."; "You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
} }
console.log(error); console.log(error);
@@ -139,7 +148,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
return $http.put(putUrl, { return $http.put(putUrl, {
id: id, id: id,
name: name, name: name,
deviceType: type, deviceType: "switch",
onUrl: onUrl, onUrl: onUrl,
offUrl: offUrl offUrl: offUrl
}).then( }).then(
@@ -156,7 +165,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
} else { } else {
return $http.post(this.state.base, { return $http.post(this.state.base, {
name: name, name: name,
deviceType: type, deviceType: "switch",
onUrl: onUrl, onUrl: onUrl,
offUrl: offUrl offUrl: offUrl
}).then( }).then(
@@ -210,7 +219,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
}; };
$scope.editDevice = function (device) { $scope.editDevice = function (device) {
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl); bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl);
$location.path('/editor'); $location.path('/editdevice');
}; };
}); });
@@ -225,7 +234,7 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin
$scope.bridge = bridgeService.state; $scope.bridge = bridgeService.state;
$scope.device = bridgeService.state.device; $scope.device = bridgeService.state.device;
$scope.buildUrls = function () { $scope.buildUrlsUsingDevice = function () {
if ($scope.vera.base.indexOf("http") < 0) { if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base; $scope.vera.base = "http://" + $scope.vera.base;
} }
@@ -237,6 +246,18 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin
+ $scope.vera.id; + $scope.vera.id;
}; };
$scope.buildUrlsUsingScene = function () {
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base;
}
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
+ $scope.vera.id;
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
+ $scope.vera.id;
};
$scope.buildDeviceUrls = function (veradevice) { $scope.buildDeviceUrls = function (veradevice) {
if ($scope.vera.base.indexOf("http") < 0) { if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base; $scope.vera.base = "http://" + $scope.vera.base;
@@ -268,11 +289,12 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin
}; };
$scope.addDevice = function () { $scope.addDevice = function () {
bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.type, $scope.device.onUrl, $scope.device.offUrl).then( bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.deviceType, $scope.device.onUrl, $scope.device.offUrl).then(
function () { function () {
$scope.device.id = ""; $scope.device.id = "";
$scope.device.name = ""; $scope.device.name = "";
$scope.device.onUrl = ""; $scope.device.onUrl = "";
$scope.device.deviceType = "switch";
$scope.device.offUrl = ""; $scope.device.offUrl = "";
}, },
function (error) { function (error) {

View File

@@ -1,6 +1,10 @@
<h2>Configuration <a class="btn btn-primary pull-right" href="#/editor"><i <h2>Configuration <a class="btn btn-primary pull-right" href="#/editor"><i
class="icon-plis-sign icon-white"></i> Editor</a> class="icon-plis-sign icon-white"></i> Manual Add</a>
<a class="btn btn-primary pull-right" href="#/verascenes"><i
class="icon-plis-sign icon-white"></i> Vera Scenes</a>
<a class="btn btn-primary pull-right" href="#/veradevices"><i
class="icon-plis-sign icon-white"></i> Vera Devices</a>
</h2> </h2>
<div class="panel panel-default bridgeServer"> <div class="panel panel-default bridgeServer">

View File

@@ -0,0 +1,49 @@
<h2>
Device Editor <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Add a new device</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<form class="form-horizontal" ng-submit="addDevice()">
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-name">Name
</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-name"
ng-model="device.name" placeholder="Device Name">
</div>
<button type="submit" class="col-xs-4 col-sm-2 btn btn-primary">
Update Device</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
URL </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-on-url"
ng-model="device.onUrl" placeholder="URL to turn device on">
</div>
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
ng-click="testUrl(device.onUrl)">Test</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label"
for="device-off-url">Off URL </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-off-url"
ng-model="device.offUrl" placeholder="URL to turn device off">
</div>
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
ng-click="testUrl(device.offUrl)">Test</button>
</div>
</form>
</li>
</ul>
</div>

View File

@@ -1,77 +1,11 @@
<h2> <h2>
Editor <a class="btn btn-primary pull-right" href="/"> Manual Add <a class="btn btn-primary pull-right" href="/">
Configuration</a> Configuration</a>
</h2> </h2>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error"> <div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading"> <div class="panel-heading">
<h2 class="panel-title">Vera Device List</h2> <h2 class="panel-title">Generate a new device/scene/control point</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<p class="text-muted">You can select a Vera device and generate
the add device box selections automatically.</p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Id</th>
<th>Category</th>
<th>Room</th>
<th>Actions</th>
</tr>
</thead>
<tr ng-repeat="veradevice in bridge.veradevices">
<td>{{veradevice.name}}</td>
<td>{{veradevice.id}}</td>
<td>{{veradevice.category}}</td>
<td>{{veradevice.room}}</td>
<td>
<button class="btn btn-success" type="submit"
ng-click="buildDeviceUrls(veradevice)">Generate
Device URLs</button>
</td>
</tr>
</table>
</li>
</ul>
</div>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Vera Scene List</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<p class="text-muted">You can select a Vera scene and generate
the add device box selections automatically.</p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Id</th>
<th>Room</th>
<th>Actions</th>
</tr>
</thead>
<tr ng-repeat="verascene in bridge.verascenes">
<td>{{verascene.name}}</td>
<td>{{verascene.id}}</td>
<td>{{verascene.room}}</td>
<td>
<button class="btn btn-success" type="submit"
ng-click="buildSceneUrls(verascene)">Generate
Device URLs</button>
</td>
</tr>
</table>
</li>
</ul>
</div>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Generate a new device</h2>
</div> </div>
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item"> <li class="list-group-item">
@@ -106,9 +40,12 @@
<input type="text" class="form-control" id="vera-id" <input type="text" class="form-control" id="vera-id"
ng-model="vera.id" placeholder="ID"> ng-model="vera.id" placeholder="ID">
</div> </div>
<button type="submit" ng-click="buildUrls()" <button type="submit" ng-click="buildUrlsUsingDevice()"
class="col-xs-4 col-sm-2 btn btn-success">Generate Device class="col-xs-4 col-sm-2 btn btn-success">Generate Device
URLs</button> URLs</button>
<button type="submit" ng-click="buildUrlsUsingScene()"
class="col-xs-4 col-sm-2 btn btn-success">Generate Scene
URLs</button>
</div> </div>
</form> </form>
</li> </li>
@@ -130,7 +67,7 @@
ng-model="device.name" placeholder="Device Name"> ng-model="device.name" placeholder="Device Name">
</div> </div>
<button type="submit" class="col-xs-4 col-sm-2 btn btn-primary"> <button type="submit" class="col-xs-4 col-sm-2 btn btn-primary">
{{device.id ? 'Update' : 'Add' }} Device</button> Add Device</button>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On <label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On

View File

@@ -0,0 +1,83 @@
<h2>
Vera Device <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Vera Device List</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<p class="text-muted">You can select a Vera device and generate
the add device box selections automatically.</p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Id</th>
<th>Category</th>
<th>Room</th>
<th>Actions</th>
</tr>
</thead>
<tr ng-repeat="veradevice in bridge.veradevices">
<td>{{veradevice.name}}</td>
<td>{{veradevice.id}}</td>
<td>{{veradevice.category}}</td>
<td>{{veradevice.room}}</td>
<td>
<button class="btn btn-success" type="submit"
ng-click="buildDeviceUrls(veradevice)">Generate
Device URLs</button>
</td>
</tr>
</table>
</li>
</ul>
</div>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Add a Vera device</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<form class="form-horizontal" ng-submit="addDevice()">
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-name">Name
</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-name"
ng-model="device.name" placeholder="Device Name">
</div>
<button type="submit" class="col-xs-4 col-sm-2 btn btn-primary">
Add Device</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
URL </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-on-url"
ng-model="device.onUrl" placeholder="URL to turn device on">
</div>
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
ng-click="testUrl(device.onUrl)">Test</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label"
for="device-off-url">Off URL </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-off-url"
ng-model="device.offUrl" placeholder="URL to turn device off">
</div>
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
ng-click="testUrl(device.offUrl)">Test</button>
</div>
</form>
</li>
</ul>
</div>

View File

@@ -0,0 +1,81 @@
<h2>
Vera Scene <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Vera Scene List</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<p class="text-muted">You can select a Vera scene and generate
the add device box selections automatically.</p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Id</th>
<th>Room</th>
<th>Actions</th>
</tr>
</thead>
<tr ng-repeat="verascene in bridge.verascenes">
<td>{{verascene.name}}</td>
<td>{{verascene.id}}</td>
<td>{{verascene.room}}</td>
<td>
<button class="btn btn-success" type="submit"
ng-click="buildSceneUrls(verascene)">Generate
Scene URLs</button>
</td>
</tr>
</table>
</li>
</ul>
</div>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">
<h2 class="panel-title">Add a Vera scene</h2>
</div>
<ul class="list-group">
<li class="list-group-item">
<form class="form-horizontal" ng-submit="addDevice()">
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-name">Name
</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-name"
ng-model="device.name" placeholder="Device Name">
</div>
<button type="submit" class="col-xs-4 col-sm-2 btn btn-primary">
Add Scene</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
URL </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-on-url"
ng-model="device.onUrl" placeholder="URL to turn device on">
</div>
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
ng-click="testUrl(device.onUrl)">Test</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label"
for="device-off-url">Off URL </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-off-url"
ng-model="device.offUrl" placeholder="URL to turn device off">
</div>
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
ng-click="testUrl(device.offUrl)">Test</button>
</div>
</form>
</li>
</ul>
</div>