Add option to set hue uid to 9 octets

This commit is contained in:
crush157
2021-03-24 14:31:11 -04:00
parent b3f2c25721
commit 7f72b0311a
6 changed files with 52 additions and 20 deletions

View File

@@ -57,20 +57,20 @@ Then locate the jar and start the server with:
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-5.4.0.jar java -jar ha-bridge-5.4.1.jar
``` ```
## Manual installation of ha-bridge and setup of systemd service ## 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. 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 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.4.0.jar is in your /home/pi/ha-bridge directory. Create the directory and make sure that ha-bridge-5.4.1.jar is in your /home/pi/ha-bridge directory.
``` ```
pi@raspberrypi:~ $ mkdir ha-bridge pi@raspberrypi:~ $ mkdir ha-bridge
pi@raspberrypi:~ $ cd ha-bridge pi@raspberrypi:~ $ cd ha-bridge
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.4.0/ha-bridge-5.4.0.jar pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.4.1/ha-bridge-5.4.1.jar
``` ```
Create the ha-bridge.service unit file: Create the ha-bridge.service unit file:
@@ -89,7 +89,7 @@ After=network.target
Type=simple Type=simple
WorkingDirectory=/home/pi/ha-bridge 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.4.0.jar ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.4.1.jar
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

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>5.4.0-java11</version> <version>5.4.1RC1-java11</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>

View File

@@ -138,6 +138,9 @@ public class BridgeSettingsDescriptor {
@SerializedName("linkbuttontimeout") @SerializedName("linkbuttontimeout")
@Expose @Expose
private Integer linkbuttontimeout; private Integer linkbuttontimeout;
@SerializedName("uidnineoctets")
@Expose
private boolean uidnineoctets;
// @SerializedName("activeloggers") // @SerializedName("activeloggers")
// @Expose // @Expose
@@ -202,6 +205,7 @@ public class BridgeSettingsDescriptor {
this.configfile = Configuration.CONFIG_FILE; this.configfile = Configuration.CONFIG_FILE;
this.upnpadvanced = false; this.upnpadvanced = false;
this.linkbuttontimeout = Configuration.LINK_BUTTON_TIMEOUT; this.linkbuttontimeout = Configuration.LINK_BUTTON_TIMEOUT;
this.uidnineoctets = false;
} }
public String getUpnpConfigAddress() { public String getUpnpConfigAddress() {
@@ -873,4 +877,12 @@ public class BridgeSettingsDescriptor {
public void setLinkbuttontimeout(Integer linkbuttontimeout) { public void setLinkbuttontimeout(Integer linkbuttontimeout) {
this.linkbuttontimeout = linkbuttontimeout; this.linkbuttontimeout = linkbuttontimeout;
} }
public boolean isUidnineoctets() {
return uidnineoctets;
}
public void setUidnineoctets(boolean uidnineoctets) {
this.uidnineoctets = uidnineoctets;
}
} }

View File

@@ -18,7 +18,7 @@ import com.bwssystems.HABridge.DeviceMapTypes;
import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.api.CallItem;
import com.bwssystems.HABridge.api.hue.DeviceResponse; import com.bwssystems.HABridge.api.hue.DeviceResponse;
import com.bwssystems.HABridge.api.hue.DeviceState; import com.bwssystems.HABridge.api.hue.DeviceState;
import com.bwssystems.HABridge.dao.DeviceDescriptor; // import com.bwssystems.HABridge.dao.DeviceDescriptor;
import com.bwssystems.HABridge.plugins.hue.HueHome; import com.bwssystems.HABridge.plugins.hue.HueHome;
import com.bwssystems.HABridge.util.BackupHandler; import com.bwssystems.HABridge.util.BackupHandler;
import com.bwssystems.HABridge.util.JsonTransformer; import com.bwssystems.HABridge.util.JsonTransformer;
@@ -43,9 +43,10 @@ public class DeviceRepository extends BackupHandler {
private Gson gson; private Gson gson;
private Integer nextId; private Integer nextId;
private Integer seedId; private Integer seedId;
private boolean uidnineoctets;
private Logger log = LoggerFactory.getLogger(DeviceRepository.class); private Logger log = LoggerFactory.getLogger(DeviceRepository.class);
public DeviceRepository(String deviceDb, Integer seedid) { public DeviceRepository(String deviceDb, Integer seedid, boolean uidnineoctets_setting) {
super(); super();
gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
repositoryPath = null; repositoryPath = null;
@@ -53,6 +54,7 @@ public class DeviceRepository extends BackupHandler {
setupParams(repositoryPath, ".bk", "device.db-"); setupParams(repositoryPath, ".bk", "device.db-");
nextId = seedid; nextId = seedid;
seedId = seedid; seedId = seedid;
uidnineoctets = uidnineoctets_setting;
_loadRepository(repositoryPath); _loadRepository(repositoryPath);
} }
@@ -311,22 +313,35 @@ public class DeviceRepository extends BackupHandler {
log.warn("Cannot get MD5 utility to hash unique ids."); log.warn("Cannot get MD5 utility to hash unique ids.");
} }
if(md != null) { if (md != null) {
md.update(anId.toString().getBytes()); md.update(anId.toString().getBytes());
byte[] digest = md.digest(); byte[] digest = md.digest();
theUniqueId = String.format("%s:%s:%s:%s:%s:%s:%s-%s", if (uidnineoctets) {
HexLibrary.encodeHexString(digest).substring(0, 2), theUniqueId = String.format("00:%s:%s:%s:%s:%s:%s:%s-%s",
HexLibrary.encodeHexString(digest).substring(2, 4), HexLibrary.encodeHexString(digest).substring(0, 2),
HexLibrary.encodeHexString(digest).substring(4, 6), HexLibrary.encodeHexString(digest).substring(2, 4),
HexLibrary.encodeHexString(digest).substring(6, 8), HexLibrary.encodeHexString(digest).substring(4, 6),
HexLibrary.encodeHexString(digest).substring(8, 10), HexLibrary.encodeHexString(digest).substring(6, 8),
HexLibrary.encodeHexString(digest).substring(10, 12), HexLibrary.encodeHexString(digest).substring(8, 10),
HexLibrary.encodeHexString(digest).substring(12, 14), HexLibrary.encodeHexString(digest).substring(10, 12),
HexLibrary.encodeHexString(digest).substring(14, 16)); HexLibrary.encodeHexString(digest).substring(12, 14),
HexLibrary.encodeHexString(digest).substring(14, 16));
} else {
theUniqueId = String.format("%s:%s:%s:%s:%s:%s:%s-%s",
HexLibrary.encodeHexString(digest).substring(0, 2),
HexLibrary.encodeHexString(digest).substring(2, 4),
HexLibrary.encodeHexString(digest).substring(4, 6),
HexLibrary.encodeHexString(digest).substring(6, 8),
HexLibrary.encodeHexString(digest).substring(8, 10),
HexLibrary.encodeHexString(digest).substring(10, 12),
HexLibrary.encodeHexString(digest).substring(12, 14),
HexLibrary.encodeHexString(digest).substring(14, 16));
}
} }
if (theUniqueId == null) {
if(theUniqueId == null) {
newValue = anId % 256; newValue = anId % 256;
if (newValue <= 0) if (newValue <= 0)
newValue = 1; newValue = 1;

View File

@@ -48,7 +48,7 @@ public class DeviceResource {
public DeviceResource(BridgeSettings theSettings, HomeManager aHomeManager) { public DeviceResource(BridgeSettings theSettings, HomeManager aHomeManager) {
bridgeSettings = theSettings; bridgeSettings = theSettings;
this.deviceRepository = new DeviceRepository(bridgeSettings.getBridgeSettingsDescriptor().getUpnpDeviceDb(), bridgeSettings.getBridgeSettingsDescriptor().getSeedid()); this.deviceRepository = new DeviceRepository(bridgeSettings.getBridgeSettingsDescriptor().getUpnpDeviceDb(), bridgeSettings.getBridgeSettingsDescriptor().getSeedid(), bridgeSettings.getBridgeSettingsDescriptor().isUidnineoctets());
this.groupRepository = new GroupRepository(bridgeSettings.getBridgeSettingsDescriptor().getUpnpGroupDb()); this.groupRepository = new GroupRepository(bridgeSettings.getBridgeSettingsDescriptor().getUpnpGroupDb());
homeManager = aHomeManager; homeManager = aHomeManager;
aGsonHandler = new GsonBuilder().create(); aGsonHandler = new GsonBuilder().create();

View File

@@ -829,6 +829,11 @@
<td><input type="checkbox" ng-model="bridge.settings.upnpadvanced" ng-true-value=true <td><input type="checkbox" ng-model="bridge.settings.upnpadvanced" ng-true-value=true
ng-false-value=false> {{bridge.settings.upnpadvanced}}</td> ng-false-value=false> {{bridge.settings.upnpadvanced}}</td>
</tr> </tr>
<tr>
<td>Unique ID to use 9 Octets (Renumber after saving this setting)</td>
<td><input type="checkbox" ng-model="bridge.settings.uidnineoctets" ng-true-value=true
ng-false-value=false> {{bridge.settings.uidnineoctets}}</td>
</tr>
<tr> <tr>
<td>Trace UPNP Calls</td> <td>Trace UPNP Calls</td>
<td><input type="checkbox" ng-model="bridge.settings.traceupnp" ng-true-value=true <td><input type="checkbox" ng-model="bridge.settings.traceupnp" ng-true-value=true