mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-21 17:18:49 +00:00
Adding button selection control for harmony. in progress....
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
25
src/main/java/com/bwssystems/harmony/ButtonPress.java
Normal file
25
src/main/java/com/bwssystems/harmony/ButtonPress.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
18
src/main/java/com/bwssystems/harmony/RunActivity.java
Normal file
18
src/main/java/com/bwssystems/harmony/RunActivity.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user