diff --git a/pom.xml b/pom.xml index 84a0129..2394d4a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 1.0.1 + 1.0.2 jar HA Bridge @@ -28,7 +28,7 @@ com.github.bwssytems harmony-java-client - 1.0.5 + 1.0.8 com.sparkjava @@ -55,11 +55,6 @@ gson 2.2.4 - - com.fasterxml.jackson.core - jackson-databind - 2.6.0 - com.fasterxml.jackson.core jackson-databind @@ -85,6 +80,11 @@ smack-core 4.0.7 + + org.igniterealtime.smack + smack-debug + 4.0.7 + diff --git a/src/main/java/com/bwssystems/HABridge/HABridge.java b/src/main/java/com/bwssystems/HABridge/HABridge.java index d83be88..531e7d1 100644 --- a/src/main/java/com/bwssystems/HABridge/HABridge.java +++ b/src/main/java/com/bwssystems/HABridge/HABridge.java @@ -42,7 +42,7 @@ public class HABridge { String addressString; BridgeSettings bridgeSettings; - log.info("HA Bridge (v1.0.1) starting setup...."); + log.info("HA Bridge (v1.0.2) starting setup...."); //get ip address for upnp requests try { address = InetAddress.getLocalHost(); diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index 4364ccd..bf268b1 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -155,10 +155,32 @@ public class DeviceResource { get (API_CONTEXT + "/harmony/activities", "application/json", (request, response) -> { log.debug("Get harmony activities"); + if(myHarmonyHandler == null) { + response.status(HttpStatus.SC_NOT_FOUND); + return null; + } response.status(HttpStatus.SC_OK); - if(myHarmonyHandler != null) - return myHarmonyHandler.getActivities(); - return ""; + return myHarmonyHandler.getActivities(); + }, new JsonTransformer()); + + get (API_CONTEXT + "/harmony/show", "application/json", (request, response) -> { + log.debug("Get harmony current activity"); + if(myHarmonyHandler == null) { + response.status(HttpStatus.SC_NOT_FOUND); + return null; + } + response.status(HttpStatus.SC_OK); + return myHarmonyHandler.getCurrentActivity(); + }, new JsonTransformer()); + + get (API_CONTEXT + "/harmony/devices", "application/json", (request, response) -> { + log.debug("Get harmony devices"); + if(myHarmonyHandler == null) { + response.status(HttpStatus.SC_NOT_FOUND); + return null; + } + response.status(HttpStatus.SC_OK); + return myHarmonyHandler.getDevices(); }, new JsonTransformer()); } diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 225d185..4436288 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -6,7 +6,9 @@ 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.harmony.ButtonPress; import com.bwssystems.harmony.HarmonyHandler; +import com.bwssystems.harmony.RunActivity; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; @@ -215,7 +217,14 @@ public class HueMulator { if(device.getDeviceType().contains("activity")) { log.debug("executing activity to Harmony: " + url); - myHarmony.startActivity(url); + RunActivity anActivity = new Gson().fromJson(url, RunActivity.class); + myHarmony.startActivity(anActivity); + } + else if(device.getDeviceType().contains("button")) + { + log.debug("executing button press to Harmony: " + url); + ButtonPress aDeviceButton = new Gson().fromJson(url, ButtonPress.class); + myHarmony.pressButton(aDeviceButton); } else { diff --git a/src/main/java/com/bwssystems/harmony/ButtonPress.java b/src/main/java/com/bwssystems/harmony/ButtonPress.java new file mode 100644 index 0000000..023352f --- /dev/null +++ b/src/main/java/com/bwssystems/harmony/ButtonPress.java @@ -0,0 +1,25 @@ +package com.bwssystems.harmony; + +public class ButtonPress { + private String device; + private String button; + public String getDevice() { + return device; + } + public void setDevice(String device) { + this.device = device; + } + public String getButton() { + return button; + } + public void setButton(String button) { + this.button = button; + } + public Boolean isValid() { + if (device != null && !device.isEmpty()){ + if (button != null && !button.isEmpty()) + return true; + } + return false; + } +} diff --git a/src/main/java/com/bwssystems/harmony/HarmonyHandler.java b/src/main/java/com/bwssystems/harmony/HarmonyHandler.java index 7cbd09f..338f517 100644 --- a/src/main/java/com/bwssystems/harmony/HarmonyHandler.java +++ b/src/main/java/com/bwssystems/harmony/HarmonyHandler.java @@ -41,46 +41,50 @@ public class HarmonyHandler { return harmonyClient.getCurrentActivity(); } - public Boolean startActivity(String anActivity) { - log.debug("Harmony api start activity requested for: " + anActivity + " noop mode: " + noopCalls); - if (anActivity != null && !anActivity.isEmpty()) { + public Boolean startActivity(RunActivity anActivity) { + log.debug("Harmony api start activity requested for: " + anActivity.getName() + " noop mode: " + noopCalls); + if (anActivity.isValid()) { try { if (!noopCalls) - harmonyClient.startActivity(Integer.parseInt(anActivity)); + harmonyClient.startActivity(Integer.parseInt(anActivity.getName())); + else + log.info("noop mode: Harmony api start activity requested for: " + anActivity.getName()); } catch (IllegalArgumentException e) { try { if (!noopCalls) - harmonyClient.startActivityByName(anActivity); + harmonyClient.startActivityByName(anActivity.getName()); } catch (IllegalArgumentException ei) { - log.error("Error in finding activity: " + anActivity); + log.error("Error in finding activity: " + anActivity.getName()); return false; } } } else { - log.error("Error in finding activity: " + anActivity); + log.error("Error in finding activity: " + anActivity.getName()); return false; } return true; } - public Boolean pressButton(String aDevice, String aDeviceButton) { - log.debug("Harmony api press a button requested for device: " + aDevice + " and a for button: " + aDeviceButton + " noop mode: " + noopCalls); - if (aDeviceButton != null && !aDeviceButton.isEmpty()) { + public Boolean pressButton(ButtonPress aDeviceButton) { + log.debug("Harmony api press a button requested for device: " + aDeviceButton.getDevice() + " and a for button: " + aDeviceButton.getButton() + " noop mode: " + noopCalls); + if (aDeviceButton.isValid()) { try { if (!noopCalls) - harmonyClient.pressButton(Integer.parseInt(aDevice), aDeviceButton); + harmonyClient.pressButton(Integer.parseInt(aDeviceButton.getDevice()), aDeviceButton.getButton()); + else + log.info("noop mode: Harmony api press a button requested for device: " + aDeviceButton.getDevice() + " and a for button: " + aDeviceButton.getButton()); } catch (IllegalArgumentException e) { try { if (!noopCalls) - harmonyClient.pressButton(aDevice, aDeviceButton); + harmonyClient.pressButton(aDeviceButton.getDevice(), aDeviceButton.getButton()); } catch (IllegalArgumentException ei) { - log.error("Error in finding device: " + aDevice +" and a button: " + aDeviceButton); + log.error("Error in finding device: " + aDeviceButton.getDevice() +" and a button: " + aDeviceButton.getButton()); return false; } } } else { - log.error("Error in finding device: " + aDevice +" and a button: " + aDeviceButton); + log.error("Error in finding device: " + aDeviceButton.getDevice() +" and a button: " + aDeviceButton.getButton()); return false; } diff --git a/src/main/java/com/bwssystems/harmony/HarmonyServer.java b/src/main/java/com/bwssystems/harmony/HarmonyServer.java index 8b376ba..51860a1 100644 --- a/src/main/java/com/bwssystems/harmony/HarmonyServer.java +++ b/src/main/java/com/bwssystems/harmony/HarmonyServer.java @@ -42,7 +42,7 @@ public class HarmonyServer { } private void execute(BridgeSettings mySettings) throws Exception { - log.debug("setup initiated...."); + log.info("setup initiated...."); harmonyClient.addListener(new ActivityChangeListener() { @Override public void activityStarted(Activity activity) { diff --git a/src/main/java/com/bwssystems/harmony/RunActivity.java b/src/main/java/com/bwssystems/harmony/RunActivity.java new file mode 100644 index 0000000..e39afc9 --- /dev/null +++ b/src/main/java/com/bwssystems/harmony/RunActivity.java @@ -0,0 +1,18 @@ +package com.bwssystems.harmony; + +public class RunActivity { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public Boolean isValid() { + if (name != null && !name.isEmpty()) + return true; + return false; + } +} diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index b2de77c..144ed15 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -36,7 +36,7 @@ diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index f8c9518..ff4c2a4 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -21,6 +21,9 @@ app.config(function ($routeProvider) { }).when('/verascenes', { templateUrl: 'views/verascene.html', controller: 'AddingController' + }).when('/harmonydevices', { + templateUrl: 'views/harmonydevice.html', + controller: 'AddingController' }).when('/harmonyactivities', { templateUrl: 'views/harmonyactivity.html', controller: 'AddingController' @@ -86,7 +89,7 @@ app.factory('BridgeSettings', function() { 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", devices: [], device: [], error: "", showVera: false, showHarmony: false}; + 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}; this.viewDevices = function () { this.state.error = ""; @@ -210,6 +213,24 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { ); }; + this.viewHarmonyDevices = function () { + this.state.error = ""; + if(!this.state.showHarmony) + return; + return $http.get(this.state.base + "/harmony/devices").then( + function (response) { + self.state.harmonydevices = response.data; + }, + function (error) { + if (error.data) { + $window.alert("Get Harmony Devices Error: " + error.data.message); + } else { + $window.alert("Get Harmony Devices Error: unknown"); + } + } + ); + }; + this.addDevice = function (id, name, type, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) { this.state.error = ""; if(httpVerb != null && httpVerb != "") @@ -302,9 +323,19 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, bridgeService.deleteDevice(device.id); }; $scope.testUrl = function (device, type) { - if(device.deviceType == "activity") - return; if(type == "on") { + if(device.deviceType == "activity" || device.deviceType == "button") { + $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":true}").then( + function (response) { + $window.alert("Request Exceuted: " + response.statusText); + }, + function (error) { + $window.alert("Request Error: " + error.data.message); + } + ); + return; + } + if(device.httpVerb == "PUT") $http.put(device.onUrl, device.contentBody).then( function (response) { @@ -327,6 +358,18 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, window.open(device.onUrl, "_blank"); } else { + if(device.deviceType == "activity" || device.deviceType == "button") { + $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":false}").then( + function (response) { + $window.alert("Request Exceuted: " + response.statusText); + }, + function (error) { + $window.alert("Request Error: " + error.data.message); + } + ); + return; + } + if(device.httpVerb == "PUT") $http.put(device.offUrl, device.contentBodyOff).then( function (response) { @@ -368,6 +411,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer bridgeService.viewVeraDevices(); bridgeService.viewVeraScenes(); bridgeService.viewHarmonyActivities(); + bridgeService.viewHarmonyDevices(); $scope.bridge = bridgeService.state; bridgeService.updateShowVera(); bridgeService.updateShowHarmony(); @@ -450,14 +494,31 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer $scope.buildActivityUrls = function (harmonyactivity) { $scope.device.deviceType = "activity"; $scope.device.name = harmonyactivity.label; - $scope.device.onUrl = harmonyactivity.id; - $scope.device.offUrl = "-1"; + $scope.device.onUrl = "{\"name\":\"" + harmonyactivity.id + "\"}"; + $scope.device.offUrl = "{\"name\":\"-1\"}"; + }; + + $scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) { + $scope.device.deviceType = "button"; + $scope.device.name = harmonydevice.label; + $scope.device.onUrl = "{\"device\":\"" + harmonydevice.id + "\",\"button\":\"" + onbutton + "\"}"; + $scope.device.offUrl = "{\"device\":\"" + harmonydevice.id + "\",\"button\":\"" + offbutton + "\"}"; }; $scope.testUrl = function (device, type) { - if(device.deviceType == "activity") - return; if(type == "on") { + if(device.deviceType == "activity" || device.deviceType == "button") { + $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":true}").then( + function (response) { + $window.alert("Request Exceuted: " + response.statusText); + }, + function (error) { + $window.alert("Request Error: " + error.data.message); + } + ); + return; + } + if(device.httpVerb == "PUT") $http.put(device.onUrl, device.contentBody).then( function (response) { @@ -480,6 +541,18 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer window.open(device.onUrl, "_blank"); } else { + if(device.deviceType == "activity" || device.deviceType == "button") { + $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":false}").then( + function (response) { + $window.alert("Request Exceuted: " + response.statusText); + }, + function (error) { + $window.alert("Request Error: " + error.data.message); + } + ); + return; + } + if(device.httpVerb == "PUT") $http.put(device.offUrl, device.contentBodyOff).then( function (response) { diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index e7ce2a2..c98827c 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -3,6 +3,7 @@
  • Vera Devices
  • Vera Scenes
  • Harmony Activities
  • +
  • Harmony Devices
  • Manual Add
  • diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 2db7b74..0971cb3 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -3,6 +3,7 @@
  • Vera Devices
  • Vera Scenes
  • Harmony Activities
  • +
  • Harmony Devices
  • Manual Add
  • diff --git a/src/main/resources/public/views/editor.html b/src/main/resources/public/views/editor.html index 906171e..872bf83 100644 --- a/src/main/resources/public/views/editor.html +++ b/src/main/resources/public/views/editor.html @@ -3,6 +3,7 @@
  • Vera Devices
  • Vera Scenes
  • Harmony Activities
  • +
  • Harmony Devices
  • diff --git a/src/main/resources/public/views/harmonyactivity.html b/src/main/resources/public/views/harmonyactivity.html index f4d6076..6a30297 100644 --- a/src/main/resources/public/views/harmonyactivity.html +++ b/src/main/resources/public/views/harmonyactivity.html @@ -3,6 +3,7 @@
  • Vera Devices
  • Vera Scenes
  • +
  • Harmony Devices
  • Manual Add
  • @@ -19,7 +20,7 @@ - Name + Name @@ -69,9 +70,6 @@ -
    -
    @@ -83,73 +81,6 @@
    -
    - - - -
    -
    - - -
    - -
    -
    -
    -
    -
    - - -
    - -
    -
    -
    -
    -
    - - -
    - -
    -
    -
    -
    -
    -
    - - -
    - -
    -
    diff --git a/src/main/resources/public/views/harmonydevice.html b/src/main/resources/public/views/harmonydevice.html new file mode 100644 index 0000000..91799db --- /dev/null +++ b/src/main/resources/public/views/harmonydevice.html @@ -0,0 +1,107 @@ + + +
    +
    +

    Harmony Device List

    +
    + +
    +
    +
    +

    Add a Harmony Button

    +
    + +
    diff --git a/src/main/resources/public/views/nonconfiguration.html b/src/main/resources/public/views/nonconfiguration.html index 3525ab9..a3bb4e5 100644 --- a/src/main/resources/public/views/nonconfiguration.html +++ b/src/main/resources/public/views/nonconfiguration.html @@ -3,6 +3,7 @@
  • Vera Devices
  • Vera Scenes
  • Harmony Activities
  • +
  • Harmony Devices
  • Manual Add
  • diff --git a/src/main/resources/public/views/veradevice.html b/src/main/resources/public/views/veradevice.html index f41f0f5..f04fd34 100644 --- a/src/main/resources/public/views/veradevice.html +++ b/src/main/resources/public/views/veradevice.html @@ -3,6 +3,7 @@
  • Vera Scenes
  • Harmony Activities
  • +
  • Harmony Devices
  • Manual Add
  • diff --git a/src/main/resources/public/views/verascene.html b/src/main/resources/public/views/verascene.html index fd32694..a7809b5 100644 --- a/src/main/resources/public/views/verascene.html +++ b/src/main/resources/public/views/verascene.html @@ -3,6 +3,7 @@
  • Vera Devices
  • Harmony Activities
  • +
  • Harmony Devices
  • Manual Add