Skip to content

Commit

Permalink
Merge pull request #1085 from bwssytems/FixesTarget5.2.2
Browse files Browse the repository at this point in the history
Fixes target5.2.2 completed and ready for release
  • Loading branch information
bwssytems committed May 3, 2019
2 parents c25f08f + f97c718 commit c1dc897
Show file tree
Hide file tree
Showing 31 changed files with 1,243 additions and 380 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ data

sftp-config\.json
/bin/
.vscode/launch.json
.vscode/launch.test.json
.vscode/settings.json
.vscode/tasks.json
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,25 @@ 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.

```
java -jar ha-bridge-5.2.1.jar
java -jar ha-bridge-5.2.2.jar
```

ATTENTION: If running Java9, you will need to add the xml bind module
```
java -jar --add-modules java.xml.bind ha-bridge-5.2.1.jar
java -jar --add-modules java.xml.bind ha-bridge-5.2.2.jar
```

## Manual installation of ha-bridge and setup of systemd service
Next gen Linux systems (this includes the Raspberry Pi), use systemd to run and manage services.
Here is a link on how to use systemd: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units

Create the directory and make sure that ha-bridge-5.2.1.jar is in your /home/pi/ha-bridge directory.
Create the directory and make sure that ha-bridge-5.2.2.jar is in your /home/pi/ha-bridge directory.

```
pi@raspberrypi:~ $ mkdir ha-bridge
pi@raspberrypi:~ $ cd ha-bridge
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.2.1/ha-bridge-5.2.1.jar
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.2.2/ha-bridge-5.2.2.jar
```

Create the ha-bridge.service unit file:
Expand All @@ -100,7 +100,7 @@ After=network.target
Type=simple
WorkingDirectory=/home/pi/ha-bridge
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.2.1.jar
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.2.2.jar
[Install]
WantedBy=multi-user.target
Expand Down
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.7.1</version>
<version>2.7.2</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
Expand Down Expand Up @@ -114,12 +114,13 @@
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.bwssytems</groupId>
Expand Down Expand Up @@ -156,6 +157,14 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/bwssystems/HABridge/BridgeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.bwssystems.HABridge.util.BackupHandler;
import com.bwssystems.HABridge.util.JsonTransformer;
import com.bwssystems.HABridge.util.ParseRoute;
import com.google.gson.Gson;

public class BridgeSettings extends BackupHandler {
Expand Down Expand Up @@ -166,8 +167,9 @@ public void buildSettings() {
theBridgeSettings.setNestpwd(System.getProperty("nest.pwd"));
}

ParseRoute aDefaultRoute = ParseRoute.getInstance();
if(theBridgeSettings.getUpnpConfigAddress() == null || theBridgeSettings.getUpnpConfigAddress().trim().equals("") || theBridgeSettings.getUpnpConfigAddress().trim().equals("0.0.0.0")) {
addressString = checkIpAddress(null, true);
addressString = aDefaultRoute.getLocalIPAddress();
if(addressString != null) {
theBridgeSettings.setUpnpConfigAddress(addressString);
log.info("Adding " + addressString + " as our default upnp config address.");
Expand All @@ -177,8 +179,10 @@ public void buildSettings() {
}
else {
addressString = checkIpAddress(theBridgeSettings.getUpnpConfigAddress(), false);
if(addressString == null)
log.warn("The upnp config address, " + theBridgeSettings.getUpnpConfigAddress() + ", does not match any known IP's on this host.");
if(addressString == null) {
addressString = aDefaultRoute.getLocalIPAddress();
log.warn("The upnp config address, " + theBridgeSettings.getUpnpConfigAddress() + ", does not match any known IP's on this host. Using default address: " + addressString);
}
}

if(theBridgeSettings.getUpnpResponsePort() == null)
Expand All @@ -194,7 +198,7 @@ public void buildSettings() {
theBridgeSettings.setUpnpGroupDb(Configuration.GROUP_DB_DIRECTORY);

if(theBridgeSettings.getNumberoflogmessages() == null || theBridgeSettings.getNumberoflogmessages() <= 0)
theBridgeSettings.setNumberoflogmessages(new Integer(Configuration.NUMBER_OF_LOG_MESSAGES));
theBridgeSettings.setNumberoflogmessages(Integer.valueOf(Configuration.NUMBER_OF_LOG_MESSAGES));

if(theBridgeSettings.getButtonsleep() == null || theBridgeSettings.getButtonsleep() < 0)
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));
Expand All @@ -215,8 +219,10 @@ public void buildSettings() {
// Lifx is either configured or not, so it does not need an update.
if(serverPortOverride != null)
theBridgeSettings.setServerPort(serverPortOverride);
if(serverIpOverride != null)
if(serverIpOverride != null) {
theBridgeSettings.setWebaddress(serverIpOverride);
theBridgeSettings.setUpnpConfigAddress(serverIpOverride);
}
if(upnpStrictOverride != null)
theBridgeSettings.setUpnpStrict(Boolean.parseBoolean(upnpStrictOverride));
setupParams(Paths.get(theBridgeSettings.getConfigfile()), ".cfgbk", "habridge.config-");
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class DeviceDescriptor{
@SerializedName("onFirstDim")
@Expose
private boolean onFirstDim;
@SerializedName("onWhenDimPresent")
@Expose
private boolean onWhenDimPresent;

public String getName() {
return name;
Expand Down Expand Up @@ -286,6 +289,14 @@ public void setOnFirstDim(boolean onFirstDim) {
this.onFirstDim = onFirstDim;
}

public boolean isOnWhenDimPresent() {
return onWhenDimPresent;
}

public void setOnWhenDimPresent(boolean onWhenDimPresent) {
this.onWhenDimPresent = onWhenDimPresent;
}

public boolean containsType(String aType) {
if(aType == null)
return false;
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -13,8 +12,6 @@
import java.util.Iterator;
import java.util.Map;

import javax.xml.bind.DatatypeConverter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,6 +22,7 @@
import com.bwssystems.HABridge.plugins.hue.HueHome;
import com.bwssystems.HABridge.util.BackupHandler;
import com.bwssystems.HABridge.util.JsonTransformer;
import com.bwssystems.HABridge.util.HexLibrary;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
Expand Down Expand Up @@ -180,9 +178,7 @@ public void save(DeviceDescriptor[] descriptors) {
descriptors[i].setId(String.valueOf(nextId));
}
if(descriptors[i].getUniqueid() == null || descriptors[i].getUniqueid().length() == 0) {
BigInteger bigInt = BigInteger.valueOf(Integer.decode(descriptors[i].getId()));
byte[] theBytes = bigInt.toByteArray();
String hexValue = DatatypeConverter.printHexBinary(theBytes);
String hexValue = HexLibrary.encodeUsingBigIntegerToString(descriptors[i].getId());

descriptors[i].setUniqueid("00:17:88:5E:D3:" + hexValue + "-" + hexValue);
}
Expand All @@ -204,9 +200,7 @@ public void renumber() {
nextId++;
DeviceDescriptor theDevice = deviceIterator.next();
theDevice.setId(String.valueOf(nextId));
BigInteger bigInt = BigInteger.valueOf(nextId);
byte[] theBytes = bigInt.toByteArray();
String hexValue = DatatypeConverter.printHexBinary(theBytes);
String hexValue = HexLibrary.encodeUsingBigIntegerToString(nextId.toString());

theDevice.setUniqueid("00:17:88:5E:D3:" + hexValue + "-" + hexValue);
newdevices.put(theDevice.getId(), theDevice);
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,22 @@ public static String replaceIntensityValue(String request, int intensity, boolea
boolean notDone = true;
String replaceValue = null;
String replaceTarget = null;
int percentBrightness = (int) Math.round(intensity / 255.0 * 100);
float decimalBrightness = (float) (intensity / 255.0);
int percentBrightness = 0;
float decimalBrightness = (float) 0.0;
Map<String, BigDecimal> variables = new HashMap<String, BigDecimal>();
String mathDescriptor = null;


if(intensity > 0) {
decimalBrightness = (float) (intensity / 255.0);
if(intensity > 0 && intensity < 5)
percentBrightness = 1;
else
percentBrightness = (int) Math.round(intensity / 255.0 * 100);
} else {
decimalBrightness = (float) 0.0;
percentBrightness = 0;
}

while(notDone) {
notDone = false;
if (request.contains(INTENSITY_BYTE)) {
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,9 @@ private String updateState(String userId, String lightId, String body, String ip
}

if (body.contains("\"bri_inc\""))
targetBriInc = new Integer(theStateChanges.getBri_inc());
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
else if (body.contains("\"bri\"")) {
targetBri = new Integer(theStateChanges.getBri());
targetBri =Integer.valueOf(theStateChanges.getBri());
}

state = device.getDeviceState();
Expand Down Expand Up @@ -1153,11 +1153,11 @@ private String changeState(String userId, String lightId, String body, String ip
}

if (body.contains("\"bri_inc\"")) {
targetBriInc = new Integer(theStateChanges.getBri_inc());
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
isDimRequest = true;
}
else if (body.contains("\"bri\"")) {
targetBri = new Integer(theStateChanges.getBri());
targetBri = Integer.valueOf(theStateChanges.getBri());
isDimRequest = true;
}

Expand Down Expand Up @@ -1186,13 +1186,22 @@ else if (body.contains("\"bri\"")) {
isOnRequest = true;
}

if(!device.isOnFirstDim() && device.isOnWhenDimPresent() && isDimRequest) {
isOnRequest = true;
theStateChanges.setOn(true);
} else if(!device.isOnFirstDim() && !device.isOnWhenDimPresent() && isDimRequest) {
isOnRequest = false;
}

if(device.isOnFirstDim() && isDimRequest && !device.getDeviceState().isOn()) {
isOnRequest = true;
theStateChanges.setOn(true);
isDimRequest = false;
isColorRequest = false;
} else if(device.isOnFirstDim() && isDimRequest && device.getDeviceState().isOn()) {
if(device.getDeviceState().getBri() == theStateChanges.getBri()) {
isOnRequest = true;
theStateChanges.setOn(true);
isDimRequest = false;
isColorRequest = false;
} else {
Expand Down Expand Up @@ -1334,10 +1343,10 @@ private String changeGroupState(String userId, String groupId, String body, Stri

if (group != null) {
if (body.contains("\"bri_inc\"")) {
targetBriInc = new Integer(theStateChanges.getBri_inc());
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
}
else if (body.contains("\"bri\"")) {
targetBri = new Integer(theStateChanges.getBri());
targetBri = Integer.valueOf(theStateChanges.getBri());
}

state = group.getAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.util.List;
import java.util.Map;

import javax.xml.bind.DatatypeConverter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -28,6 +26,7 @@
import com.bwssystems.HABridge.hue.DeviceDataDecode;
import com.bwssystems.HABridge.hue.MultiCommandUtil;
import com.bwssystems.HABridge.hue.TimeDecode;
import com.bwssystems.HABridge.util.HexLibrary;
import com.github.mob41.blapi.BLDevice;
import com.github.mob41.blapi.MP1Device;
import com.github.mob41.blapi.SP1Device;
Expand Down Expand Up @@ -118,7 +117,7 @@ public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String

if (theDevice == null) {
if(broadlinkCommand.hasIpAndMac()) {
byte[] intBytes = DatatypeConverter.parseHexBinary(broadlinkCommand.getType());
byte[] intBytes = HexLibrary.decodeHexString(broadlinkCommand.getType());
BigInteger theBig = new BigInteger(intBytes);
int theType = theBig.intValue();
try {
Expand Down Expand Up @@ -218,13 +217,13 @@ public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String
}
theStringData = DeviceDataDecode.replaceDeviceData(theStringData, device);
theStringData = TimeDecode.replaceTimeValue(theStringData);
byte[] theData = DatatypeConverter.parseHexBinary(theStringData);
byte[] theData = HexLibrary.decodeHexString(theStringData);
SendDataCmdPayload thePayload = new SendDataCmdPayload(theData);

DatagramPacket thePacket = theDevice.sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload);
String returnData = null;
if(thePacket != null)
returnData = DatatypeConverter.printHexBinary(thePacket.getData());
returnData = HexLibrary.encodeHexString(thePacket.getData());
else
returnData = "No Data - null";
log.debug("RM2 Device data return: <<<" + returnData + ">>>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.net.DatagramPacket;
import java.net.InetAddress;

import javax.xml.bind.DatatypeConverter;
import com.bwssystems.HABridge.util.HexLibrary;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -33,7 +33,7 @@ public void setPower(boolean aState) {
}

public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) {
log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(aCmd.getPayload().getData()));
log.info("sendCmdPkt called with " + HexLibrary.encodeHexString(aCmd.getPayload().getData()));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.IOException;
import java.net.DatagramPacket;
import javax.xml.bind.DatatypeConverter;
import com.bwssystems.HABridge.util.HexLibrary;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -23,7 +23,7 @@ public void setState(int anIndex, boolean aState) {
}

public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) {
log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(aCmd.getPayload().getData()));
log.info("sendCmdPkt called with " + HexLibrary.encodeHexString(aCmd.getPayload().getData()));
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.IOException;
import java.net.DatagramPacket;

import javax.xml.bind.DatatypeConverter;
import com.bwssystems.HABridge.util.HexLibrary;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -21,7 +21,7 @@ protected TestRM2Device(String host, Mac mac) throws IOException {
}

public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) {
log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(((SendDataCmdPayload)aCmd).getData()));
log.info("sendCmdPkt called with " + HexLibrary.encodeHexString(((SendDataCmdPayload)aCmd).getData()));
return null;
}
}
Loading

0 comments on commit c1dc897

Please sign in to comment.