[WLED] Fix brightness handling for HSBType (Fixes #9836) (#9863)

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

Signed-off-by: Sebastian Garske <sebgarske@gmail.com>
pull/10049/head
Sebastian Garske 2021-02-04 07:08:21 +01:00 committed by GitHub
parent bd949518de
commit d6fe0e1328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -29,6 +29,7 @@ public class WLedBindingConstants {
public static final String BINDING_ID = "wled"; 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_2_55 = new BigDecimal(2.55);
public static final BigDecimal BIG_DECIMAL_182_04 = new BigDecimal(182.04);
// List of all Thing Type UIDs // List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_WLED = new ThingTypeUID(BINDING_ID, "wled"); public static final ThingTypeUID THING_TYPE_WLED = new ThingTypeUID(BINDING_ID, "wled");

View File

@ -66,6 +66,8 @@ public class WLedHandler extends BaseThingHandler {
private final HttpClient httpClient; private final HttpClient httpClient;
private final WledDynamicStateDescriptionProvider stateDescriptionProvider; private final WledDynamicStateDescriptionProvider stateDescriptionProvider;
private @Nullable ScheduledFuture<?> pollingFuture = null; private @Nullable ScheduledFuture<?> pollingFuture = null;
private BigDecimal hue65535 = BigDecimal.ZERO;
private BigDecimal saturation255 = BigDecimal.ZERO;
private BigDecimal masterBrightness255 = BigDecimal.ZERO; private BigDecimal masterBrightness255 = BigDecimal.ZERO;
private HSBType primaryColor = new HSBType(); private HSBType primaryColor = new HSBType();
private BigDecimal primaryWhite = BigDecimal.ZERO; private BigDecimal primaryWhite = BigDecimal.ZERO;
@ -320,6 +322,8 @@ public class WLedHandler extends BaseThingHandler {
sendGetRequest("/win&TT=500&T=0"); sendGetRequest("/win&TT=500&T=0");
} }
primaryColor = (HSBType) command; 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); masterBrightness255 = primaryColor.getBrightness().toBigDecimal().multiply(BIG_DECIMAL_2_55);
if (primaryColor.getSaturation().intValue() < config.saturationThreshold) { if (primaryColor.getSaturation().intValue() < config.saturationThreshold) {
sendWhite(); sendWhite();
@ -328,8 +332,13 @@ public class WLedHandler extends BaseThingHandler {
// Google sends this when it wants white // Google sends this when it wants white
sendWhite(); sendWhite();
} else { } else {
sendGetRequest("/win&TT=1000&FX=0&CY=0&CL=" + createColorHex(primaryColor) + "&A=" if (config.segmentIndex == -1) {
+ masterBrightness255); 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) { } else if (command instanceof PercentType) {
masterBrightness255 = ((PercentType) command).toBigDecimal().multiply(BIG_DECIMAL_2_55); masterBrightness255 = ((PercentType) command).toBigDecimal().multiply(BIG_DECIMAL_2_55);