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:
parent
64723db7aa
commit
3cd9c6c86c
|
@ -446,7 +446,7 @@ public class LightThingHandler extends DeconzBaseThingHandler {
|
||||||
xyY[0] = xy[0];
|
xyY[0] = xy[0];
|
||||||
xyY[1] = xy[1];
|
xyY[1] = xy[1];
|
||||||
xyY[2] = ((double) bri) / BRIGHTNESS_MAX;
|
xyY[2] = ((double) bri) / BRIGHTNESS_MAX;
|
||||||
updateState(channelUID, ColorUtil.xyToHsv(xyY));
|
updateState(channelUID, ColorUtil.xyToHsb(xyY));
|
||||||
}
|
}
|
||||||
} else if (bri != null && hue != null && sat != null) {
|
} else if (bri != null && hue != null && sat != null) {
|
||||||
updateState(channelUID,
|
updateState(channelUID,
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class SensorThingHandler extends SensorBaseThingHandler {
|
||||||
case CHANNEL_COLOR -> {
|
case CHANNEL_COLOR -> {
|
||||||
final double @Nullable [] xy = newState.xy;
|
final double @Nullable [] xy = newState.xy;
|
||||||
if (xy != null && xy.length == 2) {
|
if (xy != null && xy.length == 2) {
|
||||||
updateState(channelUID, ColorUtil.xyToHsv(xy));
|
updateState(channelUID, ColorUtil.xyToHsb(xy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case CHANNEL_CONSUMPTION -> updateQuantityTypeChannel(channelUID, newState.consumption, WATT_HOUR);
|
case CHANNEL_CONSUMPTION -> updateQuantityTypeChannel(channelUID, newState.consumption, WATT_HOUR);
|
||||||
|
|
|
@ -210,7 +210,7 @@ public class ColorThingHandlerTest extends AbstractDmxThingTestParent {
|
||||||
assertChannelStateUpdate(CHANNEL_UID_COLOR,
|
assertChannelStateUpdate(CHANNEL_UID_COLOR,
|
||||||
state -> assertThat(((HSBType) state).getBrightness().doubleValue(), is(closeTo(30.0, 1))));
|
state -> assertThat(((HSBType) state).getBrightness().doubleValue(), is(closeTo(30.0, 1))));
|
||||||
assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_R,
|
assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_R,
|
||||||
state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(19.2, 0.5))));
|
state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(20.0, 0.5))));
|
||||||
assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_G, state -> assertEquals(PercentType.ZERO, state));
|
assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_G, state -> assertEquals(PercentType.ZERO, state));
|
||||||
assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_B,
|
assertChannelStateUpdate(CHANNEL_UID_BRIGHTNESS_B,
|
||||||
state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(29.8, 0.5))));
|
state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(29.8, 0.5))));
|
||||||
|
|
|
@ -308,10 +308,10 @@ public class ValueDecoder {
|
||||||
double x = Double.parseDouble(stringx.replace(",", "."));
|
double x = Double.parseDouble(stringx.replace(",", "."));
|
||||||
double y = Double.parseDouble(stringy.replace(",", "."));
|
double y = Double.parseDouble(stringy.replace(",", "."));
|
||||||
if (stringY == null) {
|
if (stringY == null) {
|
||||||
return ColorUtil.xyToHsv(new double[] { x, y });
|
return ColorUtil.xyToHsb(new double[] { x, y });
|
||||||
} else {
|
} else {
|
||||||
double Y = Double.parseDouble(stringY.replace(",", "."));
|
double Y = Double.parseDouble(stringY.replace(",", "."));
|
||||||
return ColorUtil.xyToHsv(new double[] { x, y, Y });
|
return ColorUtil.xyToHsb(new double[] { x, y, Y });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,8 +149,8 @@ public class ValueEncoder {
|
||||||
private static String handleHSBType(String dptId, HSBType hsb) {
|
private static String handleHSBType(String dptId, HSBType hsb) {
|
||||||
switch (dptId) {
|
switch (dptId) {
|
||||||
case "232.600":
|
case "232.600":
|
||||||
return "r:" + convertPercentToByte(hsb.getRed()) + " g:" + convertPercentToByte(hsb.getGreen()) + " b:"
|
int[] rgb = ColorUtil.hsbToRgb(hsb);
|
||||||
+ convertPercentToByte(hsb.getBlue());
|
return String.format("r:%d g:%d b:%d", rgb[0], rgb[1], rgb[2]);
|
||||||
case "232.60000":
|
case "232.60000":
|
||||||
// MDT specific: mis-use 232.600 for hsv instead of rgb
|
// MDT specific: mis-use 232.600 for hsv instead of rgb
|
||||||
int hue = hsb.getHue().toBigDecimal().multiply(BigDecimal.valueOf(255))
|
int hue = hsb.getHue().toBigDecimal().multiply(BigDecimal.valueOf(255))
|
||||||
|
@ -161,8 +161,8 @@ public class ValueEncoder {
|
||||||
double[] xyY = ColorUtil.hsbToXY(hsb);
|
double[] xyY = ColorUtil.hsbToXY(hsb);
|
||||||
return String.format("(%,.4f %,.4f) %,.1f %%", xyY[0], xyY[1], xyY[2] * 100.0);
|
return String.format("(%,.4f %,.4f) %,.1f %%", xyY[0], xyY[1], xyY[2] * 100.0);
|
||||||
case "251.600":
|
case "251.600":
|
||||||
return String.format("%d %d %d - %%", hsb.getRed().intValue(), hsb.getGreen().intValue(),
|
rgb = ColorUtil.hsbToRgb(hsb);
|
||||||
hsb.getBlue().intValue());
|
return String.format("%d %d %d - %%", rgb[0], rgb[1], rgb[2]);
|
||||||
case "5.003":
|
case "5.003":
|
||||||
return hsb.getHue().toString();
|
return hsb.getHue().toString();
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -293,7 +293,6 @@ class DPTTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("null")
|
|
||||||
void testToDPT29ValueFromQuantityType() {
|
void testToDPT29ValueFromQuantityType() {
|
||||||
assertEquals("42", ValueEncoder.encode(new QuantityType<>("42 Wh"), "29.010"));
|
assertEquals("42", ValueEncoder.encode(new QuantityType<>("42 Wh"), "29.010"));
|
||||||
assertEquals("42", ValueEncoder.encode(new QuantityType<>("42 VAh"), "29.011"));
|
assertEquals("42", ValueEncoder.encode(new QuantityType<>("42 VAh"), "29.011"));
|
||||||
|
@ -337,8 +336,8 @@ class DPTTest {
|
||||||
|
|
||||||
assertNotNull(hsbType);
|
assertNotNull(hsbType);
|
||||||
assertEquals(207, hsbType.getHue().doubleValue(), 0.1);
|
assertEquals(207, hsbType.getHue().doubleValue(), 0.1);
|
||||||
assertEquals(22, hsbType.getSaturation().doubleValue(), 0.1);
|
assertEquals(23, hsbType.getSaturation().doubleValue(), 0.1);
|
||||||
assertEquals(18, hsbType.getBrightness().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
|
// This test checks all our overrides for units. It allows to detect unnecessary overrides when we
|
||||||
|
|
|
@ -262,8 +262,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((Command) value.getChannelState(), null), is("13,20,229"));
|
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), null), is("11,18,232"));
|
||||||
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), "%3$d,%2$d,%1$d"), is("229,20,13"));
|
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), "%3$d,%2$d,%1$d"), is("232,18,11"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -311,9 +311,9 @@ public class ChannelStateTests {
|
||||||
|
|
||||||
c.processMessage("state", "0.3,0.6,100".getBytes());
|
c.processMessage("state", "0.3,0.6,100".getBytes());
|
||||||
assertThat(value.getChannelState(), is(t)); // HSB
|
assertThat(value.getChannelState(), is(t)); // HSB
|
||||||
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), null), is("0.304200,0.594600,100.00"));
|
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), null), is("0.298700,0.601500,100.00"));
|
||||||
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), "%3$.1f,%2$.4f,%1$.4f"),
|
assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), "%3$.1f,%2$.4f,%1$.4f"),
|
||||||
is("100.0,0.5946,0.3042"));
|
is("100.0,0.6015,0.2987"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class JSONSchemaLightTests extends AbstractComponentTests {
|
||||||
publishMessage("zigbee2mqtt/light/state", "{ \"color\": {\"r\": 10, \"g\": 20, \"b\": 30 } }");
|
publishMessage("zigbee2mqtt/light/state", "{ \"color\": {\"r\": 10, \"g\": 20, \"b\": 30 } }");
|
||||||
assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(10, 20, 30));
|
assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(10, 20, 30));
|
||||||
publishMessage("zigbee2mqtt/light/state", "{ \"brightness\": 255 }");
|
publishMessage("zigbee2mqtt/light/state", "{ \"brightness\": 255 }");
|
||||||
assertState(component, Light.COLOR_CHANNEL_ID, new HSBType("210,66,100"));
|
assertState(component, Light.COLOR_CHANNEL_ID, new HSBType("210,67,100"));
|
||||||
|
|
||||||
sendCommand(component, Light.COLOR_CHANNEL_ID, HSBType.BLUE);
|
sendCommand(component, Light.COLOR_CHANNEL_ID, HSBType.BLUE);
|
||||||
assertPublished("zigbee2mqtt/light/set/state",
|
assertPublished("zigbee2mqtt/light/set/state",
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class TradfriColorTest {
|
||||||
HSBType hsbType = color.getHSB();
|
HSBType hsbType = color.getHSB();
|
||||||
assertNotNull(hsbType);
|
assertNotNull(hsbType);
|
||||||
assertEquals(312, hsbType.getHue().intValue());
|
assertEquals(312, hsbType.getHue().intValue());
|
||||||
assertEquals(91, hsbType.getSaturation().intValue());
|
assertEquals(92, hsbType.getSaturation().intValue());
|
||||||
assertEquals(100, hsbType.getBrightness().intValue());
|
assertEquals(100, hsbType.getBrightness().intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class TradfriColorTest {
|
||||||
assertEquals(84, (int) color.brightness);
|
assertEquals(84, (int) color.brightness);
|
||||||
HSBType hsbType = color.getHSB();
|
HSBType hsbType = color.getHSB();
|
||||||
assertNotNull(hsbType);
|
assertNotNull(hsbType);
|
||||||
assertEquals(92, hsbType.getHue().intValue());
|
assertEquals(93, hsbType.getHue().intValue());
|
||||||
assertEquals(65, hsbType.getSaturation().intValue());
|
assertEquals(65, hsbType.getSaturation().intValue());
|
||||||
assertEquals(34, hsbType.getBrightness().intValue());
|
assertEquals(34, hsbType.getBrightness().intValue());
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class TradfriColorTest {
|
||||||
assertEquals(1, (int) color.brightness);
|
assertEquals(1, (int) color.brightness);
|
||||||
HSBType hsbType = color.getHSB();
|
HSBType hsbType = color.getHSB();
|
||||||
assertNotNull(hsbType);
|
assertNotNull(hsbType);
|
||||||
assertEquals(92, hsbType.getHue().intValue());
|
assertEquals(93, hsbType.getHue().intValue());
|
||||||
assertEquals(65, hsbType.getSaturation().intValue());
|
assertEquals(65, hsbType.getSaturation().intValue());
|
||||||
assertEquals(1, hsbType.getBrightness().intValue());
|
assertEquals(1, hsbType.getBrightness().intValue());
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class TradfriColorTest {
|
||||||
HSBType hsbType = color.getHSB();
|
HSBType hsbType = color.getHSB();
|
||||||
assertNotNull(hsbType);
|
assertNotNull(hsbType);
|
||||||
assertEquals(156, hsbType.getHue().intValue());
|
assertEquals(156, hsbType.getHue().intValue());
|
||||||
assertEquals(76, hsbType.getSaturation().intValue());
|
assertEquals(77, hsbType.getSaturation().intValue());
|
||||||
assertEquals(72, hsbType.getBrightness().intValue());
|
assertEquals(72, hsbType.getBrightness().intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class WebthingChannelLinkTest {
|
||||||
performDataTypeMappingTest("targettemp_prop", 18.6, new DecimalType(18.6), 23.2, new DecimalType(23.2));
|
performDataTypeMappingTest("targettemp_prop", 18.6, new DecimalType(18.6), 23.2, new DecimalType(23.2));
|
||||||
performDataTypeMappingTest("open_prop", true, OpenClosedType.OPEN, false, OpenClosedType.CLOSED);
|
performDataTypeMappingTest("open_prop", true, OpenClosedType.OPEN, false, OpenClosedType.CLOSED);
|
||||||
performDataTypeMappingTest("colortemp_prop", 10, new PercentType(10), 60, new PercentType(60));
|
performDataTypeMappingTest("colortemp_prop", 10, new PercentType(10), 60, new PercentType(60));
|
||||||
performDataTypeMappingTest("color_prop", "#f2fe00", new HSBType("62,100,99"), "#ff0000",
|
performDataTypeMappingTest("color_prop", "#f2fe00", new HSBType("63,100,100"), "#ff0000",
|
||||||
new HSBType("0.0,100.0,100.0"));
|
new HSBType("0.0,100.0,100.0"));
|
||||||
performDataTypeMappingTest("colormode_prop", "color", new StringType("color"), "temperature",
|
performDataTypeMappingTest("colormode_prop", "color", new StringType("color"), "temperature",
|
||||||
new StringType("temperature"));
|
new StringType("temperature"));
|
||||||
|
|
Loading…
Reference in New Issue