]> git.basschouten.com Git - openhab-addons.git/commitdiff
[knx] Fix warnings and remove TODOs (#16394)
authorHolger Friedrich <mail@holger-friedrich.de>
Wed, 14 Feb 2024 20:17:59 +0000 (21:17 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 20:17:59 +0000 (21:17 +0100)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannel.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueDecoder.java
bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java

index 407fc56a10977aa8cc83efaf08ce523a0baf45c8..923759b0e1d80415995c0020eff3b2d8f9cdb479 100644 (file)
@@ -131,7 +131,8 @@ public abstract class KNXChannel {
             } else {
                 for (Class<? extends Type> expectedTypeClass : expectedTypeClasses) {
                     if (command instanceof State state && State.class.isAssignableFrom(expectedTypeClass)) {
-                        if (state.as(expectedTypeClass.asSubclass(State.class)) != null) {
+                        var subClass = expectedTypeClass.asSubclass(State.class);
+                        if (state.as(subClass) != null) {
                             logger.trace(
                                     "getCommandSpec command class '{}' is a sub-class of the expectedTypeClass '{}' for key '{}'",
                                     command.getClass(), expectedTypeClass, entry.getKey());
index 8d6b33550cec47122fccfd25beb128d49ab80740..ad6cb704e3518b08609dd8a4e4c97664fe4a9b72 100644 (file)
@@ -211,7 +211,6 @@ public class ValueDecoder {
                     return handleDpt251(value, subType, preferredType);
                 default:
                     return handleNumericDpt(id, translator, preferredType);
-                // TODO 6.001 is mapped to PercentType, which can only cover 0-100%, not -128..127%
             }
         } catch (NumberFormatException | KNXFormatException | KNXIllegalArgumentException | ParseException e) {
             LOGGER.info("Translator couldn't parse data '{}' for datapoint type '{}' ({}).", data, dptId, e.getClass());
@@ -271,9 +270,6 @@ public class ValueDecoder {
     }
 
     private static Type handleDpt10(String value) throws ParseException {
-        // TODO check handling of DPT10: date is not set to current date, but 1970-01-01 + offset if day is given
-        // maybe we should change the semantics and use current date + offset if day is given
-
         // Calimero will provide either TIME_DAY_FORMAT or TIME_FORMAT, no-day is not printed
         Date date = null;
         try {
index 854b08eb04d13e8adb43dd42d82f288121554904..b3ca61b858488ad4ce6782b406713e672f1353ae 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Objects;
 import java.util.Set;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.junit.jupiter.api.Test;
 import org.openhab.binding.knx.internal.KNXBindingConstants;
 import org.openhab.binding.knx.internal.client.OutboundSpec;
@@ -176,7 +177,10 @@ class KNXChannelTest {
         when(channel.getAcceptedItemType()).thenReturn(ColorItem.class.getName());
         MyKNXChannel knxChannel = new MyKNXChannel(channel);
         assertNotNull(knxChannel.getCommandSpec(new HSBType("0,100,100")));
-        assertEquals(knxChannel.getCommandSpec(new HSBType("0,100,100")).getDPT(), "1.001");
+        @Nullable
+        OutboundSpec outboundSpec = knxChannel.getCommandSpec(new HSBType("0,100,100"));
+        assertNotNull(outboundSpec);
+        assertEquals(outboundSpec.getDPT(), "1.001");
     }
 
     @Test
@@ -191,8 +195,9 @@ class KNXChannelTest {
         assertThat(knxChannel, instanceOf(TypeDimmer.class));
 
         Command command = new PercentType("100");
+        @Nullable
         OutboundSpec outboundSpec = knxChannel.getCommandSpec(command);
-        assertThat(outboundSpec, is(notNullValue()));
+        assertNotNull(outboundSpec);
 
         String mappedValue = ValueEncoder.encode(outboundSpec.getValue(), outboundSpec.getDPT());
         assertThat(mappedValue, is("100"));