Skip to content

Commit c1dc897

Browse files
authored
Merge pull request #1085 from bwssytems/FixesTarget5.2.2
Fixes target5.2.2 completed and ready for release
2 parents c25f08f + f97c718 commit c1dc897

31 files changed

+1243
-380
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ data
1515

1616
sftp-config\.json
1717
/bin/
18+
.vscode/launch.json
19+
.vscode/launch.test.json
20+
.vscode/settings.json
21+
.vscode/tasks.json

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ ATTENTION: This requires JDK 1.8 to run
6363
ATTENTION: Due to port 80 being the default, Linux restricts this to super user. Use the instructions below.
6464

6565
```
66-
java -jar ha-bridge-5.2.1.jar
66+
java -jar ha-bridge-5.2.2.jar
6767
```
6868

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

7474
## Manual installation of ha-bridge and setup of systemd service
7575
Next gen Linux systems (this includes the Raspberry Pi), use systemd to run and manage services.
7676
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
7777

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

8080
```
8181
pi@raspberrypi:~ $ mkdir ha-bridge
8282
pi@raspberrypi:~ $ cd ha-bridge
8383
84-
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.2.1/ha-bridge-5.2.1.jar
84+
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.2.2/ha-bridge-5.2.2.jar
8585
```
8686

8787
Create the ha-bridge.service unit file:
@@ -100,7 +100,7 @@ After=network.target
100100
Type=simple
101101
102102
WorkingDirectory=/home/pi/ha-bridge
103-
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.2.1.jar
103+
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.2.2.jar
104104
105105
[Install]
106106
WantedBy=multi-user.target

pom.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<dependency>
6464
<groupId>com.sparkjava</groupId>
6565
<artifactId>spark-core</artifactId>
66-
<version>2.7.1</version>
66+
<version>2.7.2</version>
6767
<exclusions>
6868
<exclusion>
6969
<artifactId>slf4j-simple</artifactId>
@@ -114,12 +114,13 @@
114114
<dependency>
115115
<groupId>org.eclipse.paho</groupId>
116116
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
117-
<version>1.1.0</version>
117+
<version>1.2.0</version>
118118
</dependency>
119119
<dependency>
120120
<groupId>junit</groupId>
121121
<artifactId>junit</artifactId>
122122
<version>4.12</version>
123+
<scope>test</scope>
123124
</dependency>
124125
<dependency>
125126
<groupId>com.github.bwssytems</groupId>
@@ -156,6 +157,14 @@
156157
</resource>
157158
</resources>
158159
<plugins>
160+
<plugin>
161+
<groupId>org.apache.maven.plugins</groupId>
162+
<artifactId>maven-surefire-plugin</artifactId>
163+
<version>2.22.1</version>
164+
<configuration>
165+
<skipTests>true</skipTests>
166+
</configuration>
167+
</plugin>
159168
<plugin>
160169
<groupId>org.apache.maven.plugins</groupId>
161170
<artifactId>maven-shade-plugin</artifactId>

src/main/java/com/bwssystems/HABridge/BridgeSettings.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.bwssystems.HABridge.util.BackupHandler;
2626
import com.bwssystems.HABridge.util.JsonTransformer;
27+
import com.bwssystems.HABridge.util.ParseRoute;
2728
import com.google.gson.Gson;
2829

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

170+
ParseRoute aDefaultRoute = ParseRoute.getInstance();
169171
if(theBridgeSettings.getUpnpConfigAddress() == null || theBridgeSettings.getUpnpConfigAddress().trim().equals("") || theBridgeSettings.getUpnpConfigAddress().trim().equals("0.0.0.0")) {
170-
addressString = checkIpAddress(null, true);
172+
addressString = aDefaultRoute.getLocalIPAddress();
171173
if(addressString != null) {
172174
theBridgeSettings.setUpnpConfigAddress(addressString);
173175
log.info("Adding " + addressString + " as our default upnp config address.");
@@ -177,8 +179,10 @@ public void buildSettings() {
177179
}
178180
else {
179181
addressString = checkIpAddress(theBridgeSettings.getUpnpConfigAddress(), false);
180-
if(addressString == null)
181-
log.warn("The upnp config address, " + theBridgeSettings.getUpnpConfigAddress() + ", does not match any known IP's on this host.");
182+
if(addressString == null) {
183+
addressString = aDefaultRoute.getLocalIPAddress();
184+
log.warn("The upnp config address, " + theBridgeSettings.getUpnpConfigAddress() + ", does not match any known IP's on this host. Using default address: " + addressString);
185+
}
182186
}
183187

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

196200
if(theBridgeSettings.getNumberoflogmessages() == null || theBridgeSettings.getNumberoflogmessages() <= 0)
197-
theBridgeSettings.setNumberoflogmessages(new Integer(Configuration.NUMBER_OF_LOG_MESSAGES));
201+
theBridgeSettings.setNumberoflogmessages(Integer.valueOf(Configuration.NUMBER_OF_LOG_MESSAGES));
198202

199203
if(theBridgeSettings.getButtonsleep() == null || theBridgeSettings.getButtonsleep() < 0)
200204
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));
@@ -215,8 +219,10 @@ public void buildSettings() {
215219
// Lifx is either configured or not, so it does not need an update.
216220
if(serverPortOverride != null)
217221
theBridgeSettings.setServerPort(serverPortOverride);
218-
if(serverIpOverride != null)
222+
if(serverIpOverride != null) {
219223
theBridgeSettings.setWebaddress(serverIpOverride);
224+
theBridgeSettings.setUpnpConfigAddress(serverIpOverride);
225+
}
220226
if(upnpStrictOverride != null)
221227
theBridgeSettings.setUpnpStrict(Boolean.parseBoolean(upnpStrictOverride));
222228
setupParams(Paths.get(theBridgeSettings.getConfigfile()), ".cfgbk", "habridge.config-");

src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public class DeviceDescriptor{
8383
@SerializedName("onFirstDim")
8484
@Expose
8585
private boolean onFirstDim;
86+
@SerializedName("onWhenDimPresent")
87+
@Expose
88+
private boolean onWhenDimPresent;
8689

8790
public String getName() {
8891
return name;
@@ -286,6 +289,14 @@ public void setOnFirstDim(boolean onFirstDim) {
286289
this.onFirstDim = onFirstDim;
287290
}
288291

292+
public boolean isOnWhenDimPresent() {
293+
return onWhenDimPresent;
294+
}
295+
296+
public void setOnWhenDimPresent(boolean onWhenDimPresent) {
297+
this.onWhenDimPresent = onWhenDimPresent;
298+
}
299+
289300
public boolean containsType(String aType) {
290301
if(aType == null)
291302
return false;

src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import java.io.IOException;
5-
import java.math.BigInteger;
65
import java.nio.file.FileSystems;
76
import java.nio.file.Files;
87
import java.nio.file.Path;
@@ -13,8 +12,6 @@
1312
import java.util.Iterator;
1413
import java.util.Map;
1514

16-
import javax.xml.bind.DatatypeConverter;
17-
1815
import org.slf4j.Logger;
1916
import org.slf4j.LoggerFactory;
2017

@@ -25,6 +22,7 @@
2522
import com.bwssystems.HABridge.plugins.hue.HueHome;
2623
import com.bwssystems.HABridge.util.BackupHandler;
2724
import com.bwssystems.HABridge.util.JsonTransformer;
25+
import com.bwssystems.HABridge.util.HexLibrary;
2826
import com.google.gson.Gson;
2927
import com.google.gson.GsonBuilder;
3028
import com.google.gson.JsonSyntaxException;
@@ -180,9 +178,7 @@ public void save(DeviceDescriptor[] descriptors) {
180178
descriptors[i].setId(String.valueOf(nextId));
181179
}
182180
if(descriptors[i].getUniqueid() == null || descriptors[i].getUniqueid().length() == 0) {
183-
BigInteger bigInt = BigInteger.valueOf(Integer.decode(descriptors[i].getId()));
184-
byte[] theBytes = bigInt.toByteArray();
185-
String hexValue = DatatypeConverter.printHexBinary(theBytes);
181+
String hexValue = HexLibrary.encodeUsingBigIntegerToString(descriptors[i].getId());
186182

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

211205
theDevice.setUniqueid("00:17:88:5E:D3:" + hexValue + "-" + hexValue);
212206
newdevices.put(theDevice.getId(), theDevice);

src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,22 @@ public static String replaceIntensityValue(String request, int intensity, boolea
5252
boolean notDone = true;
5353
String replaceValue = null;
5454
String replaceTarget = null;
55-
int percentBrightness = (int) Math.round(intensity / 255.0 * 100);
56-
float decimalBrightness = (float) (intensity / 255.0);
55+
int percentBrightness = 0;
56+
float decimalBrightness = (float) 0.0;
5757
Map<String, BigDecimal> variables = new HashMap<String, BigDecimal>();
5858
String mathDescriptor = null;
59-
59+
60+
if(intensity > 0) {
61+
decimalBrightness = (float) (intensity / 255.0);
62+
if(intensity > 0 && intensity < 5)
63+
percentBrightness = 1;
64+
else
65+
percentBrightness = (int) Math.round(intensity / 255.0 * 100);
66+
} else {
67+
decimalBrightness = (float) 0.0;
68+
percentBrightness = 0;
69+
}
70+
6071
while(notDone) {
6172
notDone = false;
6273
if (request.contains(INTENSITY_BYTE)) {

src/main/java/com/bwssystems/HABridge/hue/HueMulator.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,9 @@ private String updateState(String userId, String lightId, String body, String ip
10731073
}
10741074

10751075
if (body.contains("\"bri_inc\""))
1076-
targetBriInc = new Integer(theStateChanges.getBri_inc());
1076+
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
10771077
else if (body.contains("\"bri\"")) {
1078-
targetBri = new Integer(theStateChanges.getBri());
1078+
targetBri =Integer.valueOf(theStateChanges.getBri());
10791079
}
10801080

10811081
state = device.getDeviceState();
@@ -1153,11 +1153,11 @@ private String changeState(String userId, String lightId, String body, String ip
11531153
}
11541154

11551155
if (body.contains("\"bri_inc\"")) {
1156-
targetBriInc = new Integer(theStateChanges.getBri_inc());
1156+
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
11571157
isDimRequest = true;
11581158
}
11591159
else if (body.contains("\"bri\"")) {
1160-
targetBri = new Integer(theStateChanges.getBri());
1160+
targetBri = Integer.valueOf(theStateChanges.getBri());
11611161
isDimRequest = true;
11621162
}
11631163

@@ -1186,13 +1186,22 @@ else if (body.contains("\"bri\"")) {
11861186
isOnRequest = true;
11871187
}
11881188

1189+
if(!device.isOnFirstDim() && device.isOnWhenDimPresent() && isDimRequest) {
1190+
isOnRequest = true;
1191+
theStateChanges.setOn(true);
1192+
} else if(!device.isOnFirstDim() && !device.isOnWhenDimPresent() && isDimRequest) {
1193+
isOnRequest = false;
1194+
}
1195+
11891196
if(device.isOnFirstDim() && isDimRequest && !device.getDeviceState().isOn()) {
11901197
isOnRequest = true;
1198+
theStateChanges.setOn(true);
11911199
isDimRequest = false;
11921200
isColorRequest = false;
11931201
} else if(device.isOnFirstDim() && isDimRequest && device.getDeviceState().isOn()) {
11941202
if(device.getDeviceState().getBri() == theStateChanges.getBri()) {
11951203
isOnRequest = true;
1204+
theStateChanges.setOn(true);
11961205
isDimRequest = false;
11971206
isColorRequest = false;
11981207
} else {
@@ -1334,10 +1343,10 @@ private String changeGroupState(String userId, String groupId, String body, Stri
13341343

13351344
if (group != null) {
13361345
if (body.contains("\"bri_inc\"")) {
1337-
targetBriInc = new Integer(theStateChanges.getBri_inc());
1346+
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
13381347
}
13391348
else if (body.contains("\"bri\"")) {
1340-
targetBri = new Integer(theStateChanges.getBri());
1349+
targetBri = Integer.valueOf(theStateChanges.getBri());
13411350
}
13421351

13431352
state = group.getAction();

src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import java.util.List;
1212
import java.util.Map;
1313

14-
import javax.xml.bind.DatatypeConverter;
15-
1614
import org.slf4j.Logger;
1715
import org.slf4j.LoggerFactory;
1816

@@ -28,6 +26,7 @@
2826
import com.bwssystems.HABridge.hue.DeviceDataDecode;
2927
import com.bwssystems.HABridge.hue.MultiCommandUtil;
3028
import com.bwssystems.HABridge.hue.TimeDecode;
29+
import com.bwssystems.HABridge.util.HexLibrary;
3130
import com.github.mob41.blapi.BLDevice;
3231
import com.github.mob41.blapi.MP1Device;
3332
import com.github.mob41.blapi.SP1Device;
@@ -118,7 +117,7 @@ public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String
118117

119118
if (theDevice == null) {
120119
if(broadlinkCommand.hasIpAndMac()) {
121-
byte[] intBytes = DatatypeConverter.parseHexBinary(broadlinkCommand.getType());
120+
byte[] intBytes = HexLibrary.decodeHexString(broadlinkCommand.getType());
122121
BigInteger theBig = new BigInteger(intBytes);
123122
int theType = theBig.intValue();
124123
try {
@@ -218,13 +217,13 @@ public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String
218217
}
219218
theStringData = DeviceDataDecode.replaceDeviceData(theStringData, device);
220219
theStringData = TimeDecode.replaceTimeValue(theStringData);
221-
byte[] theData = DatatypeConverter.parseHexBinary(theStringData);
220+
byte[] theData = HexLibrary.decodeHexString(theStringData);
222221
SendDataCmdPayload thePayload = new SendDataCmdPayload(theData);
223222

224223
DatagramPacket thePacket = theDevice.sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload);
225224
String returnData = null;
226225
if(thePacket != null)
227-
returnData = DatatypeConverter.printHexBinary(thePacket.getData());
226+
returnData = HexLibrary.encodeHexString(thePacket.getData());
228227
else
229228
returnData = "No Data - null";
230229
log.debug("RM2 Device data return: <<<" + returnData + ">>>");

src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestBLDevice.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.net.DatagramPacket;
55
import java.net.InetAddress;
66

7-
import javax.xml.bind.DatatypeConverter;
7+
import com.bwssystems.HABridge.util.HexLibrary;
88

99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
@@ -33,7 +33,7 @@ public void setPower(boolean aState) {
3333
}
3434

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

0 commit comments

Comments
 (0)