[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 <cody@cutrer.us>
This commit is contained in:
@@ -46,6 +46,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class ColorValue extends Value {
|
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 Logger logger = LoggerFactory.getLogger(ColorValue.class);
|
||||||
|
|
||||||
private final ColorMode colorMode;
|
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.
|
* Converts the color state to a string.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -261,8 +261,8 @@ public class ChannelStateTests {
|
|||||||
c.processMessage("state", "12,18,231".getBytes());
|
c.processMessage("state", "12,18,231".getBytes());
|
||||||
assertThat(value.getChannelState(), is(t)); // HSB
|
assertThat(value.getChannelState(), is(t)); // HSB
|
||||||
// rgb -> hsv -> rgb is quite lossy
|
// rgb -> hsv -> rgb is quite lossy
|
||||||
assertThat(value.getMQTTpublishValue(null), is("13,20,225"));
|
assertThat(value.getMQTTpublishValue(null), is("13,20,229"));
|
||||||
assertThat(value.getMQTTpublishValue("%3$d,%2$d,%1$d"), is("225,20,13"));
|
assertThat(value.getMQTTpublishValue("%3$d,%2$d,%1$d"), is("229,20,13"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user