From c28f07d6283af37024408fb0145e105735b51def Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 11 Jan 2016 16:45:02 -0600 Subject: [PATCH] Continuation of nest implementation. --- pom.xml | 11 +- .../bwssystems/HABridge/BridgeSettings.java | 7 + .../devicemanagmeent/DeviceResource.java | 16 +-- .../bwssystems/HABridge/hue/HueMulator.java | 2 +- .../HABridge/upnp/UpnpSettingsResource.java | 1 + .../com/bwssystems/NestBridge/NestHome.java | 70 ++++++++-- src/main/resources/public/scripts/app.js | 42 +++++- .../resources/public/views/configuration.html | 5 + .../resources/public/views/editdevice.html | 1 + src/main/resources/public/views/editor.html | 1 + .../public/views/harmonyactivity.html | 1 + .../resources/public/views/harmonydevice.html | 1 + .../resources/public/views/nestactions.html | 128 ++++++++++++++++++ .../resources/public/views/veradevice.html | 1 + .../resources/public/views/verascene.html | 1 + 15 files changed, 260 insertions(+), 28 deletions(-) create mode 100644 src/main/resources/public/views/nestactions.html diff --git a/pom.xml b/pom.xml index 6d377e4..cbc19a5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 1.2.3b + 1.2.3c jar HA Bridge @@ -33,7 +33,7 @@ com.github.bwssytems nest-controller - 1.0.0 + 1.0.1 com.sparkjava @@ -43,8 +43,13 @@ org.apache.httpcomponents httpclient - 4.3.6 + 4.5.1 + + org.apache.httpcomponents + httpcore + 4.4.4 + org.slf4j slf4j-simple diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java index b82a9fa..7ee6b46 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java @@ -17,6 +17,7 @@ public class BridgeSettings { private boolean devmode; private String nestuser; private String nestpwd; + private boolean nestconfigured; public String getUpnpConfigAddress() { return upnpconfigaddress; @@ -102,6 +103,12 @@ public class BridgeSettings { public void setNestpwd(String nestpwd) { this.nestpwd = nestpwd; } + public boolean isNestConfigured() { + return nestconfigured; + } + public void setNestConfigured(boolean isNestConfigured) { + this.nestconfigured = isNestConfigured; + } public Boolean isValidVera() { if(this.veraaddress.contains(Configuration.DEFAULT_VERA_ADDRESS)) return false; diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index 2f05ebe..7e53de6 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -225,24 +225,14 @@ public class DeviceResource { return myHarmonyHome.getDevices(); }, new JsonTransformer()); - get (API_CONTEXT + "/nest/homes", "application/json", (request, response) -> { - log.debug("Get nest homes"); + get (API_CONTEXT + "/nest/items", "application/json", (request, response) -> { + log.debug("Get nest items"); if(nestHome == null) { response.status(HttpStatus.SC_NOT_FOUND); return null; } response.status(HttpStatus.SC_OK); - return nestHome.getHomeNames(); - }, new JsonTransformer()); - - get (API_CONTEXT + "/nest/thermostats", "application/json", (request, response) -> { - log.debug("Get nest thermostats"); - if(nestHome == null) { - response.status(HttpStatus.SC_NOT_FOUND); - return null; - } - response.status(HttpStatus.SC_OK); - return nestHome.getThermostatNames(); + return nestHome.getItems(); }, new JsonTransformer()); } } \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 2fa5ef3..96b52a8 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -345,7 +345,7 @@ public class HueMulator { else myHarmony.pressButton(aDeviceButton); } - else if(device.getDeviceType().toLowerCase().contains("home") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestHome"))) + else if(device.getDeviceType().toLowerCase().contains("home") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestHomeAway"))) { log.debug("executing set away for nest home: " + url); HomeAway homeAway = new Gson().fromJson(url, HomeAway.class); diff --git a/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java b/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java index 5a4d669..944e085 100644 --- a/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java +++ b/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java @@ -53,6 +53,7 @@ public class UpnpSettingsResource { this.theSettings.setUpnpResponsePort(theBridgeSettings.getUpnpResponsePort()); this.theSettings.setUpnpStrict(theBridgeSettings.isUpnpStrict()); this.theSettings.setVeraAddress(theBridgeSettings.getVeraAddress()); + this.theSettings.setNestConfigured(theBridgeSettings.isValidNest()); } public void setupServer() { diff --git a/src/main/java/com/bwssystems/NestBridge/NestHome.java b/src/main/java/com/bwssystems/NestBridge/NestHome.java index 914702f..10bb6bd 100644 --- a/src/main/java/com/bwssystems/NestBridge/NestHome.java +++ b/src/main/java/com/bwssystems/NestBridge/NestHome.java @@ -2,26 +2,36 @@ package com.bwssystems.NestBridge; import java.util.ArrayList; import java.util.List; +import java.util.ListIterator; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.bwssystems.HABridge.BridgeSettings; +import com.bwssystems.nest.controller.Home; import com.bwssystems.nest.controller.Nest; import com.bwssystems.nest.controller.NestSession; +import com.bwssystems.nest.controller.Thermostat; import com.bwssystems.nest.protocol.error.LoginException; +import com.bwssystems.nest.protocol.status.WhereDetail; +import com.bwssystems.nest.protocol.status.WhereItem; public class NestHome { private static final Logger log = LoggerFactory.getLogger(NestHome.class); private NestSession theSession; private Nest theNest; + private ArrayList nestItems; public NestHome(BridgeSettings bridgeSettings) { theSession = null; theNest = null; + nestItems = null; - if(bridgeSettings.isValidNest()) + if(!bridgeSettings.isValidNest()) { + log.info("not a valid nest"); return; + } try { theSession = new NestSession(bridgeSettings.getNestuser(), bridgeSettings.getNestpwd()); @@ -32,18 +42,58 @@ public class NestHome { } } - public List getHomeNames() { + public List getItems() { if(theNest == null) return null; - return new ArrayList(theNest.getHomeNames()); /* list of home structures i.e. MyHouse */ + + if(nestItems == null) { + nestItems = new ArrayList(); + Set homeNames = theNest.getHomeNames(); + Home aHome = null; + NestItem anItem = null; + for(String name : homeNames) { + aHome = theNest.getHome(name); + anItem = new NestItem(); + anItem.setId(name); + anItem.setName(aHome.getDetail().getName()); + anItem.setType("Home"); + anItem.setLocation(aHome.getDetail().getLocation()); + nestItems.add(anItem); + } + Thermostat thermo = null; + Set thermoNames = theNest.getThermostatNames(); + for(String name : thermoNames) { + thermo = theNest.getThermostat(name); + anItem = new NestItem(); + anItem.setId(name); + anItem.setType("Thermostat"); + String where = null; + String homeName= null; + Boolean found = false; + for(String aHomeName : homeNames) { + WhereDetail aDetail = theNest.getWhere(aHomeName); + ListIterator anIterator = aDetail.getWheres().listIterator(); + while(anIterator.hasNext()) { + WhereItem aWhereItem = (WhereItem) anIterator.next(); + if(aWhereItem.getWhereId().equals(thermo.getDeviceDetail().getWhereId())) { + where = aWhereItem.getName(); + homeName = theNest.getHome(aHomeName).getDetail().getName(); + found = true; + break; + } + } + if(found) + break; + } + anItem.setName(where + "(" + name.substring(name.length() - 4) + ")"); + anItem.setLocation(where + " - " + homeName); + nestItems.add(anItem); + } + } + + return nestItems; } - - public List getThermostatNames() { - if(theNest == null) - return null; - return new ArrayList(theNest.getThermostatNames()); /* list of thermostats in all structure */ - } - + public Nest getTheNest() { return theNest; } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index ee5b1e2..7721dff 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -24,6 +24,9 @@ app.config(function ($routeProvider) { }).when('/harmonyactivities', { templateUrl: 'views/harmonyactivity.html', controller: 'AddingController' + }).when('/nest', { + templateUrl: 'views/nestactions.html', + controller: 'AddingController' }).otherwise({ templateUrl: 'views/configuration.html', controller: 'ViewingController' @@ -34,6 +37,7 @@ app.run( function (bridgeService) { bridgeService.loadBridgeSettings(); bridgeService.updateShowVera(); bridgeService.updateShowHarmony(); + bridgeService.updateShowNest(); bridgeService.getHABridgeVersion(); }); @@ -49,6 +53,7 @@ app.factory('BridgeSettings', function() { BridgeSettings.upnpstrict = ""; BridgeSettings.traceupnp = ""; BridgeSettings.devmode = ""; + BridgeSettings.nestconfigured = ""; BridgeSettings.setupnpconfigaddress = function(aconfigaddress){ BridgeSettings.upnpconfigaddress = aconfigaddress; @@ -82,13 +87,17 @@ app.factory('BridgeSettings', function() { BridgeSettings.devmode = adevmode; }; + BridgeSettings.setnestconfigured = function(anestconfigured){ + BridgeSettings.nestconfigured = anestconfigured; + }; + return BridgeSettings; }); 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", huebase: window.location.origin + "/api", devices: [], device: [], error: "", showVera: false, showHarmony: false, habridgeversion: ""}; + this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", huebase: window.location.origin + "/api", devices: [], device: [], error: "", showVera: false, showHarmony: false, showNest: false, habridgeversion: ""}; this.viewDevices = function () { this.state.error = ""; @@ -136,6 +145,14 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { return; } + this.updateShowNest = function () { + if(self.BridgeSettings.nestconfigured == true) + this.state.showNest = true; + else + this.state.showNest = false; + return; + } + this.updateShowHarmony = function () { if(self.BridgeSettings.harmonyaddress.devices) { if(this.aContainsB(self.BridgeSettings.harmonyaddress.devices[0].ip, "1.1.1.1") || self.BridgeSettings.harmonyaddress == "" || self.BridgeSettings.harmonyaddress == null) @@ -162,6 +179,7 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { self.BridgeSettings.settraceupnp(response.data.traceupnp); self.BridgeSettings.setupnpstrict(response.data.upnpstrict); self.BridgeSettings.setdevmode(response.data.devmode); + self.BridgeSettings.setnestconfigured(response.data.nestconfigured); }, function (error) { if (error.data) { @@ -174,6 +192,25 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { ); }; + this.viewNestItems = function () { + this.state.error = ""; + if(!this.state.showNest) + return; + this.state.error = ""; + return $http.get(this.state.base + "/nest/items").then( + function (response) { + self.state.nestitems = response.data; + }, + function (error) { + if (error.data) { + $window.alert("Get Nest Items Error: " + error.data.message); + } else { + $window.alert("Get Nest Items Error: unknown"); + } + } + ); + }; + this.viewVeraDevices = function () { this.state.error = ""; if(!this.state.showVera) @@ -375,6 +412,7 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, $scope.bridge = bridgeService.state; bridgeService.updateShowVera(); bridgeService.updateShowHarmony(); + bridgeService.updateShowNest(); $scope.visible = false; $scope.imgUrl = "glyphicon glyphicon-plus"; $scope.predicate = ''; @@ -419,9 +457,11 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer bridgeService.viewVeraScenes(); bridgeService.viewHarmonyActivities(); bridgeService.viewHarmonyDevices(); + bridgeService.viewNestItems(); $scope.bridge = bridgeService.state; bridgeService.updateShowVera(); bridgeService.updateShowHarmony(); + bridgeService.updateShowNest(); $scope.device = bridgeService.state.device; $scope.activitiesVisible = false; $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index 5249158..aaac8dc 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -4,6 +4,7 @@
  • Vera Scenes
  • Harmony Activities
  • Harmony Devices
  • +
  • Nest
  • Manual Add
  • @@ -126,6 +127,10 @@ dev.mode {{BridgeSettings.devmode}} + + nest.configured + {{BridgeSettings.nestconfigured}} + diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 2cf0e47..14c7508 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -4,6 +4,7 @@
  • Vera Scenes
  • Harmony Activities
  • Harmony Devices
  • +
  • Nest
  • Manual Add
  • diff --git a/src/main/resources/public/views/editor.html b/src/main/resources/public/views/editor.html index 73924a6..8a67eb4 100644 --- a/src/main/resources/public/views/editor.html +++ b/src/main/resources/public/views/editor.html @@ -4,6 +4,7 @@
  • Vera Scenes
  • Harmony Activities
  • Harmony Devices
  • +
  • Nest
  • diff --git a/src/main/resources/public/views/harmonyactivity.html b/src/main/resources/public/views/harmonyactivity.html index b228873..feacfe8 100644 --- a/src/main/resources/public/views/harmonyactivity.html +++ b/src/main/resources/public/views/harmonyactivity.html @@ -4,6 +4,7 @@
  • Vera Scenes
  • Harmony Devices
  • +
  • Nest
  • Manual Add
  • diff --git a/src/main/resources/public/views/harmonydevice.html b/src/main/resources/public/views/harmonydevice.html index 3bb58f3..14ad44e 100644 --- a/src/main/resources/public/views/harmonydevice.html +++ b/src/main/resources/public/views/harmonydevice.html @@ -4,6 +4,7 @@
  • Vera Scenes
  • Harmony Activities
  • +
  • Nest
  • Manual Add
  • diff --git a/src/main/resources/public/views/nestactions.html b/src/main/resources/public/views/nestactions.html new file mode 100644 index 0000000..ccdff34 --- /dev/null +++ b/src/main/resources/public/views/nestactions.html @@ -0,0 +1,128 @@ + + +
    +
    +

    Nest Items List

    +
    +
      +
    • +

      You can select a Nest item and generate + the add activity box selections automatically.

      + + + + + + + + + + + + + + + + +
      + Name + + + Type + + + Location + + Actions
      {{nestitem.name}}{{nestitem.type}}{{nestitem.location}} + +
      +
    • +
    +
    +

    Already Configured Activities

    +
    +
      +
    • + + + + + + + + + + + + + + + +
      + Name + + + Id + + + Hub + + Actions
      {{nestitem.name}}{{nestitem.type}}{{nestitem.location}}
      +
    • +
    +
    +
    +
    +

    Add a Harmony Activity

    +
    +
      +
    • +
      +
      + + +
      + +
      + +
      +
      +
      + + +
      + +
      +
      +
      +
      +
      + + +
      + +
      +
      +
      +
      +
    • +
    +
    diff --git a/src/main/resources/public/views/veradevice.html b/src/main/resources/public/views/veradevice.html index c1b8911..ce25838 100644 --- a/src/main/resources/public/views/veradevice.html +++ b/src/main/resources/public/views/veradevice.html @@ -4,6 +4,7 @@
  • Vera Scenes
  • Harmony Activities
  • Harmony Devices
  • +
  • Nest
  • Manual Add
  • diff --git a/src/main/resources/public/views/verascene.html b/src/main/resources/public/views/verascene.html index 7b6926e..36b515e 100644 --- a/src/main/resources/public/views/verascene.html +++ b/src/main/resources/public/views/verascene.html @@ -4,6 +4,7 @@
  • Harmony Activities
  • Harmony Devices
  • +
  • Nest
  • Manual Add