From 7f72b0311a3d21780fa27e168da6824861f0b706 Mon Sep 17 00:00:00 2001 From: crush157 Date: Wed, 24 Mar 2021 14:31:11 -0400 Subject: [PATCH] Add option to set hue uid to 9 octets --- README.md | 8 ++-- pom.xml | 2 +- .../HABridge/BridgeSettingsDescriptor.java | 12 ++++++ .../HABridge/dao/DeviceRepository.java | 43 +++++++++++++------ .../devicemanagmeent/DeviceResource.java | 2 +- src/main/resources/public/views/system.html | 5 +++ 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0cf49931..0d7d3d8a 100644 --- a/README.md +++ b/README.md @@ -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. ``` -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 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.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:~ $ 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: @@ -89,7 +89,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.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] WantedBy=multi-user.target diff --git a/pom.xml b/pom.xml index fead990c..5e420240 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.4.0-java11 + 5.4.1RC1-java11 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java index a5727689..665f0bfe 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java @@ -138,6 +138,9 @@ public class BridgeSettingsDescriptor { @SerializedName("linkbuttontimeout") @Expose private Integer linkbuttontimeout; + @SerializedName("uidnineoctets") + @Expose + private boolean uidnineoctets; // @SerializedName("activeloggers") // @Expose @@ -202,6 +205,7 @@ public BridgeSettingsDescriptor() { this.configfile = Configuration.CONFIG_FILE; this.upnpadvanced = false; this.linkbuttontimeout = Configuration.LINK_BUTTON_TIMEOUT; + this.uidnineoctets = false; } public String getUpnpConfigAddress() { @@ -873,4 +877,12 @@ public Integer getLinkbuttontimeout() { public void setLinkbuttontimeout(Integer linkbuttontimeout) { this.linkbuttontimeout = linkbuttontimeout; } + + public boolean isUidnineoctets() { + return uidnineoctets; + } + + public void setUidnineoctets(boolean uidnineoctets) { + this.uidnineoctets = uidnineoctets; + } } diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java index 15b2afba..a0483252 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java @@ -18,7 +18,7 @@ import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.api.hue.DeviceResponse; 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.util.BackupHandler; import com.bwssystems.HABridge.util.JsonTransformer; @@ -43,9 +43,10 @@ public class DeviceRepository extends BackupHandler { private Gson gson; private Integer nextId; private Integer seedId; + private boolean uidnineoctets; private Logger log = LoggerFactory.getLogger(DeviceRepository.class); - public DeviceRepository(String deviceDb, Integer seedid) { + public DeviceRepository(String deviceDb, Integer seedid, boolean uidnineoctets_setting) { super(); gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); repositoryPath = null; @@ -53,6 +54,7 @@ public DeviceRepository(String deviceDb, Integer seedid) { setupParams(repositoryPath, ".bk", "device.db-"); nextId = seedid; seedId = seedid; + uidnineoctets = uidnineoctets_setting; _loadRepository(repositoryPath); } @@ -311,22 +313,35 @@ private String hueUniqueId(Integer anId) { log.warn("Cannot get MD5 utility to hash unique ids."); } - if(md != null) { + if (md != null) { md.update(anId.toString().getBytes()); byte[] digest = md.digest(); - 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 (uidnineoctets) { + theUniqueId = String.format("00:%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)); + + } 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; if (newValue <= 0) newValue = 1; diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index 4a8ca49a..d75b3d8a 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -48,7 +48,7 @@ public class DeviceResource { public DeviceResource(BridgeSettings theSettings, HomeManager aHomeManager) { 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()); homeManager = aHomeManager; aGsonHandler = new GsonBuilder().create(); diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index f7fc78b5..d7c936de 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -829,6 +829,11 @@

Bridge Settings

{{bridge.settings.upnpadvanced}} + + Unique ID to use 9 Octets (Renumber after saving this setting) + {{bridge.settings.uidnineoctets}} + Trace UPNP Calls