Fix immediate issues for JSON decoding

Fixes #391
Fixes #392
Fixes #398
This commit is contained in:
Admin
2017-01-25 15:19:46 -06:00
parent 881f739c0b
commit c9d55e26ac
9 changed files with 42 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
# ha-bridge # ha-bridge
Emulates Philips Hue api to other home automation gateways such as an Amazon Echo or Google Home. The Bridge handles basic commands such as "On", "Off" and "brightness" commands of the hue protocol. This bridge can control most devices that have a distinct API. Emulates Philips Hue api to other home automation gateways such as an Amazon Echo or Google Home. The Bridge handles basic commands such as "On", "Off" and "brightness" commands of the hue protocol. This bridge can control most devices that have a distinct API.
**SECURITY RISK: If you are unsure on how this software operates and what it exposes to your netowrk, please make sure you understand that it can allow root access to your sytem. It is best practice to not open this to the itnernet through your router as there are no security protocols in place to protect the system. The Licenese agreement states specifically that you use this at your own risk.**
**ATTENTION: This requires a physical Amazon Echo, Dot or Tap and does not work with prototype devices built using the Alexa Voice Service e.g. Amazon's Alexa AVS Sample App and Sam Machin's AlexaPi. The AVS version does not have any capability for Hue Bridge discovery!** **ATTENTION: This requires a physical Amazon Echo, Dot or Tap and does not work with prototype devices built using the Alexa Voice Service e.g. Amazon's Alexa AVS Sample App and Sam Machin's AlexaPi. The AVS version does not have any capability for Hue Bridge discovery!**
**NOTE: This software does require the user to have knwoledge on how processes run on Linux or Windows with java. Also, an understanding of networking basics will help as well. This system reveives upnp udp multicast packets from devices to be found, so that is some thing to understand. Please make sure you have all your devices use static IP addresses from your router. Most all questions have been answered already. PLEASE USE GOOGLE TO FIND YOUR ANSWERS!** **NOTE: This software does require the user to have knwoledge on how processes run on Linux or Windows with java. Also, an understanding of networking basics will help as well. This system reveives upnp udp multicast packets from devices to be found, so that is some thing to understand. Please make sure you have all your devices use static IP addresses from your router. Most all questions have been answered already. PLEASE USE GOOGLE TO FIND YOUR ANSWERS!**
@@ -31,16 +33,16 @@ ATTENTION: This requires JDK 1.8 to run
ATTENTION: Due to port 80 being the default, Linux restricts this to super user. Use the instructions below. ATTENTION: Due to port 80 being the default, Linux restricts this to super user. Use the instructions below.
``` ```
java -jar ha-bridge-4.0.2.jar java -jar ha-bridge-4.0.3.jar
``` ```
### Automation on Linux systems ### Automation on Linux systems
To have this configured and running automatically there are a few resources to use. One is using Docker and a docker container has been built for this and can be gotten here: https://github.com/aptalca/docker-ha-bridge To have this configured and running automatically there are a few resources to use. One is using Docker and a docker container has been built for this and can be gotten here: https://github.com/aptalca/docker-ha-bridge
Create the directory and make sure that ha-bridge-4.0.2.jar is in your /home/pi/habridge directory. Create the directory and make sure that ha-bridge-4.0.3.jar is in your /home/pi/habridge directory.
``` ```
pi@raspberrypi:~ $ mkdir habridge pi@raspberrypi:~ $ mkdir habridge
pi@raspberrypi:~ $ cd habridge pi@raspberrypi:~ $ cd habridge
pi@raspberrypi:~/habridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v4.0.2/ha-bridge-4.0.2.jar pi@raspberrypi:~/habridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v4.0.3/ha-bridge-4.0.3.jar
``` ```
#### System Control Setup on a pi (preferred) #### System Control Setup on a pi (preferred)
For next gen Linux systems (this includes the Raspberry Pi), here is a systemctl unit file that you can install. Here is a link on how to do this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units For next gen Linux systems (this includes the Raspberry Pi), here is a systemctl unit file that you can install. Here is a link on how to do this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
@@ -59,7 +61,7 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.0.2.jar ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.0.3.jar
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
@@ -94,7 +96,7 @@ Then cut and past this, modify any locations that are not correct
``` ```
cd /home/pi/habridge cd /home/pi/habridge
rm /home/pi/habridge/habridge-log.txt rm /home/pi/habridge/habridge-log.txt
nohup java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.0.2.jar > /home/pi/habridge/habridge-log.txt 2>&1 & nohup java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.0.3.jar > /home/pi/habridge/habridge-log.txt 2>&1 &
chmod 777 /home/pi/habridge/habridge-log.txt chmod 777 /home/pi/habridge/habridge-log.txt
``` ```
Exit and save the file with ctrl-X and follow the prompts and then execute on the command line: Exit and save the file with ctrl-X and follow the prompts and then execute on the command line:

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>4.0.2</version> <version>4.0.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>

View File

@@ -6,6 +6,7 @@ public class NamedIP {
private String port; private String port;
private String username; private String username;
private String password; private String password;
private Boolean secure;
public String getName() { public String getName() {
return name; return name;
@@ -37,4 +38,10 @@ public class NamedIP {
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
public Boolean getSecure() {
return secure;
}
public void setSecure(Boolean secure) {
this.secure = secure;
}
} }

View File

@@ -524,10 +524,11 @@ public class HueMulator {
deviceResponseMap = new HashMap<String, DeviceResponse>(); deviceResponseMap = new HashMap<String, DeviceResponse>();
for (DeviceDescriptor device : deviceList) { for (DeviceDescriptor device : deviceList) {
DeviceResponse deviceResponse = null; DeviceResponse deviceResponse = null;
if ((device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) { // In the multi command context, this is not valid anymore
HueDeviceIdentifier deviceId = aGsonHandler.fromJson(device.getOnUrl(), HueDeviceIdentifier.class); // if ((device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
deviceResponse = myHueHome.getHueDeviceInfo(deviceId, device); // HueDeviceIdentifier deviceId = aGsonHandler.fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
} // deviceResponse = myHueHome.getHueDeviceInfo(deviceId, device);
// }
if (deviceResponse == null) if (deviceResponse == null)
deviceResponse = DeviceResponse.createResponse(device); deviceResponse = DeviceResponse.createResponse(device);
@@ -730,7 +731,7 @@ public class HueMulator {
} }
// code for backwards compatibility // code for backwards compatibility
if(!(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) { if(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
if(url == null) if(url == null)
url = device.getOnUrl(); url = device.getOnUrl();
} }

View File

@@ -25,7 +25,7 @@ public class CommandHome implements Home {
log.debug("Exec Request called with url: " + anItem.getItem().getAsString()); log.debug("Exec Request called with url: " + anItem.getItem().getAsString());
String responseString = null; String responseString = null;
String intermediate; String intermediate;
if (anItem.getItem().toString().contains("exec://")) if (anItem.getItem().getAsString().contains("exec://"))
intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3); intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3);
else else
intermediate = anItem.getItem().getAsString(); intermediate = anItem.getItem().getAsString();

View File

@@ -125,9 +125,10 @@ public class HalHome implements Home {
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(), String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
intensity, targetBri, targetBriInc, false); intensity, targetBri, targetBriInc, false);
String aBody; String aBody = null;
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(), if(anItem.getHttpBody()!= null && !anItem.getHttpBody().isEmpty())
intensity, targetBri, targetBriInc, false); aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
intensity, targetBri, targetBriInc, false);
// make call // make call
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody, if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) { new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {

View File

@@ -152,7 +152,12 @@ public class HarmonyHome implements Home {
myHarmony.startActivity(anActivity); myHarmony.startActivity(anActivity);
} }
} else if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) { } else if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
String url = anItem.getItem().toString(); String url = null;
if(anItem.getItem().isJsonObject()) {
url = aGsonHandler.toJson(anItem.getItem());
} else
url = anItem.getItem().getAsString();
if (url.substring(0, 1).equalsIgnoreCase("{")) { if (url.substring(0, 1).equalsIgnoreCase("{")) {
url = "[" + url + "]"; url = "[" + url + "]";
} }

View File

@@ -46,9 +46,10 @@ public class HTTPHome implements Home {
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(), String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
intensity, targetBri, targetBriInc, false); intensity, targetBri, targetBriInc, false);
String aBody; String aBody = null;
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(), if(anItem.getHttpBody()!= null && !anItem.getHttpBody().isEmpty())
intensity, targetBri, targetBriInc, false); aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
intensity, targetBri, targetBriInc, false);
// make call // make call
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody, if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) { new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {

View File

@@ -80,11 +80,13 @@ public class MQTTHome implements Home {
log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString()); log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString());
if (validMqtt) { if (validMqtt) {
String mqttObject = null; String mqttObject = null;
if(anItem.getItem().isJsonObject()) if(anItem.getItem().isJsonObject() || anItem.getItem().isJsonArray()) {
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(), String theItem = aGsonHandler.toJson(anItem.getItem());
intensity, targetBri, targetBriInc, false); mqttObject = BrightnessDecode.calculateReplaceIntensityValue(theItem,
intensity, targetBri, targetBriInc, false);
}
else else
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().toString(), mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
intensity, targetBri, targetBriInc, false); intensity, targetBri, targetBriInc, false);
if (mqttObject.substring(0, 1).equalsIgnoreCase("{")) if (mqttObject.substring(0, 1).equalsIgnoreCase("{"))
mqttObject = "[" + mqttObject + "]"; mqttObject = "[" + mqttObject + "]";