diff --git a/README.md b/README.md index 7f6eea28..3fab54ab 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.3.1RC3.jar +java -jar ha-bridge-5.3.1RC5.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.3.1RC3.jar is in your /home/pi/ha-bridge directory. +Create the directory and make sure that ha-bridge-5.3.1RC5.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.3.1RC3/ha-bridge-5.3.1RC3.jar +pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.3.1RC5/ha-bridge-5.3.1RC5.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.3.1RC3.jar +ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.3.1RC5.jar [Install] WantedBy=multi-user.target diff --git a/pom.xml b/pom.xml index 0fd9cc19..9d46c6db 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.3.1RC4-java11 + 5.3.1RC5-java11 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java index 1af0d295..f67e7a0e 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java @@ -200,7 +200,10 @@ public void buildSettings() { theBridgeSettings.setNumberoflogmessages(Integer.valueOf(Configuration.NUMBER_OF_LOG_MESSAGES)); if(theBridgeSettings.getButtonsleep() == null || theBridgeSettings.getButtonsleep() < 0) - theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP)); + theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP)); + + if(theBridgeSettings.getLinkbuttontimeout() < 30) + theBridgeSettings.setLinkbuttontimeout(Configuration.LINK_BUTTON_TIMEOUT); theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera()); theBridgeSettings.setFibaroconfigured(theBridgeSettings.isValidFibaro()); diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java index e7140385..a5727689 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java @@ -135,6 +135,10 @@ public class BridgeSettingsDescriptor { @SerializedName("upnpadvanced") @Expose private boolean upnpadvanced; + @SerializedName("linkbuttontimeout") + @Expose + private Integer linkbuttontimeout; + // @SerializedName("activeloggers") // @Expose // private List activeloggers; @@ -197,6 +201,7 @@ public BridgeSettingsDescriptor() { this.haaddressessecured = false; this.configfile = Configuration.CONFIG_FILE; this.upnpadvanced = false; + this.linkbuttontimeout = Configuration.LINK_BUTTON_TIMEOUT; } public String getUpnpConfigAddress() { @@ -860,4 +865,12 @@ public boolean isUpnpadvanced() { public void setUpnpadvanced(boolean upnpadvanced) { this.upnpadvanced = upnpadvanced; } + + public Integer getLinkbuttontimeout() { + return linkbuttontimeout; + } + + public void setLinkbuttontimeout(Integer linkbuttontimeout) { + this.linkbuttontimeout = linkbuttontimeout; + } } diff --git a/src/main/java/com/bwssystems/HABridge/Configuration.java b/src/main/java/com/bwssystems/HABridge/Configuration.java index 7ad5ad8c..c82a4b77 100644 --- a/src/main/java/com/bwssystems/HABridge/Configuration.java +++ b/src/main/java/com/bwssystems/HABridge/Configuration.java @@ -17,4 +17,5 @@ public class Configuration { public static final int UPNP_SEND_DELAY = 650; public static final int BROADLINK_DISCOVER_PORT = 40000; public static final int BROADLINK_DISCONVER_TIMEOUT = 5000; + public static final int LINK_BUTTON_TIMEOUT = 45; } diff --git a/src/main/java/com/bwssystems/HABridge/SystemControl.java b/src/main/java/com/bwssystems/HABridge/SystemControl.java index 1393a0af..f4c4cf93 100644 --- a/src/main/java/com/bwssystems/HABridge/SystemControl.java +++ b/src/main/java/com/bwssystems/HABridge/SystemControl.java @@ -276,12 +276,12 @@ public void setupServer() { if(!request.body().isEmpty()) { linkParams = new Gson().fromJson(request.body(), LinkParams.class); if(linkParams.getSeconds() <= 0) - linkParams.setSeconds(1); + linkParams.setSeconds(3); } else { linkParams = new LinkParams(); linkParams.setSilent(false); - linkParams.setSeconds(30); + linkParams.setSeconds(bridgeSettings.getBridgeSettingsDescriptor().getLinkbuttontimeout()); } if(!linkParams.isSilent()) log.info("Link button pressed...."); diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java index b52e99f6..4199d2dc 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java @@ -95,6 +95,9 @@ public class DeviceDescriptor{ @SerializedName("dimNoOn") @Expose private boolean dimNoOn; + @SerializedName("dimOnColor") + @Expose + private boolean dimOnColor; public String getName() { return name; @@ -366,4 +369,12 @@ public boolean isDimNoOn() { public void setDimNoOn(boolean dimNoOn) { this.dimNoOn = dimNoOn; } + + public boolean isDimOnColor() { + return dimOnColor; + } + + public void setDimOnColor(boolean dimOnColor) { + this.dimOnColor = dimOnColor; + } } \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java index 276b08a1..ce0a7016 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java @@ -21,6 +21,9 @@ public class BrightnessDecode { private static final String INTENSITY_MATH_CLOSE_HEX = ").hex}"; private static final String INTENSITY_PERCENT_HEX = "${intensity.percent.hex}"; private static final String INTENSITY_BYTE_HEX = "${intensity.byte.hex}"; + private static final String INTENSITY_PREVIOUS_PERCENT = "${intensity.previous_percent}"; + private static final String INTENSITY_PREVIOUS_DECIMAL_PERCENT = "${intensity.previous_decimal_percent}"; + private static final String INTENSITY_PREVIOUS_BYTE = "${intensity.previous_byte}"; public static int calculateIntensity(int setIntensity, Integer targetBri, Integer targetBriInc) { if (targetBri != null) { @@ -45,7 +48,7 @@ else if ((setIntensity + targetBriInc) > 254) * intensity.math(X*1) : where X is the value from the interface call and * can use net.java.dev.eval math */ - public static String replaceIntensityValue(String request, int intensity, boolean isHex) { + private static String replaceIntensityValue(String request, int previous_intensity, int intensity, boolean isHex) { if (request == null) { return null; } @@ -54,6 +57,8 @@ public static String replaceIntensityValue(String request, int intensity, boolea String replaceTarget = null; int percentBrightness = 0; float decimalBrightness = (float) 1.0; + int previousPercentBrightness = 0; + float previousDecimalBrightness = (float) 1.0; Map variables = new HashMap(); String mathDescriptor = null; @@ -68,6 +73,17 @@ public static String replaceIntensityValue(String request, int intensity, boolea percentBrightness = 1; } + if(previous_intensity > 0) { + previousDecimalBrightness = (float) (previous_intensity / 255.0); + if(previous_intensity > 0 && previous_intensity < 5) + previousPercentBrightness = 1; + else + previousPercentBrightness = (int) Math.round(previous_intensity / 255.0 * 100); + } else { + previousDecimalBrightness = (float) 1.0; + previousPercentBrightness = 1; + } + while(notDone) { notDone = false; if (request.contains(INTENSITY_BYTE)) { @@ -78,6 +94,14 @@ public static String replaceIntensityValue(String request, int intensity, boolea } replaceTarget = INTENSITY_BYTE; notDone = true; + } else if (request.contains(INTENSITY_PREVIOUS_BYTE)) { + if (isHex) { + replaceValue = convertToHex(previous_intensity); + } else { + replaceValue = String.valueOf(previous_intensity); + } + replaceTarget = INTENSITY_PREVIOUS_BYTE; + notDone = true; } else if (request.contains(INTENSITY_BYTE_HEX)) { replaceValue = convertToHex(intensity); replaceTarget = INTENSITY_BYTE_HEX; @@ -90,6 +114,14 @@ public static String replaceIntensityValue(String request, int intensity, boolea } replaceTarget = INTENSITY_PERCENT; notDone = true; + } else if (request.contains(INTENSITY_PREVIOUS_PERCENT)) { + if (isHex) { + replaceValue = convertToHex(previousPercentBrightness); + } else { + replaceValue = String.valueOf(previousPercentBrightness); + } + replaceTarget = INTENSITY_PREVIOUS_PERCENT; + notDone = true; } else if (request.contains(INTENSITY_PERCENT_HEX)) { replaceValue = convertToHex(percentBrightness); replaceTarget = INTENSITY_PERCENT_HEX; @@ -98,6 +130,10 @@ public static String replaceIntensityValue(String request, int intensity, boolea replaceValue = String.format(Locale.ROOT, "%1.2f", decimalBrightness); replaceTarget = INTENSITY_DECIMAL_PERCENT; notDone = true; + } else if (request.contains(INTENSITY_PREVIOUS_DECIMAL_PERCENT)) { + replaceValue = String.format(Locale.ROOT, "%1.2f", previousDecimalBrightness); + replaceTarget = INTENSITY_PREVIOUS_DECIMAL_PERCENT; + notDone = true; } else if (request.contains(INTENSITY_MATH_CLOSE)) { mathDescriptor = request.substring(request.indexOf(INTENSITY_MATH) + INTENSITY_MATH.length(), request.indexOf(INTENSITY_MATH_CLOSE)); @@ -135,7 +171,7 @@ public static String replaceIntensityValue(String request, int intensity, boolea // Helper Method public static String calculateReplaceIntensityValue(String request, int theIntensity, Integer targetBri, Integer targetBriInc, boolean isHex) { - return replaceIntensityValue(request, calculateIntensity(theIntensity, targetBri, targetBriInc), isHex); + return replaceIntensityValue(request, theIntensity, calculateIntensity(theIntensity, targetBri, targetBriInc), isHex); } // Apache Commons Conversion utils likes little endian too much diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index a136a388..283892fb 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -1250,6 +1250,9 @@ private String changeState(String userId, String lightId, String body, String ip } } + if(isColorRequest && isDimRequest && !device.isDimOnColor()) { + isDimRequest = false; + } /* Old code supperceded by the above block if (!device.isOnFirstDim() && device.isOnWhenDimPresent() && isDimRequest && !isOnRequest) { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java index 090f45d1..ca8e863a 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java @@ -139,8 +139,7 @@ public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String hassCommand = aGsonHandler.fromJson(anItem.getItem(), HassCommand.class); else hassCommand = aGsonHandler.fromJson(anItem.getItem().getAsString().replaceAll("^\"|\"$", ""), HassCommand.class); - hassCommand.setBri(BrightnessDecode.replaceIntensityValue(hassCommand.getBri(), - BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false)); + hassCommand.setBri(BrightnessDecode.calculateReplaceIntensityValue(hassCommand.getBri(), intensity, targetBri, targetBriInc, false)); HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName()); if (homeAssistant == null) { log.warn("Should not get here, no HomeAssistants available"); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index a67ea1b1..f53175f1 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -479,7 +479,7 @@ app.service('bridgeService', function ($rootScope, $http, $base64, $location, ng this.pushLinkButton = function () { return $http.put(this.state.systemsbase + "/presslinkbutton").then( function (response) { - self.displayTimer("Link your device", 30000); + self.displayTimer("Link your device", self.state.settings.linkbuttontimeout * 1000); }, function (error) { if (error.status === 401) diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 9630f4ae..f6474a7a 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -120,6 +120,12 @@

Edit/Copy a device

ng-model="device.dimNoOn" ng-true-value=true ng-false-value=false> {{device.dimNoOn}} + + + {{device.dimOnColor}} + Bridge Settings + + Link Button Timeout (seconds) + + ID Seed (start numbering from this value)