Adding button selection control for harmony. in progress....

This commit is contained in:
Admin
2015-10-30 16:30:30 -05:00
parent 59f1db285d
commit bf5ad2e23c
18 changed files with 301 additions and 106 deletions

View File

@@ -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();

View File

@@ -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());
}

View File

@@ -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
{

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;
}
}