]> git.basschouten.com Git - openhab-addons.git/commitdiff
[WLED] Fix brightness handling for HSBType (Fixes #9836) (#9863)
authorSebastian Garske <moesfeld@users.noreply.github.com>
Thu, 4 Feb 2021 06:08:21 +0000 (07:08 +0100)
committerGitHub <noreply@github.com>
Thu, 4 Feb 2021 06:08:21 +0000 (22:08 -0800)
* Fix brightness
* Revert to old beahaviour if segments are used
* Fix formatting
* Remove unused Var

Signed-off-by: Sebastian Garske <sebgarske@gmail.com>
bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/WLedBindingConstants.java
bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/WLedHandler.java

index 6a4f44c8128305daa2802e23f2406f660a909d2e..72106cea5616401fa7fa0b35215e2d5417e02c47 100644 (file)
@@ -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");
index 75c8afad5a9096981eb281a7092bcdc458857253..a3991d3649a9eb0d3a1f104d511c35febb5dfec5 100644 (file)
@@ -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;
@@ -320,6 +322,8 @@ public class WLedHandler extends BaseThingHandler {
                         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();
@@ -328,8 +332,13 @@ public class WLedHandler extends BaseThingHandler {
                         // 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);