Adapt to ColorUtil changes in core (#14724)

* [deconz][dmx][mqtt.generic][mqtt.homeassistant][tado][tradfri][webthing] Adapt to core change (ColorUtil)

openhab/openhab-core#3479

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-04-08 11:42:18 +02:00
committed by GitHub
parent 64723db7aa
commit 3cd9c6c86c
10 changed files with 21 additions and 22 deletions

View File

@@ -308,10 +308,10 @@ public class ValueDecoder {
double x = Double.parseDouble(stringx.replace(",", "."));
double y = Double.parseDouble(stringy.replace(",", "."));
if (stringY == null) {
return ColorUtil.xyToHsv(new double[] { x, y });
return ColorUtil.xyToHsb(new double[] { x, y });
} else {
double Y = Double.parseDouble(stringY.replace(",", "."));
return ColorUtil.xyToHsv(new double[] { x, y, Y });
return ColorUtil.xyToHsb(new double[] { x, y, Y });
}
}
}

View File

@@ -149,8 +149,8 @@ public class ValueEncoder {
private static String handleHSBType(String dptId, HSBType hsb) {
switch (dptId) {
case "232.600":
return "r:" + convertPercentToByte(hsb.getRed()) + " g:" + convertPercentToByte(hsb.getGreen()) + " b:"
+ convertPercentToByte(hsb.getBlue());
int[] rgb = ColorUtil.hsbToRgb(hsb);
return String.format("r:%d g:%d b:%d", rgb[0], rgb[1], rgb[2]);
case "232.60000":
// MDT specific: mis-use 232.600 for hsv instead of rgb
int hue = hsb.getHue().toBigDecimal().multiply(BigDecimal.valueOf(255))
@@ -161,8 +161,8 @@ public class ValueEncoder {
double[] xyY = ColorUtil.hsbToXY(hsb);
return String.format("(%,.4f %,.4f) %,.1f %%", xyY[0], xyY[1], xyY[2] * 100.0);
case "251.600":
return String.format("%d %d %d - %%", hsb.getRed().intValue(), hsb.getGreen().intValue(),
hsb.getBlue().intValue());
rgb = ColorUtil.hsbToRgb(hsb);
return String.format("%d %d %d - %%", rgb[0], rgb[1], rgb[2]);
case "5.003":
return hsb.getHue().toString();
default:

View File

@@ -293,7 +293,6 @@ class DPTTest {
}
@Test
@SuppressWarnings("null")
void testToDPT29ValueFromQuantityType() {
assertEquals("42", ValueEncoder.encode(new QuantityType<>("42 Wh"), "29.010"));
assertEquals("42", ValueEncoder.encode(new QuantityType<>("42 VAh"), "29.011"));
@@ -337,8 +336,8 @@ class DPTTest {
assertNotNull(hsbType);
assertEquals(207, hsbType.getHue().doubleValue(), 0.1);
assertEquals(22, hsbType.getSaturation().doubleValue(), 0.1);
assertEquals(18, hsbType.getBrightness().doubleValue(), 0.1);
assertEquals(23, hsbType.getSaturation().doubleValue(), 0.1);
assertEquals(19, hsbType.getBrightness().doubleValue(), 0.1);
}
// This test checks all our overrides for units. It allows to detect unnecessary overrides when we