Skip to content

Commit

Permalink
Add switch for dim when color request is present and other items
Browse files Browse the repository at this point in the history
  • Loading branch information
bwssytems committed Dec 8, 2020
1 parent fb7aabb commit 675e74d
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>5.3.1RC4-java11</version>
<version>5.3.1RC5-java11</version>
<packaging>jar</packaging>

<name>HA Bridge</name>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/bwssystems/HABridge/BridgeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public class BridgeSettingsDescriptor {
@SerializedName("upnpadvanced")
@Expose
private boolean upnpadvanced;
@SerializedName("linkbuttontimeout")
@Expose
private Integer linkbuttontimeout;

// @SerializedName("activeloggers")
// @Expose
// private List<NameValue> activeloggers;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/main/java/com/bwssystems/HABridge/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/main/java/com/bwssystems/HABridge/SystemControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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....");
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 @@ -95,6 +95,9 @@ public class DeviceDescriptor{
@SerializedName("dimNoOn")
@Expose
private boolean dimNoOn;
@SerializedName("dimOnColor")
@Expose
private boolean dimOnColor;

public String getName() {
return name;
Expand Down Expand Up @@ -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;
}
}
40 changes: 38 additions & 2 deletions src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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<String, BigDecimal> variables = new HashMap<String, BigDecimal>();
String mathDescriptor = null;

Expand All @@ -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)) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/public/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/public/views/editdevice.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ <h2 class="panel-title">Edit/Copy a device</h2>
ng-model="device.dimNoOn" ng-true-value=true
ng-false-value=false> {{device.dimNoOn}}</td>
</tr>
<tr>
<td><label>Send dim when color request present and dim present</label></td>
<td><input type="checkbox"
ng-model="device.dimOnColor" ng-true-value=true
ng-false-value=false> {{device.dimOnColor}}</td>
</tr>
<tr>
<td><label>Filter Address (comma separated list)</label></td>
<td><input type="text" class="form-control" id="device-requester-addr"
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/public/views/system.html
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,11 @@ <h1 class="panel-title">Bridge Settings</h1>
<td><input id="bridge-settings-upnpsenddelay" class="form-control" type="number"
ng-model="bridge.settings.upnpsenddelay" min="100" max="15000"></td>
</tr>
<tr>
<td>Link Button Timeout (seconds)</td>
<td><input id="bridge-settings-linkbuttontimeout" class="form-control" type="number"
ng-model="bridge.settings.linkbuttontimeout" min="30"></td>
</tr>
<tr>
<td>ID Seed (start numbering from this value)</td>
<td><input id="bridge-settings-seedid" class="form-control" type="number"
Expand Down

0 comments on commit 675e74d

Please sign in to comment.