diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java index c6e903dc4..8668bc708 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java @@ -446,7 +446,7 @@ public class LightThingHandler extends DeconzBaseThingHandler { 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, diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThingHandler.java index 20e84a804..563d5aca5 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThingHandler.java @@ -117,7 +117,7 @@ public class SensorThingHandler extends SensorBaseThingHandler { 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); diff --git a/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/internal/handler/ColorThingHandlerTest.java b/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/internal/handler/ColorThingHandlerTest.java index 8dfaf7f54..5e118cb16 100644 --- a/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/internal/handler/ColorThingHandlerTest.java +++ b/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/internal/handler/ColorThingHandlerTest.java @@ -210,7 +210,7 @@ public class ColorThingHandlerTest extends AbstractDmxThingTestParent { 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)))); diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java index 0f1db1307..7aa716130 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java @@ -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 }); } } } diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java index 48e1ede1d..23b056e05 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java @@ -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: diff --git a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java index 668276fca..b61f55e7d 100644 --- a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java +++ b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java @@ -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 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 90176963d..7cef11288 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 @@ -262,8 +262,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((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 @@ -311,9 +311,9 @@ public class ChannelStateTests { 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 diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java index a33957479..fdd18ee34 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java @@ -76,7 +76,7 @@ public class JSONSchemaLightTests extends AbstractComponentTests { 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", diff --git a/bundles/org.openhab.binding.tradfri/src/test/java/org/openhab/binding/tradfri/internal/TradfriColorTest.java b/bundles/org.openhab.binding.tradfri/src/test/java/org/openhab/binding/tradfri/internal/TradfriColorTest.java index c38f6344a..e1a7bf51b 100644 --- a/bundles/org.openhab.binding.tradfri/src/test/java/org/openhab/binding/tradfri/internal/TradfriColorTest.java +++ b/bundles/org.openhab.binding.tradfri/src/test/java/org/openhab/binding/tradfri/internal/TradfriColorTest.java @@ -36,7 +36,7 @@ public class TradfriColorTest { 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()); } @@ -48,7 +48,7 @@ public class TradfriColorTest { 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()); } @@ -61,7 +61,7 @@ public class TradfriColorTest { 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()); } @@ -75,7 +75,7 @@ public class TradfriColorTest { 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()); } diff --git a/bundles/org.openhab.binding.webthing/src/test/java/org/openhab/binding/webthing/internal/link/WebthingChannelLinkTest.java b/bundles/org.openhab.binding.webthing/src/test/java/org/openhab/binding/webthing/internal/link/WebthingChannelLinkTest.java index 0472f6225..8d82a4a93 100644 --- a/bundles/org.openhab.binding.webthing/src/test/java/org/openhab/binding/webthing/internal/link/WebthingChannelLinkTest.java +++ b/bundles/org.openhab.binding.webthing/src/test/java/org/openhab/binding/webthing/internal/link/WebthingChannelLinkTest.java @@ -140,7 +140,7 @@ public class WebthingChannelLinkTest { 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"));