Skip to content

Commit 675e74d

Browse files
committed
Add switch for dim when color request is present and other items
1 parent fb7aabb commit 675e74d

File tree

13 files changed

+90
-13
lines changed

13 files changed

+90
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ Then locate the jar and start the server with:
5757
ATTENTION: Due to port 80 being the default, Linux restricts this to super user. Use the instructions below.
5858

5959
```
60-
java -jar ha-bridge-5.3.1RC3.jar
60+
java -jar ha-bridge-5.3.1RC5.jar
6161
```
6262

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

67-
Create the directory and make sure that ha-bridge-5.3.1RC3.jar is in your /home/pi/ha-bridge directory.
67+
Create the directory and make sure that ha-bridge-5.3.1RC5.jar is in your /home/pi/ha-bridge directory.
6868

6969
```
7070
pi@raspberrypi:~ $ mkdir ha-bridge
7171
pi@raspberrypi:~ $ cd ha-bridge
7272
73-
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.3.1RC3/ha-bridge-5.3.1RC3.jar
73+
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.3.1RC5/ha-bridge-5.3.1RC5.jar
7474
```
7575

7676
Create the ha-bridge.service unit file:
@@ -89,7 +89,7 @@ After=network.target
8989
Type=simple
9090
9191
WorkingDirectory=/home/pi/ha-bridge
92-
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.3.1RC3.jar
92+
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.3.1RC5.jar
9393
9494
[Install]
9595
WantedBy=multi-user.target

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bwssystems.HABridge</groupId>
77
<artifactId>ha-bridge</artifactId>
8-
<version>5.3.1RC4-java11</version>
8+
<version>5.3.1RC5-java11</version>
99
<packaging>jar</packaging>
1010

1111
<name>HA Bridge</name>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ public void buildSettings() {
200200
theBridgeSettings.setNumberoflogmessages(Integer.valueOf(Configuration.NUMBER_OF_LOG_MESSAGES));
201201

202202
if(theBridgeSettings.getButtonsleep() == null || theBridgeSettings.getButtonsleep() < 0)
203-
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));
203+
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));
204+
205+
if(theBridgeSettings.getLinkbuttontimeout() < 30)
206+
theBridgeSettings.setLinkbuttontimeout(Configuration.LINK_BUTTON_TIMEOUT);
204207

205208
theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera());
206209
theBridgeSettings.setFibaroconfigured(theBridgeSettings.isValidFibaro());

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public class BridgeSettingsDescriptor {
135135
@SerializedName("upnpadvanced")
136136
@Expose
137137
private boolean upnpadvanced;
138+
@SerializedName("linkbuttontimeout")
139+
@Expose
140+
private Integer linkbuttontimeout;
141+
138142
// @SerializedName("activeloggers")
139143
// @Expose
140144
// private List<NameValue> activeloggers;
@@ -197,6 +201,7 @@ public BridgeSettingsDescriptor() {
197201
this.haaddressessecured = false;
198202
this.configfile = Configuration.CONFIG_FILE;
199203
this.upnpadvanced = false;
204+
this.linkbuttontimeout = Configuration.LINK_BUTTON_TIMEOUT;
200205
}
201206

202207
public String getUpnpConfigAddress() {
@@ -860,4 +865,12 @@ public boolean isUpnpadvanced() {
860865
public void setUpnpadvanced(boolean upnpadvanced) {
861866
this.upnpadvanced = upnpadvanced;
862867
}
868+
869+
public Integer getLinkbuttontimeout() {
870+
return linkbuttontimeout;
871+
}
872+
873+
public void setLinkbuttontimeout(Integer linkbuttontimeout) {
874+
this.linkbuttontimeout = linkbuttontimeout;
875+
}
863876
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class Configuration {
1717
public static final int UPNP_SEND_DELAY = 650;
1818
public static final int BROADLINK_DISCOVER_PORT = 40000;
1919
public static final int BROADLINK_DISCONVER_TIMEOUT = 5000;
20+
public static final int LINK_BUTTON_TIMEOUT = 45;
2021
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ public void setupServer() {
276276
if(!request.body().isEmpty()) {
277277
linkParams = new Gson().fromJson(request.body(), LinkParams.class);
278278
if(linkParams.getSeconds() <= 0)
279-
linkParams.setSeconds(1);
279+
linkParams.setSeconds(3);
280280
}
281281
else {
282282
linkParams = new LinkParams();
283283
linkParams.setSilent(false);
284-
linkParams.setSeconds(30);
284+
linkParams.setSeconds(bridgeSettings.getBridgeSettingsDescriptor().getLinkbuttontimeout());
285285
}
286286
if(!linkParams.isSilent())
287287
log.info("Link button pressed....");

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public class DeviceDescriptor{
9595
@SerializedName("dimNoOn")
9696
@Expose
9797
private boolean dimNoOn;
98+
@SerializedName("dimOnColor")
99+
@Expose
100+
private boolean dimOnColor;
98101

99102
public String getName() {
100103
return name;
@@ -366,4 +369,12 @@ public boolean isDimNoOn() {
366369
public void setDimNoOn(boolean dimNoOn) {
367370
this.dimNoOn = dimNoOn;
368371
}
372+
373+
public boolean isDimOnColor() {
374+
return dimOnColor;
375+
}
376+
377+
public void setDimOnColor(boolean dimOnColor) {
378+
this.dimOnColor = dimOnColor;
379+
}
369380
}

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class BrightnessDecode {
2121
private static final String INTENSITY_MATH_CLOSE_HEX = ").hex}";
2222
private static final String INTENSITY_PERCENT_HEX = "${intensity.percent.hex}";
2323
private static final String INTENSITY_BYTE_HEX = "${intensity.byte.hex}";
24+
private static final String INTENSITY_PREVIOUS_PERCENT = "${intensity.previous_percent}";
25+
private static final String INTENSITY_PREVIOUS_DECIMAL_PERCENT = "${intensity.previous_decimal_percent}";
26+
private static final String INTENSITY_PREVIOUS_BYTE = "${intensity.previous_byte}";
2427

2528
public static int calculateIntensity(int setIntensity, Integer targetBri, Integer targetBriInc) {
2629
if (targetBri != null) {
@@ -45,7 +48,7 @@ else if ((setIntensity + targetBriInc) > 254)
4548
* intensity.math(X*1) : where X is the value from the interface call and
4649
* can use net.java.dev.eval math
4750
*/
48-
public static String replaceIntensityValue(String request, int intensity, boolean isHex) {
51+
private static String replaceIntensityValue(String request, int previous_intensity, int intensity, boolean isHex) {
4952
if (request == null) {
5053
return null;
5154
}
@@ -54,6 +57,8 @@ public static String replaceIntensityValue(String request, int intensity, boolea
5457
String replaceTarget = null;
5558
int percentBrightness = 0;
5659
float decimalBrightness = (float) 1.0;
60+
int previousPercentBrightness = 0;
61+
float previousDecimalBrightness = (float) 1.0;
5762
Map<String, BigDecimal> variables = new HashMap<String, BigDecimal>();
5863
String mathDescriptor = null;
5964

@@ -68,6 +73,17 @@ public static String replaceIntensityValue(String request, int intensity, boolea
6873
percentBrightness = 1;
6974
}
7075

76+
if(previous_intensity > 0) {
77+
previousDecimalBrightness = (float) (previous_intensity / 255.0);
78+
if(previous_intensity > 0 && previous_intensity < 5)
79+
previousPercentBrightness = 1;
80+
else
81+
previousPercentBrightness = (int) Math.round(previous_intensity / 255.0 * 100);
82+
} else {
83+
previousDecimalBrightness = (float) 1.0;
84+
previousPercentBrightness = 1;
85+
}
86+
7187
while(notDone) {
7288
notDone = false;
7389
if (request.contains(INTENSITY_BYTE)) {
@@ -78,6 +94,14 @@ public static String replaceIntensityValue(String request, int intensity, boolea
7894
}
7995
replaceTarget = INTENSITY_BYTE;
8096
notDone = true;
97+
} else if (request.contains(INTENSITY_PREVIOUS_BYTE)) {
98+
if (isHex) {
99+
replaceValue = convertToHex(previous_intensity);
100+
} else {
101+
replaceValue = String.valueOf(previous_intensity);
102+
}
103+
replaceTarget = INTENSITY_PREVIOUS_BYTE;
104+
notDone = true;
81105
} else if (request.contains(INTENSITY_BYTE_HEX)) {
82106
replaceValue = convertToHex(intensity);
83107
replaceTarget = INTENSITY_BYTE_HEX;
@@ -90,6 +114,14 @@ public static String replaceIntensityValue(String request, int intensity, boolea
90114
}
91115
replaceTarget = INTENSITY_PERCENT;
92116
notDone = true;
117+
} else if (request.contains(INTENSITY_PREVIOUS_PERCENT)) {
118+
if (isHex) {
119+
replaceValue = convertToHex(previousPercentBrightness);
120+
} else {
121+
replaceValue = String.valueOf(previousPercentBrightness);
122+
}
123+
replaceTarget = INTENSITY_PREVIOUS_PERCENT;
124+
notDone = true;
93125
} else if (request.contains(INTENSITY_PERCENT_HEX)) {
94126
replaceValue = convertToHex(percentBrightness);
95127
replaceTarget = INTENSITY_PERCENT_HEX;
@@ -98,6 +130,10 @@ public static String replaceIntensityValue(String request, int intensity, boolea
98130
replaceValue = String.format(Locale.ROOT, "%1.2f", decimalBrightness);
99131
replaceTarget = INTENSITY_DECIMAL_PERCENT;
100132
notDone = true;
133+
} else if (request.contains(INTENSITY_PREVIOUS_DECIMAL_PERCENT)) {
134+
replaceValue = String.format(Locale.ROOT, "%1.2f", previousDecimalBrightness);
135+
replaceTarget = INTENSITY_PREVIOUS_DECIMAL_PERCENT;
136+
notDone = true;
101137
} else if (request.contains(INTENSITY_MATH_CLOSE)) {
102138
mathDescriptor = request.substring(request.indexOf(INTENSITY_MATH) + INTENSITY_MATH.length(),
103139
request.indexOf(INTENSITY_MATH_CLOSE));
@@ -135,7 +171,7 @@ public static String replaceIntensityValue(String request, int intensity, boolea
135171

136172
// Helper Method
137173
public static String calculateReplaceIntensityValue(String request, int theIntensity, Integer targetBri, Integer targetBriInc, boolean isHex) {
138-
return replaceIntensityValue(request, calculateIntensity(theIntensity, targetBri, targetBriInc), isHex);
174+
return replaceIntensityValue(request, theIntensity, calculateIntensity(theIntensity, targetBri, targetBriInc), isHex);
139175
}
140176

141177
// Apache Commons Conversion utils likes little endian too much

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,9 @@ private String changeState(String userId, String lightId, String body, String ip
12501250
}
12511251
}
12521252

1253+
if(isColorRequest && isDimRequest && !device.isDimOnColor()) {
1254+
isDimRequest = false;
1255+
}
12531256

12541257
/* Old code supperceded by the above block
12551258
if (!device.isOnFirstDim() && device.isOnWhenDimPresent() && isDimRequest && !isOnRequest) {

src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String
139139
hassCommand = aGsonHandler.fromJson(anItem.getItem(), HassCommand.class);
140140
else
141141
hassCommand = aGsonHandler.fromJson(anItem.getItem().getAsString().replaceAll("^\"|\"$", ""), HassCommand.class);
142-
hassCommand.setBri(BrightnessDecode.replaceIntensityValue(hassCommand.getBri(),
143-
BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false));
142+
hassCommand.setBri(BrightnessDecode.calculateReplaceIntensityValue(hassCommand.getBri(), intensity, targetBri, targetBriInc, false));
144143
HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName());
145144
if (homeAssistant == null) {
146145
log.warn("Should not get here, no HomeAssistants available");

0 commit comments

Comments
 (0)