Skip to content

Commit

Permalink
[WLED] Fix brightness handling for HSBType (Fixes openhab#9836) (open…
Browse files Browse the repository at this point in the history
…hab#9863)

* Fix brightness
* Revert to old beahaviour if segments are used
* Fix formatting
* Remove unused Var

Signed-off-by: Sebastian Garske <sebgarske@gmail.com>
Signed-off-by: John Marshall <john.marshall.au@gmail.com>
  • Loading branch information
moesfeld authored and themillhousegroup committed May 10, 2021
1 parent ae162be commit 7e3d82e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class WLedBindingConstants {

public static final String BINDING_ID = "wled";
public static final BigDecimal BIG_DECIMAL_2_55 = new BigDecimal(2.55);
public static final BigDecimal BIG_DECIMAL_182_04 = new BigDecimal(182.04);

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_WLED = new ThingTypeUID(BINDING_ID, "wled");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class WLedHandler extends BaseThingHandler {
private final HttpClient httpClient;
private final WledDynamicStateDescriptionProvider stateDescriptionProvider;
private @Nullable ScheduledFuture<?> pollingFuture = null;
private BigDecimal hue65535 = BigDecimal.ZERO;
private BigDecimal saturation255 = BigDecimal.ZERO;
private BigDecimal masterBrightness255 = BigDecimal.ZERO;
private HSBType primaryColor = new HSBType();
private BigDecimal primaryWhite = BigDecimal.ZERO;
Expand Down Expand Up @@ -320,6 +322,8 @@ public void handleCommand(ChannelUID channelUID, Command command) {
sendGetRequest("/win&TT=500&T=0");
}
primaryColor = (HSBType) command;
hue65535 = primaryColor.getHue().toBigDecimal().multiply(BIG_DECIMAL_182_04);
saturation255 = primaryColor.getSaturation().toBigDecimal().multiply(BIG_DECIMAL_2_55);
masterBrightness255 = primaryColor.getBrightness().toBigDecimal().multiply(BIG_DECIMAL_2_55);
if (primaryColor.getSaturation().intValue() < config.saturationThreshold) {
sendWhite();
Expand All @@ -328,8 +332,13 @@ public void handleCommand(ChannelUID channelUID, Command command) {
// Google sends this when it wants white
sendWhite();
} else {
sendGetRequest("/win&TT=1000&FX=0&CY=0&CL=" + createColorHex(primaryColor) + "&A="
+ masterBrightness255);
if (config.segmentIndex == -1) {
sendGetRequest("/win&TT=1000&FX=0&CY=0&HU=" + hue65535 + "&SA=" + saturation255 + "&A="
+ masterBrightness255);
} else {
sendGetRequest("/win&TT=1000&FX=0&CY=0&CL=" + createColorHex(primaryColor) + "&A="
+ masterBrightness255);
}
}
} else if (command instanceof PercentType) {
masterBrightness255 = ((PercentType) command).toBigDecimal().multiply(BIG_DECIMAL_2_55);
Expand Down

0 comments on commit 7e3d82e

Please sign in to comment.