From 8d9357cf9ef6f8b0e3b1a2d561ac069fd9bac400 Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 17 Aug 2015 16:10:38 -0500 Subject: [PATCH] Finished normalizing vera devices and scenes. Separated device add and editng pages. --- .../HABridge/dao/DeviceRepository.java | 1 + .../java/com/bwssystems/vera/VeraInfo.java | 35 +++++++- src/main/resources/public/index.html | 1 + src/main/resources/public/scripts/app.js | 38 +++++++-- .../resources/public/views/configuration.html | 6 +- .../resources/public/views/editdevice.html | 49 +++++++++++ src/main/resources/public/views/editor.html | 77 ++--------------- .../resources/public/views/veradevice.html | 83 +++++++++++++++++++ .../resources/public/views/verascene.html | 81 ++++++++++++++++++ 9 files changed, 291 insertions(+), 80 deletions(-) create mode 100644 src/main/resources/public/views/editdevice.html create mode 100644 src/main/resources/public/views/veradevice.html create mode 100644 src/main/resources/public/views/verascene.html diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java index 7e00eac..67c954c 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java @@ -35,6 +35,7 @@ public class DeviceRepository { repositoryPath = Paths.get(deviceDb); String jsonContent = repositoryReader(repositoryPath); devices = new HashMap(); + if(jsonContent != null) { List list = readJsonStream(jsonContent); diff --git a/src/main/java/com/bwssystems/vera/VeraInfo.java b/src/main/java/com/bwssystems/vera/VeraInfo.java index f96db8f..b11c56f 100644 --- a/src/main/java/com/bwssystems/vera/VeraInfo.java +++ b/src/main/java/com/bwssystems/vera/VeraInfo.java @@ -1,6 +1,9 @@ package com.bwssystems.vera; 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.client.HttpClient; @@ -10,6 +13,10 @@ import org.apache.http.util.EntityUtils; import org.slf4j.Logger; 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.google.gson.Gson; @@ -33,10 +40,36 @@ public class VeraInfo { theData = doHttpGETRequest(theUrl); Sdata theSdata = new Gson().fromJson(theData, Sdata.class); log.debug("GET sdata - full: " + theSdata.getFull() + ", version: " + theSdata.getVersion()); + denormalizeSdata(theSdata); return theSdata; } -// This function executes the url against the vera + private void denormalizeSdata(Sdata theSdata) { + Map roomMap = new HashMap(); + for (Room i : theSdata.getRooms()) roomMap.put(i.getId(),i); + Map categoryMap = new HashMap(); + 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 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 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) { log.info("calling GET on URL: " + url); HttpGet httpGet = new HttpGet(url); diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index b9cf15a..e0aaf49 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -41,6 +41,7 @@ diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index d80ed93..0453452 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -9,6 +9,15 @@ app.config(function ($routeProvider) { }).when('/editor', { templateUrl: 'views/editor.html', 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({ templateUrl: 'views/configuration.html', controller: 'ViewingController' @@ -16,7 +25,7 @@ app.config(function ($routeProvider) { }); app.run( function (bridgeService) { - bridgeService.viewBridgeSettings(); + bridgeService.loadBridgeSettings(); }); app.factory('BridgeSettings', function() { @@ -74,7 +83,7 @@ app.service('bridgeService', function ($http, BridgeSettings) { ); }; - this.viewBridgeSettings = function () { + this.loadBridgeSettings = function () { this.state.error = ""; return $http.get(this.state.upnpbase).then( function (response) { @@ -88,7 +97,7 @@ app.service('bridgeService', function ($http, BridgeSettings) { if (error.data) { self.state.error = error.data.message; } 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."; } console.log(error); @@ -139,7 +148,7 @@ app.service('bridgeService', function ($http, BridgeSettings) { return $http.put(putUrl, { id: id, name: name, - deviceType: type, + deviceType: "switch", onUrl: onUrl, offUrl: offUrl }).then( @@ -156,7 +165,7 @@ app.service('bridgeService', function ($http, BridgeSettings) { } else { return $http.post(this.state.base, { name: name, - deviceType: type, + deviceType: "switch", onUrl: onUrl, offUrl: offUrl }).then( @@ -210,7 +219,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, }; $scope.editDevice = function (device) { 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.device = bridgeService.state.device; - $scope.buildUrls = function () { + $scope.buildUrlsUsingDevice = function () { if ($scope.vera.base.indexOf("http") < 0) { $scope.vera.base = "http://" + $scope.vera.base; } @@ -237,6 +246,18 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin + $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) { if ($scope.vera.base.indexOf("http") < 0) { $scope.vera.base = "http://" + $scope.vera.base; @@ -268,11 +289,12 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin }; $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 () { $scope.device.id = ""; $scope.device.name = ""; $scope.device.onUrl = ""; + $scope.device.deviceType = "switch"; $scope.device.offUrl = ""; }, function (error) { diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index 87a7d94..2011316 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -1,6 +1,10 @@

Configuration Editor + class="icon-plis-sign icon-white"> Manual Add + Vera Scenes + Vera Devices

diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html new file mode 100644 index 0000000..a2b648d --- /dev/null +++ b/src/main/resources/public/views/editdevice.html @@ -0,0 +1,49 @@ +

+ Device Editor + Configuration +

+ +
+
+

Add a new device

+
+
    +
  • +
    +
    + + +
    + +
    + +
    +
    + + +
    + +
    + +
    +
    + + +
    + +
    + +
    +
    +
  • +
+
diff --git a/src/main/resources/public/views/editor.html b/src/main/resources/public/views/editor.html index 1d0f0cd..b5990db 100644 --- a/src/main/resources/public/views/editor.html +++ b/src/main/resources/public/views/editor.html @@ -1,77 +1,11 @@

- Editor + Manual Add Configuration

-

Vera Device List

-
-
    -
  • -

    You can select a Vera device and generate - the add device box selections automatically.

    - - - - - - - - - - - - - - - - - - -
    NameIdCategoryRoomActions
    {{veradevice.name}}{{veradevice.id}}{{veradevice.category}}{{veradevice.room}} - -
    -
  • -
-
-
-
-

Vera Scene List

-
-
    -
  • -

    You can select a Vera scene and generate - the add device box selections automatically.

    - - - - - - - - - - - - - - - - -
    NameIdRoomActions
    {{verascene.name}}{{verascene.id}}{{verascene.room}} - -
    -
  • -
-
-
-
-

Generate a new device

+

Generate a new device/scene/control point

  • @@ -106,9 +40,12 @@
- +
@@ -130,7 +67,7 @@ ng-model="device.name" placeholder="Device Name"> + Add Device