]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt.generic] fix range of RGB values (#13426)
authorCody Cutrer <cody@cutrer.us>
Mon, 26 Sep 2022 17:03:37 +0000 (11:03 -0600)
committerGitHub <noreply@github.com>
Mon, 26 Sep 2022 17:03:37 +0000 (19:03 +0200)
Range is 0..255, not 0..250.

rgb -> hsv -> rgb still isn't perfect, but it's better. In
particular, I found this when using HSBType.BLUE in a test,
and it was coming out as 0,0,250 in RGB. It now comes out as
a proper 0,0,255.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/ColorValue.java
bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/ChannelStateTests.java

index df8ac688809645ed1e8838d01506761a5788eac5..9c6c9db57ed4ab60c23b5096141537e7c02b3ae3 100644 (file)
@@ -46,6 +46,8 @@ import org.slf4j.LoggerFactory;
  */
 @NonNullByDefault
 public class ColorValue extends Value {
+    private static BigDecimal factor = new BigDecimal("2.55"); // string to not lose precision
+
     private final Logger logger = LoggerFactory.getLogger(ColorValue.class);
 
     private final ColorMode colorMode;
@@ -120,8 +122,6 @@ public class ColorValue extends Value {
         }
     }
 
-    private static BigDecimal factor = new BigDecimal(2.5);
-
     /**
      * Converts the color state to a string.
      *
index 338b43a7118f341ecba31891788a490c315dc845..ca1955dbf7c3e56c57c4ca9f33f894223d549098 100644 (file)
@@ -261,8 +261,8 @@ public class ChannelStateTests {
         c.processMessage("state", "12,18,231".getBytes());
         assertThat(value.getChannelState(), is(t)); // HSB
         // rgb -> hsv -> rgb is quite lossy
-        assertThat(value.getMQTTpublishValue(null), is("13,20,225"));
-        assertThat(value.getMQTTpublishValue("%3$d,%2$d,%1$d"), is("225,20,13"));
+        assertThat(value.getMQTTpublishValue(null), is("13,20,229"));
+        assertThat(value.getMQTTpublishValue("%3$d,%2$d,%1$d"), is("229,20,13"));
     }
 
     @Test