* [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>
xyY[0] = xy[0];
xyY[1] = xy[1];
xyY[2] = ((double) bri) / BRIGHTNESS_MAX;
- updateState(channelUID, ColorUtil.xyToHsv(xyY));
+ updateState(channelUID, ColorUtil.xyToHsb(xyY));
}
} else if (bri != null && hue != null && sat != null) {
updateState(channelUID,
case CHANNEL_COLOR -> {
final double @Nullable [] xy = newState.xy;
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);
assertChannelStateUpdate(CHANNEL_UID_COLOR,
state -> assertThat(((HSBType) state).getBrightness().doubleValue(), is(closeTo(30.0, 1))));
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_B,
state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(29.8, 0.5))));
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 });
}
}
}
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))
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:
}
@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"));
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
c.processMessage("state", "12,18,231".getBytes());
assertThat(value.getChannelState(), is(t)); // HSB
// rgb -> hsv -> rgb is quite lossy
- assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), null), is("13,20,229"));
- assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), "%3$d,%2$d,%1$d"), is("229,20,13"));
+ assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), null), is("11,18,232"));
+ assertThat(value.getMQTTpublishValue((Command) value.getChannelState(), "%3$d,%2$d,%1$d"), is("232,18,11"));
}
@Test
c.processMessage("state", "0.3,0.6,100".getBytes());
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"),
- is("100.0,0.5946,0.3042"));
+ is("100.0,0.6015,0.2987"));
}
@Test
publishMessage("zigbee2mqtt/light/state", "{ \"color\": {\"r\": 10, \"g\": 20, \"b\": 30 } }");
assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(10, 20, 30));
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);
assertPublished("zigbee2mqtt/light/set/state",
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
assertEquals(312, hsbType.getHue().intValue());
- assertEquals(91, hsbType.getSaturation().intValue());
+ assertEquals(92, hsbType.getSaturation().intValue());
assertEquals(100, hsbType.getBrightness().intValue());
}
assertEquals(84, (int) color.brightness);
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
- assertEquals(92, hsbType.getHue().intValue());
+ assertEquals(93, hsbType.getHue().intValue());
assertEquals(65, hsbType.getSaturation().intValue());
assertEquals(34, hsbType.getBrightness().intValue());
}
assertEquals(1, (int) color.brightness);
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
- assertEquals(92, hsbType.getHue().intValue());
+ assertEquals(93, hsbType.getHue().intValue());
assertEquals(65, hsbType.getSaturation().intValue());
assertEquals(1, hsbType.getBrightness().intValue());
}
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
assertEquals(156, hsbType.getHue().intValue());
- assertEquals(76, hsbType.getSaturation().intValue());
+ assertEquals(77, hsbType.getSaturation().intValue());
assertEquals(72, hsbType.getBrightness().intValue());
}
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("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"));
performDataTypeMappingTest("colormode_prop", "color", new StringType("color"), "temperature",
new StringType("temperature"));