diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannel.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannel.java index 407fc56a109..923759b0e1d 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannel.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/KNXChannel.java @@ -131,7 +131,8 @@ public abstract class KNXChannel { } else { for (Class 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()); 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 8d6b33550ce..ad6cb704e35 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 @@ -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 { diff --git a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java index 854b08eb04d..b3ca61b8584 100644 --- a/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java +++ b/bundles/org.openhab.binding.knx/src/test/java/org/openhab/binding/knx/internal/channel/KNXChannelTest.java @@ -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"));