From: Cody Cutrer Date: Mon, 26 Sep 2022 17:03:37 +0000 (-0600) Subject: [mqtt.generic] fix range of RGB values (#13426) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=517fe44b3690a5f8b7d594156a9180ca4844a969;p=openhab-addons.git [mqtt.generic] fix range of RGB values (#13426) 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 --- diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/ColorValue.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/ColorValue.java index df8ac68880..9c6c9db57e 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/ColorValue.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/ColorValue.java @@ -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. * diff --git a/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/ChannelStateTests.java b/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/ChannelStateTests.java index 338b43a711..ca1955dbf7 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/ChannelStateTests.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/ChannelStateTests.java @@ -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