From ac59398aa0d5b17f2d4c952279a726221e7da0b9 Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 20 Jan 2016 16:46:21 -0600 Subject: [PATCH] Testing nest functionality --- pom.xml | 2 +- .../bwssystems/HABridge/hue/HueMulator.java | 30 +++++++- .../com/bwssystems/NestBridge/HomeAway.java | 18 ----- .../NestBridge/NestInstruction.java | 33 +++++++++ src/main/resources/public/scripts/app.js | 74 +++++++++++++++++-- .../resources/public/views/editdevice.html | 1 + .../resources/public/views/harmonydevice.html | 9 ++- .../resources/public/views/nestactions.html | 49 ++++++++---- 8 files changed, 170 insertions(+), 46 deletions(-) delete mode 100644 src/main/java/com/bwssystems/NestBridge/HomeAway.java create mode 100644 src/main/java/com/bwssystems/NestBridge/NestInstruction.java diff --git a/pom.xml b/pom.xml index 467016c..dbad96d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 1.2.3e + 1.2.3f jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 96b52a8..af87756 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -7,7 +7,7 @@ import com.bwssystems.HABridge.api.hue.DeviceResponse; import com.bwssystems.HABridge.api.hue.DeviceState; import com.bwssystems.HABridge.api.hue.HueApiResponse; import com.bwssystems.HABridge.dao.*; -import com.bwssystems.NestBridge.HomeAway; +import com.bwssystems.NestBridge.NestInstruction; import com.bwssystems.NestBridge.NestHome; import com.bwssystems.harmony.ButtonPress; import com.bwssystems.harmony.HarmonyHandler; @@ -348,15 +348,36 @@ public class HueMulator { 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); + NestInstruction homeAway = new Gson().fromJson(url, NestInstruction.class); if(theNest == null) { - log.warn("Should not get here, no NEst available"); + log.warn("Should not get here, no Nest available"); responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + ",\"description\": \"Should not get here, no Nest available\", \"parameter\": \"/lights/" + lightId + "state\"}}]"; } else theNest.getHome(homeAway.getName()).setAway(homeAway.getAway()); } + else if(device.getDeviceType().toLowerCase().contains("thermo") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestThermoSet"))) + { + log.debug("executing set thermostat for nest: " + url); + NestInstruction thermoSetting = new Gson().fromJson(url, NestInstruction.class); + if(theNest == null) + { + log.warn("Should not get here, no Nest available"); + responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + ",\"description\": \"Should not get here, no Nest available\", \"parameter\": \"/lights/" + lightId + "state\"}}]"; + } + else { + if(thermoSetting.getControl().equalsIgnoreCase("temp")) { + if(request.body().contains("bri")) { + thermoSetting.setTemp(replaceIntensityValue(thermoSetting.getTemp(), state.getBri())); + theNest.getThermostat(thermoSetting.getName()).setTargetTemperature(Float.parseFloat(thermoSetting.getTemp())); + } + } + else if (!thermoSetting.getControl().equalsIgnoreCase("status")) { + theNest.getThermostat(thermoSetting.getName()).setTargetType(thermoSetting.getControl()); + } + } + } else if(url.startsWith("udp://")) { try { @@ -432,7 +453,8 @@ public class HueMulator { request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, endResult.toString()); } catch (Exception e) { log.warn("Could not execute Math: " + mathDescriptor, e); - } } + } + } return request; } diff --git a/src/main/java/com/bwssystems/NestBridge/HomeAway.java b/src/main/java/com/bwssystems/NestBridge/HomeAway.java deleted file mode 100644 index 32878d9..0000000 --- a/src/main/java/com/bwssystems/NestBridge/HomeAway.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.bwssystems.NestBridge; - -public class HomeAway { - private String name; - private Boolean away; - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public Boolean getAway() { - return away; - } - public void setAway(Boolean away) { - this.away = away; - } -} diff --git a/src/main/java/com/bwssystems/NestBridge/NestInstruction.java b/src/main/java/com/bwssystems/NestBridge/NestInstruction.java new file mode 100644 index 0000000..28fba68 --- /dev/null +++ b/src/main/java/com/bwssystems/NestBridge/NestInstruction.java @@ -0,0 +1,33 @@ +package com.bwssystems.NestBridge; + +public class NestInstruction { + private String name; + private Boolean away; + private String control; + private String temp; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Boolean getAway() { + return away; + } + public void setAway(Boolean away) { + this.away = away; + } + public String getControl() { + return control; + } + public void setControl(String control) { + this.control = control; + } + public String getTemp() { + return temp; + } + public void setTemp(String temp) { + this.temp = temp; + } +} diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index e54a427..3bf95d9 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -292,6 +292,14 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { return false; }; + this.findNestItemByMapId = function(id, type) { + for(var i = 0; i < this.state.devices.length; i++) { + if(this.state.devices[i].mapId == id && this.aContainsB(this.state.devices[i].mapType, type)) + return true; + } + return false; + }; + this.addDevice = function (device) { this.state.error = ""; if(device.httpVerb != null && device.httpVerb != "") @@ -370,7 +378,7 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { this.deleteDeviceByMapId = function (id, type) { for(var i = 0; i < this.state.devices.length; i++) { - if(this.state.devices[i].mapId == id && this.state.devices[i].mapType == type) + if(this.state.devices[i].mapId == id && this.aContainsB(this.state.devices[i].mapType, type)) return self.deleteDevice(this.state.devices[i].id); } }; @@ -575,13 +583,67 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer $scope.device.offUrl = "{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + offbutton + "\"}"; }; - $scope.buildNestHomeUrls = function (nestitem, onbutton, offbutton) { + $scope.buildNestHomeUrls = function (nestitem) { $scope.device.deviceType = "home"; $scope.device.name = nestitem.name; $scope.device.mapType = "nestHomeAway"; $scope.device.mapId = nestitem.Id; - $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"away\":false}"; - $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"away\":true}"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"away\":false,\"control\":\"status\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"away\":true,\"control\":\"status\"}"; + }; + + $scope.buildNestTempUrls = function (nestitem) { + $scope.device.deviceType = "thermo"; + $scope.device.name = nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Temperature"; + $scope.device.mapType = "nestThermoSet"; + $scope.device.mapId = nestitem.Id + "-SetTemp"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; + }; + + $scope.buildNestHeatUrls = function (nestitem) { + $scope.device.deviceType = "thermo"; + $scope.device.name = nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Heat"; + $scope.device.mapType = "nestThermoSet"; + $scope.device.mapId = nestitem.Id + "-SetHeat"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"heat\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"off\"}"; + }; + + $scope.buildNestCoolUrls = function (nestitem) { + $scope.device.deviceType = "thermo"; + $scope.device.name = nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Cool"; + $scope.device.mapType = "nestThermoSet"; + $scope.device.mapId = nestitem.Id + "-SetCool"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"cool\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"off\"}"; + }; + + $scope.buildNestRangeUrls = function (nestitem) { + $scope.device.deviceType = "thermo"; + $scope.device.name = nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Range"; + $scope.device.mapType = "nestThermoSet"; + $scope.device.mapId = nestitem.Id + "-SetRange"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"range\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"off\"}"; + }; + + $scope.buildNestOffUrls = function (nestitem) { + $scope.device.deviceType = "thermo"; + $scope.device.name = nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Thermostat"; + $scope.device.mapType = "nestThermoSet"; + $scope.device.mapId = nestitem.Id + "-TurnOff"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"range\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"off\"}"; + }; + + $scope.buildNestFanUrls = function (nestitem) { + $scope.device.deviceType = "thermo"; + $scope.device.name = nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Fan"; + $scope.device.mapType = "nestThermoSet"; + $scope.device.mapId = nestitem.Id + "-SetFan"; + $scope.device.onUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"fan-on\"}"; + $scope.device.offUrl = "{\"name\":\"" + nestitem.Id + "\",\"control\":\"fan-auto\"}"; }; $scope.testUrl = function (device, type) { @@ -738,7 +800,7 @@ app.filter('availableNestItemId', function(bridgeService) { if(input == null) return out; for (var i = 0; i < input.length; i++) { - if(!bridgeService.findDeviceByMapId(input[i].Id, null, "nestHomeAway")){ + if(!bridgeService.findNestItemByMapId(input[i].Id, "nestHomeAway")){ out.push(input[i]); } } @@ -752,7 +814,7 @@ return function(input) { if(input == null) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.findDeviceByMapId(input[i].Id, null, "nestHomeAway")){ + if(input[i].mapType != null && bridgeService.aContainsB(input[i].mapType, "nest")){ out.push(input[i]); } } diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 1907a22..c34ac09 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -49,6 +49,7 @@ + diff --git a/src/main/resources/public/views/harmonydevice.html b/src/main/resources/public/views/harmonydevice.html index 14ad44e..1609b8b 100644 --- a/src/main/resources/public/views/harmonydevice.html +++ b/src/main/resources/public/views/harmonydevice.html @@ -14,8 +14,9 @@