]> git.basschouten.com Git - openhab-addons.git/commitdiff
Adapt to ColorUtil changes in core (#14724)
authorHolger Friedrich <holgerfriedrich@users.noreply.github.com>
Sat, 8 Apr 2023 09:42:18 +0000 (11:42 +0200)
committerGitHub <noreply@github.com>
Sat, 8 Apr 2023 09:42:18 +0000 (11:42 +0200)
* [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>
bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java
bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThingHandler.java
bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/internal/handler/ColorThingHandlerTest.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java
bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/dpt/DPTTest.java
bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/ChannelStateTests.java
bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java
bundles/org.openhab.binding.tradfri/src/test/java/org/openhab/binding/tradfri/internal/TradfriColorTest.java
bundles/org.openhab.binding.webthing/src/test/java/org/openhab/binding/webthing/internal/link/WebthingChannelLinkTest.java

index c6e903dc4797fc6d88551ce1f737af6cd9420ead..8668bc708fab6b4672396b3127e6ee64b6867298 100644 (file)
@@ -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,
index 20e84a80413ba72e37d621a4b586871390ced445..563d5aca502c98393b019c623b6ce5bf08defa52 100644 (file)
@@ -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);
index 8dfaf7f54fae578149e05883a196b1765b4c0659..5e118cb162ed34b553bc7565a1f62604bf188baf 100644 (file)
@@ -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))));
index 0f1db1307e379e06a3bb1d8fd8d7e753331147ad..7aa716130c16d0b79db4f21a627af0c2353bf240 100644 (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 });
                 }
             }
         }
index 48e1ede1d77a8ca665167cdf1a511f5e0f62214b..23b056e05914aae35521926a1b246e76d0ec4070 100644 (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:
index 668276fca1d5ce079a98fc18f9e4e0d21c4684b8..b61f55e7de9b7a82aeb1abe213ff0a5e75891f4d 100644 (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
index 90176963d5cfea60d5df8121c6d98eea6f07fbab..7cef112889048fb5211d11ab80313c4f93f155cd 100644 (file)
@@ -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
index a33957479b19355e88b55c0f4938ca63a291157b..fdd18ee34a6ef8449386d67fa975403785cc4b07 100644 (file)
@@ -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",
index c38f6344ab21cfe58dc92882172fc916571f61ee..e1a7bf51bda07e97e8bf4f5872d0513762fc2327 100644 (file)
@@ -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());
     }
 
index 0472f6225e470f40e318c6322b36899084d61797..8d82a4a93cafd21f6bd96fb304e5f46420877f6b 100644 (file)
@@ -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"));