diff --git a/pom.xml b/pom.xml
index ac4959d..f3ea4a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.bwssystems.HABridge
ha-bridge
- 5.2.0RC12
+ 5.2.0RC13
jar
HA Bridge
@@ -127,7 +127,7 @@
2.1.6
- com.github.mob41
+ com.github.bwssytems
broadlink-java-api
-SNAPSHOT
diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java
index 4e4cdd1..1003b6e 100644
--- a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java
+++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java
@@ -28,7 +28,6 @@ import com.bwssystems.HABridge.hue.MultiCommandUtil;
import com.bwssystems.HABridge.hue.TimeDecode;
import com.github.mob41.blapi.BLDevice;
import com.github.mob41.blapi.MP1Device;
-import com.github.mob41.blapi.RM2Device;
import com.github.mob41.blapi.SP1Device;
import com.github.mob41.blapi.SP2Device;
import com.github.mob41.blapi.pkt.cmd.rm2.SendDataCmdPayload;
@@ -159,18 +158,24 @@ public class BroadlinkHome implements Home {
else
changeState = false;
try {
- if(!isDevMode)
- theDevice.auth();
+ if(!isDevMode) {
+ if(!theDevice.auth()) {
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _rm2 + " device authorization failed.");
+ theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _rm2 + " device auth error.\", \"parameter\": \"/lights/"
+ + lightId + "state\"}}]";
+ }
+ }
((MP1Device) theDevice).setState(Integer.parseInt(broadlinkCommand.getData()), changeState);
} catch (NumberFormatException e1) {
- log.error("Call to " + _mp1 + " device failed with number format exception.", e1);
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _mp1 + " device failed with number format exception.", e1);
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
- + "\",\"description\": \"" + _mp1 + " number format error.\", \"parameter\": \"/lights/"
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _mp1 + " number format error.\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
} catch (Exception e1) {
- log.error("Call to " + _mp1 + " device failed with exception.", e1);
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _mp1 + " device failed with exception.", e1);
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
- + "\",\"description\": \"" + _mp1 + " device call error.\", \"parameter\": \"/lights/"
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _mp1 + " device call error.\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
};
break;
@@ -190,13 +195,19 @@ public class BroadlinkHome implements Home {
else
changeState = false;
try {
- if(!isDevMode)
- theDevice.auth();
+ if(!isDevMode) {
+ if(!theDevice.auth()) {
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _rm2 + " device authorization failed.");
+ theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _rm2 + " device auth error.\", \"parameter\": \"/lights/"
+ + lightId + "state\"}}]";
+ }
+ }
((SP2Device) theDevice).setState(changeState);
} catch (Exception e1) {
- log.error("Call to " + _sp2 + " device failed with exception.", e1);
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _sp2 + " device failed with exception.", e1);
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
- + "\",\"description\": \"" + _sp2 + " device call error.\", \"parameter\": \"/lights/"
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _sp2 + " device call error.\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
}
break;
@@ -206,11 +217,17 @@ public class BroadlinkHome implements Home {
else
changeState = false;
try {
- if(!isDevMode)
- theDevice.auth();
+ if(!isDevMode) {
+ if(!theDevice.auth()) {
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _rm2 + " device authorization failed.");
+ theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _rm2 + " device auth error.\", \"parameter\": \"/lights/"
+ + lightId + "state\"}}]";
+ }
+ }
((SP1Device) theDevice).setPower(changeState);
} catch (Exception e) {
- log.error("Call to " + _sp1 + " device failed with exception.", e);
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _sp1 + " device failed with exception.", e);
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ "\",\"description\": \"" + _sp1 + " device call error.\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
@@ -238,22 +255,29 @@ public class BroadlinkHome implements Home {
byte[] theData = DatatypeConverter.parseHexBinary(theStringData);
SendDataCmdPayload thePayload = new SendDataCmdPayload(theData);
try {
- if(!isDevMode)
- theDevice.auth();
- DatagramPacket thePacket = ((RM2Device) theDevice).sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload);
+ if(!isDevMode) {
+ if(!theDevice.auth()) {
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _rm2 + " device authorization failed.");
+ theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _rm2 + " device auth error.\", \"parameter\": \"/lights/"
+ + lightId + "state\"}}]";
+ }
+ }
+
+ DatagramPacket thePacket = theDevice.sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload);
String returnData = DatatypeConverter.printHexBinary(thePacket.getData());
log.debug("RM2 Device data return: <<<" + returnData + ">>>");
} catch (IOException e) {
- log.error("Call to " + _rm2 + " device failed with exception.", e);
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _rm2 + " device failed with exception.", e);
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
- + "\",\"description\": \"" + _rm2 + " device call error.\", \"parameter\": \"/lights/"
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _rm2 + " device call error.\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
}
}
else {
- log.error("Call to " + _rm2 + " with no data, noop");
+ log.error("Call to " + broadlinkCommand.getId() + " - " + _rm2 + " with no data, noop");
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
- + "\",\"description\": \"" + _rm2 + " could not call device without data.\", \"parameter\": \"/lights/"
+ + "\",\"description\": \"" + broadlinkCommand.getId() + " - " + _rm2 + " could not call device without data.\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
}
break;
diff --git a/src/test/java/com/bwssystems/broadlink/test/BroadlinkDataConstructor.java b/src/test/java/com/bwssystems/broadlink/test/BroadlinkDataConstructor.java
new file mode 100644
index 0000000..e2c80e6
--- /dev/null
+++ b/src/test/java/com/bwssystems/broadlink/test/BroadlinkDataConstructor.java
@@ -0,0 +1,37 @@
+package com.bwssystems.broadlink.test;
+
+import javax.xml.bind.DatatypeConverter;
+
+public class BroadlinkDataConstructor {
+ public final static byte[] testData1 = { 84, 104, 105, 115, 73, 115, 65, 84, 101, 115, 116, 83, 116, 114, 105, 110, 103, 49 };
+ public final static String hexString1 = "5468697349734154657374537472696E6731";
+ public final static byte[] testData2 = { 110, 0, 110, 1, 13, 4, 40, 0, 1, 79, 0, 1, 26, (byte) 139, 18, 17, 18, 52, 17, 53, 17, 18, 27, 8, 17, 18, 30, 5, 17, 18, 18, 51};
+ public final static String hexString2 = "6e006e010d042800014f00011a8b12111234113511121b0811121e051112123312111211123412331234123412331212111212111112123312121211111212341134113412341211113511341135110004db00011a8c11121134123412111112111212111212113411121112113511341135113511341112111211121112123411121112121111351135113412331212113412341135110004db00011a8c11121135113412111211111211131112113411121211123411351134123411341211121112111212113411121212111211341135113412341112113511341234110004dc0001198d11121134113511121112111211121112113511121112113511341135113412341112111212111211123411121112111211351134123411341212113412341134120004db00011a8c11121135113411121112121211111211123411121112123411341234123411341211121112111212113412111211121112341234113412341112113511341234110005dc00000000000000000000";
+ public final static byte[] testData3 = { 38, 0, 120, 0, 88, 28};
+ public final static String hexString3 = "26007800581c111b0f0f0e0f2b2b100e0f0f100d0f0f0e0f100d0f0f0e0f100e1d0f0e100e0f0e1e1f000add571c111b0f0f110c2c2b100e0e0f100e0e0f0e0f100e0e0f0e0f110d1d100e0f0e0f0e1e1f000add571d0f1c100e100d2c2c0e0f0e0f0f0f0e0f0e0f110d0f0e100d100f1c100e0f0f0e0f1e1d000d05";
+ public Boolean validateStructure() {
+ String theHexString = hexString3;
+ byte[] theBytes = testData3;
+ byte[] theData;
+
+
+ System.out.println("----------------------------------");
+ System.out.println("This is the test hex string: <<<" + theHexString + ">>>");
+ try {
+ theData = DatatypeConverter.parseHexBinary(theHexString);
+ System.out.println("This is the test hex string from data bytes: <<<" + DatatypeConverter.printHexBinary(theData) + ">>>");
+ } catch(Exception e) {
+ System.out.println("Error parsing he string: " + e.getMessage());
+ return false;
+ }
+ for( int i = 0; i < theBytes.length; i++) {
+ if(theBytes[i] != theData[i]) {
+ System.out.println("the compare data is not the same length at index: " + i);
+ return false;
+ }
+ }
+ System.out.println("----------------------------------");
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/bwssystems/broadlink/test/BroadlinkDataTestCase.java b/src/test/java/com/bwssystems/broadlink/test/BroadlinkDataTestCase.java
new file mode 100644
index 0000000..e793b95
--- /dev/null
+++ b/src/test/java/com/bwssystems/broadlink/test/BroadlinkDataTestCase.java
@@ -0,0 +1,14 @@
+package com.bwssystems.broadlink.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BroadlinkDataTestCase {
+
+ @Test
+ public void testValidateStructure() {
+ BroadlinkDataConstructor aTestService = new BroadlinkDataConstructor();
+ Assert.assertEquals(aTestService.validateStructure(), true);
+ }
+
+}