diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanBindingConstants.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanBindingConstants.java index 77f6a3b0dfd..5bcae336afd 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanBindingConstants.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanBindingConstants.java @@ -576,7 +576,7 @@ public class EnOceanBindingConstants { // Bridge properties public static final String PROPERTY_BASE_ID = "Base ID"; - public static final String PROPERTY_REMAINING_WRITE_CYCLES_Base_ID = "Remaining Base ID Write Cycles"; + public static final String PROPERTY_REMAINING_WRITE_CYCLES_BASE_ID = "Remaining Base ID Write Cycles"; public static final String PROPERTY_APP_VERSION = "APP Version"; public static final String PROPERTY_API_VERSION = "API Version"; public static final String PROPERTY_CHIP_ID = "Chip ID"; @@ -594,9 +594,9 @@ public class EnOceanBindingConstants { public static final String PARAMETER_ENOCEANID = "enoceanId"; // Channel config parameter - public static final String PARAMETER_CHANNEL_TeachInMSG = "teachInMSG"; - public static final String PARAMETER_CHANNEL_Duration = "duration"; - public static final String PARAMETER_CHANNEL_SwitchMode = "switchMode"; + public static final String PARAMETER_CHANNEL_TEACHINMSG = "teachInMSG"; + public static final String PARAMETER_CHANNEL_DURATION = "duration"; + public static final String PARAMETER_CHANNEL_SWITCHMODE = "switchMode"; // Manufacturer Ids - used to recognize special EEPs during auto discovery public static final int ELTAKOID = 0x00d; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanChannelDescription.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanChannelDescription.java index dcbaa2cfdf1..ca06c0cd07a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanChannelDescription.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanChannelDescription.java @@ -12,7 +12,8 @@ */ package org.openhab.binding.enocean.internal; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.thing.type.ChannelTypeUID; /** @@ -21,10 +22,10 @@ import org.openhab.core.thing.type.ChannelTypeUID; * This class holds information for creating a channel of an EnOcean thing like acceptedItemType and * channelTypeUID */ +@NonNullByDefault public class EnOceanChannelDescription { public final ChannelTypeUID channelTypeUID; public final String acceptedItemType; - @NonNull public final String label; public final boolean isStateChannel; public final boolean autoCreate; @@ -49,15 +50,11 @@ public class EnOceanChannelDescription { * @param autoCreate create channel during thing initialization, otherwise channel is created * manually/predefined */ - public EnOceanChannelDescription(ChannelTypeUID channelTypeUID, String itemType, String label, + public EnOceanChannelDescription(ChannelTypeUID channelTypeUID, @Nullable String itemType, @Nullable String label, boolean isStateChannel, boolean autoCreate) { this.channelTypeUID = channelTypeUID; - this.acceptedItemType = itemType; - if (label != null) { - this.label = label; - } else { - this.label = ""; - } + this.acceptedItemType = itemType != null ? itemType : ""; + this.label = label != null ? label : ""; this.isStateChannel = isStateChannel; this.autoCreate = autoCreate; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanConfigStatusMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanConfigStatusMessage.java index d9d755e97d2..f877090a48a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanConfigStatusMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanConfigStatusMessage.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public enum EnOceanConfigStatusMessage { PORT_MISSING("missing-port-configuration"), SENDERID_MISSING("missing-senderId-configuration"), diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanException.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanException.java index bbff240cf4e..1faca0043d3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanException.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanException.java @@ -12,10 +12,14 @@ */ package org.openhab.binding.enocean.internal; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanException extends Exception { /** @@ -23,7 +27,7 @@ public class EnOceanException extends Exception { */ private static final long serialVersionUID = 1L; - public EnOceanException(String msg) { + public EnOceanException(@Nullable String msg) { super(msg); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanHandlerFactory.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanHandlerFactory.java index 11364186498..48aa03cfa0f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanHandlerFactory.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/EnOceanHandlerFactory.java @@ -19,6 +19,8 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.discovery.EnOceanDeviceDiscoveryService; import org.openhab.binding.enocean.internal.handler.EnOceanBaseActuatorHandler; import org.openhab.binding.enocean.internal.handler.EnOceanBaseSensorHandler; @@ -36,6 +38,7 @@ import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.ThingHandlerFactory; import org.openhab.core.thing.link.ItemChannelLinkRegistry; import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -45,6 +48,7 @@ import org.osgi.service.component.annotations.Reference; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault @Component(service = ThingHandlerFactory.class, configurationPid = "binding.enocean") public class EnOceanHandlerFactory extends BaseThingHandlerFactory { @@ -55,14 +59,19 @@ public class EnOceanHandlerFactory extends BaseThingHandlerFactory { private Map> discoveryServiceRegs = new HashMap<>(); - @Reference - SerialPortManager serialPortManager; + private final SerialPortManager serialPortManager; + private final ThingManager thingManager; + private final ItemChannelLinkRegistry itemChannelLinkRegistry; - @Reference - ItemChannelLinkRegistry itemChannelLinkRegistry; - - @Reference - ThingManager thingManager; + @Activate + public EnOceanHandlerFactory(final @Reference SerialPortManager serialPortManager, + final @Reference ThingManager thingManager, + final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry) { + // Obtain references to thes service using an OSGi reference + this.serialPortManager = serialPortManager; + this.thingManager = thingManager; + this.itemChannelLinkRegistry = itemChannelLinkRegistry; + } @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { @@ -70,9 +79,8 @@ public class EnOceanHandlerFactory extends BaseThingHandlerFactory { } @Override - protected ThingHandler createHandler(Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); - if (EnOceanBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { EnOceanBridgeHandler bridgeHandler = new EnOceanBridgeHandler((Bridge) thing, serialPortManager); registerDeviceDiscoveryService(bridgeHandler); @@ -90,12 +98,10 @@ public class EnOceanHandlerFactory extends BaseThingHandlerFactory { @Override protected void removeHandler(ThingHandler thingHandler) { - if (this.discoveryServiceRegs != null) { - ServiceRegistration serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID()); - if (serviceReg != null) { - serviceReg.unregister(); - discoveryServiceRegs.remove(thingHandler.getThing().getUID()); - } + ServiceRegistration serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID()); + if (serviceReg != null) { + serviceReg.unregister(); + discoveryServiceRegs.remove(thingHandler.getThing().getUID()); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/Helper.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/Helper.java index be93505c6da..6420e8d6874 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/Helper.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/Helper.java @@ -14,14 +14,17 @@ package org.openhab.binding.enocean.internal; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class Helper { public static byte[] concatAll(byte[] a, byte[]... rest) { - if (rest == null) { + if (rest.length == 0) { return a; } @@ -40,7 +43,7 @@ public class Helper { offset += array.length; } } - return result; + return result != null ? result : new byte[0]; } public static int tryParseInt(String value, int defaultValue) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanActuatorConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanActuatorConfig.java index 942962d0f79..4b528e1f47a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanActuatorConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanActuatorConfig.java @@ -12,18 +12,22 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanActuatorConfig extends EnOceanBaseConfig { public int channel; - public Integer senderIdOffset = null; - public String manufacturerId; - public String teachInType; + public @Nullable Integer senderIdOffset = null; + public String manufacturerId = ""; + public String teachInType = ""; - public String sendingEEPId; + public String sendingEEPId = ""; public int pollingInterval; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanBridgeConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanBridgeConfig.java index d8f37866a70..565954a8a6d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanBridgeConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanBridgeConfig.java @@ -12,10 +12,14 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanBridgeConfig { public enum ESPVersion { @@ -40,24 +44,17 @@ public class EnOceanBridgeConfig { } } - public String path; + public String path = ""; - public String espVersion; + public String espVersion = "ESP3"; public boolean rs485; - public String rs485BaseId; + public String rs485BaseId = ""; - public Integer nextSenderId; + public @Nullable Integer nextSenderId; - public boolean enableSmack; + public boolean enableSmack = true; public boolean sendTeachOuts; - public EnOceanBridgeConfig() { - espVersion = "ESP3"; - sendTeachOuts = false; - enableSmack = true; - nextSenderId = null; - } - public ESPVersion getESPVersion() { return ESPVersion.getESPVersion(espVersion); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelContactConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelContactConfig.java index 45fb2723976..e500dbfa9b2 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelContactConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelContactConfig.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Holger Englert - Initial contribution */ +@NonNullByDefault public class EnOceanChannelContactConfig { // Swap Open/Closed value, e.g. // Eltako FPE-1: false, Eltako FPE-2: true diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelDimmerConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelDimmerConfig.java index d6b77d46fa5..26517cc7dca 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelDimmerConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelDimmerConfig.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class EnOceanChannelDimmerConfig { public int rampingTime = 0; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchConfigBase.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchConfigBase.java index e86b8b18fdf..99da566e0a4 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchConfigBase.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchConfigBase.java @@ -14,10 +14,14 @@ package org.openhab.binding.enocean.internal.config; import java.security.InvalidParameterException; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelRockerSwitchConfigBase { public String switchMode; @@ -39,7 +43,7 @@ public class EnOceanChannelRockerSwitchConfigBase { return value; } - public static SwitchMode getSwitchMode(String value) { + public static SwitchMode getSwitchMode(@Nullable String value) { if (value == null) { return SwitchMode.Unkown; } @@ -65,7 +69,7 @@ public class EnOceanChannelRockerSwitchConfigBase { this.value = value; } - public static Channel getChannel(String value) { + public static Channel getChannel(@Nullable String value) { if (value == null) { return Channel.Unkown; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchListenerConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchListenerConfig.java index d18c31a89b3..0e834d49c14 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchListenerConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRockerSwitchListenerConfig.java @@ -12,18 +12,19 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelRockerSwitchListenerConfig extends EnOceanChannelRockerSwitchConfigBase { - public String enoceanId; - public boolean handleSecondAction; + public String enoceanId = ""; + public boolean handleSecondAction = false; public EnOceanChannelRockerSwitchListenerConfig() { super(); - enoceanId = null; - handleSecondAction = false; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRollershutterConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRollershutterConfig.java index 6fb521d6739..39753ff2375 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRollershutterConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelRollershutterConfig.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelRollershutterConfig { public int shutTime; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTariffInfoConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTariffInfoConfig.java index 9362de2918f..fcea43c6c99 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTariffInfoConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTariffInfoConfig.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelTariffInfoConfig { public int tariff = 0; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTeachInConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTeachInConfig.java index 59a33974d12..145ace49a5f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTeachInConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTeachInConfig.java @@ -12,12 +12,15 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelTeachInConfig { - public String teachInMSG; - public String manufacturerId; + public String teachInMSG = ""; + public String manufacturerId = ""; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTotalusageConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTotalusageConfig.java index 3145172655f..d68c3dfb94e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTotalusageConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTotalusageConfig.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Dominik Vorreiter - Initial contribution */ +@NonNullByDefault public class EnOceanChannelTotalusageConfig { public boolean validateValue = false; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTransformationConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTransformationConfig.java index eb7712e29bd..5628e6f0e6c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTransformationConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelTransformationConfig.java @@ -12,19 +12,21 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.config.core.Configuration; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelTransformationConfig extends Configuration { - public String transformationType; - public String transformationFunction; + public String transformationType = ""; + public String transformationFunction = ""; public EnOceanChannelTransformationConfig() { - put("transformationType", ""); - put("transformationFunction", ""); + put("transformationType", transformationType); + put("transformationFunction", transformationFunction); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelVirtualRockerSwitchConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelVirtualRockerSwitchConfig.java index b4a5bf1fb18..880b01cff95 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelVirtualRockerSwitchConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanChannelVirtualRockerSwitchConfig.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanChannelVirtualRockerSwitchConfig extends EnOceanChannelRockerSwitchConfigBase { public Integer duration; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanProfileRockerSwitchActionConfig.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanProfileRockerSwitchActionConfig.java index 6985fc29e53..5f125ab505c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanProfileRockerSwitchActionConfig.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/config/EnOceanProfileRockerSwitchActionConfig.java @@ -12,12 +12,15 @@ */ package org.openhab.binding.enocean.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * This {@link EnOceanProfileRockerSwitchActionConfig} config class is used for rockerSwitchAction profiles to define in * which case it should react. * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanProfileRockerSwitchActionConfig { public String channelAFilter; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java index 52546501aca..6d0af65ece3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java @@ -17,6 +17,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.Set; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base.UTEResponse; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.eep.EEP; @@ -27,7 +29,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; import org.openhab.binding.enocean.internal.messages.EventMessage; import org.openhab.binding.enocean.internal.messages.EventMessage.EventMessageType; -import org.openhab.binding.enocean.internal.messages.Responses.SMACKTeachInResponse; +import org.openhab.binding.enocean.internal.messages.responses.SMACKTeachInResponse; import org.openhab.binding.enocean.internal.transceiver.TeachInListener; import org.openhab.core.config.discovery.AbstractDiscoveryService; import org.openhab.core.config.discovery.DiscoveryResultBuilder; @@ -44,6 +46,7 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService implements TeachInListener { private final Logger logger = LoggerFactory.getLogger(EnOceanDeviceDiscoveryService.class); @@ -70,20 +73,12 @@ public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService impl @Override protected void startScan() { - if (bridgeHandler == null) { - return; - } - logger.info("Starting EnOcean discovery and accepting teach in requests"); bridgeHandler.startDiscovery(this); } @Override public synchronized void stopScan() { - if (bridgeHandler == null) { - return; - } - logger.info("Stopping EnOcean discovery scan"); bridgeHandler.stopDiscovery(); super.stopScan(); @@ -125,11 +120,12 @@ public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService impl // check for bidirectional communication => do not use broadcast in this case if (msg.getRORG() == RORG.UTE && (msg.getPayload(1, 1)[0] - & UTEResponse.CommunicationType_MASK) == UTEResponse.CommunicationType_MASK) { + & UTEResponse.COMMUNICATION_TYPE_MASK) == UTEResponse.COMMUNICATION_TYPE_MASK) { broadcastMessages = false; } - if (msg.getRORG() == RORG.UTE && (msg.getPayload(1, 1)[0] & UTEResponse.ResponseNeeded_MASK) == 0) { + if (msg.getRORG() == RORG.UTE + && (msg.getPayload(1, 1)[0] & UTEResponse.RESPONSE_NEEDED_MASK) == 0) { // if ute => send response if needed logger.debug("Sending UTE response to {}", enoceanId); senderIdOffset = sendTeachInResponse(msg, enoceanId); @@ -183,7 +179,7 @@ public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService impl } } - private Integer sendTeachInResponse(ERP1Message msg, String enoceanId) { + private @Nullable Integer sendTeachInResponse(ERP1Message msg, String enoceanId) { // get new sender Id Integer offset = bridgeHandler.getNextSenderId(enoceanId); if (offset != null) { @@ -193,9 +189,12 @@ public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService impl // send response EEP response = EEPFactory.buildResponseEEPFromTeachInERP1(msg, newSenderId, true); if (response != null) { - bridgeHandler.sendMessage(response.getERP1Message(), null); - logger.debug("Teach in response for {} with new senderId {} (= offset {}) sent", enoceanId, - HexUtils.bytesToHex(newSenderId), offset); + BasePacket bPacket = response.getERP1Message(); + if (bPacket != null) { + bridgeHandler.sendMessage(bPacket, null); + logger.debug("Teach in response for {} with new senderId {} (= offset {}) sent", enoceanId, + HexUtils.bytesToHex(newSenderId), offset); + } } else { logger.warn("Teach in response for enoceanId {} not supported!", enoceanId); } @@ -212,16 +211,24 @@ public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService impl // send response EEP response = EEPFactory.buildResponseEEPFromTeachInERP1(msg, senderId, false); if (response != null) { - bridgeHandler.sendMessage(response.getERP1Message(), null); - logger.debug("Teach out response for thing {} with EnOceanId {} sent", thing.getUID().getId(), enoceanId); + ERP1Message message = response.getERP1Message(); + if (message != null) { + bridgeHandler.sendMessage(message, null); + logger.debug("Teach out response for thing {} with EnOceanId {} sent", thing.getUID().getId(), + enoceanId); + } } else { logger.warn("Teach out response for enoceanId {} not supported!", enoceanId); } } - protected void createDiscoveryResult(EEP eep, boolean broadcastMessages, Integer senderIdOffset) { + protected void createDiscoveryResult(EEP eep, boolean broadcastMessages, @Nullable Integer senderIdOffset) { String enoceanId = HexUtils.bytesToHex(eep.getSenderId()); ThingTypeUID thingTypeUID = eep.getThingTypeUID(); + if (thingTypeUID == null) { + logger.debug("Discovery failed, could not get ThingTypeUID for EnOceanId {}", enoceanId); + return; + } ThingUID thingUID = new ThingUID(thingTypeUID, bridgeHandler.getThing().getUID(), enoceanId); DiscoveryResultBuilder discoveryResultBuilder = DiscoveryResultBuilder.create(thingUID) diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanUsbSerialDiscoveryParticipant.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanUsbSerialDiscoveryParticipant.java index f5969984da6..337e4f7df14 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanUsbSerialDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanUsbSerialDiscoveryParticipant.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultBuilder; @@ -35,6 +36,7 @@ import org.osgi.service.component.annotations.Component; * * @author Aitor Iturrioz - initial contribution */ +@NonNullByDefault @Component(service = UsbSerialDiscoveryParticipant.class) public class EnOceanUsbSerialDiscoveryParticipant implements UsbSerialDiscoveryParticipant { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02.java index 8cc55741f17..dabf2d1783e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02.java @@ -14,6 +14,8 @@ package org.openhab.binding.enocean.internal.eep.A5_02; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -25,6 +27,7 @@ import org.openhab.core.types.State; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class A5_02 extends _4BSMessage { public A5_02(ERP1Message packet) { @@ -44,13 +47,12 @@ public abstract class A5_02 extends _4BSMessage { protected abstract double getScaledMax(); protected int getUnscaledTemperatureValue() { - return getDB_1Value(); + return getDB1Value(); } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { double scaledTemp = getScaledMin() - (((getUnscaledMin() - getUnscaledTemperatureValue()) * (getScaledMin() - getScaledMax())) / getUnscaledMin()); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_01.java index 5c5bdf33fae..96800ea0806 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_01.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_01 extends A5_02 { public A5_02_01(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_02.java index 214f5db007e..033d2044b4c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_02.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_02 extends A5_02 { public A5_02_02(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_03.java index 3d62bdffdf1..49bb0df2031 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_03.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_03 extends A5_02 { public A5_02_03(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_04.java index 558164d666a..057c3b596f9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_04.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_04 extends A5_02 { public A5_02_04(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_05.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_05.java index 586b5ec61d2..1349b133aac 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_05.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_05.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_05 extends A5_02 { public A5_02_05(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_06.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_06.java index 323cb9c439c..49d8c8ef5b9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_06.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_06.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_06 extends A5_02 { public A5_02_06(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_07.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_07.java index c47851477bb..d1ee5ee46b7 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_07.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_07.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_07 extends A5_02 { public A5_02_07(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_08.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_08.java index b1069526926..51f8271a29a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_08.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_08.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_08 extends A5_02 { public A5_02_08(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_09.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_09.java index 4b57d5eb9ca..a4465925b15 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_09.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_09.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_09 extends A5_02 { public A5_02_09(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0A.java index 74af8c2009c..1f44e818e39 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0A.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_0A extends A5_02 { public A5_02_0A(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0B.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0B.java index 7e624bd05a8..a74484ff4f0 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0B.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_0B.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_0B extends A5_02 { public A5_02_0B(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_10.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_10.java index 0eef55bd85a..76ca31f3d9b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_10.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_10.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_10 extends A5_02 { public A5_02_10(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_11.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_11.java index 640d228379f..97d77faab3b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_11.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_11.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_11 extends A5_02 { public A5_02_11(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_12.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_12.java index 681e26025e6..c22dc4c16cf 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_12.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_12.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_12 extends A5_02 { public A5_02_12(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_13.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_13.java index e156d8eeff5..99538d9540c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_13.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_13.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_13 extends A5_02 { public A5_02_13(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_14.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_14.java index d003a932776..0901ae61876 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_14.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_14.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_14 extends A5_02 { public A5_02_14(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_15.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_15.java index 0f2cbc229a7..97f331991cf 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_15.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_15.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_15 extends A5_02 { public A5_02_15(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_16.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_16.java index 82c5d2d5659..1a3028bc92b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_16.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_16.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_16 extends A5_02 { public A5_02_16(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_17.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_17.java index 85916e271d9..dbcfa599bff 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_17.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_17.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_17 extends A5_02 { public A5_02_17(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_18.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_18.java index 26ad46c675e..96a7a5bd402 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_18.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_18.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_18 extends A5_02 { public A5_02_18(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_19.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_19.java index 31496faca0e..5c03c17ee7b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_19.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_19.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_19 extends A5_02 { public A5_02_19(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1A.java index 0c67197f01a..772080ed9fb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1A.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_1A extends A5_02 { public A5_02_1A(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1B.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1B.java index 8e3ed6dcf36..6e4505c1aaa 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1B.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_1B.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_1B extends A5_02 { public A5_02_1B(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_20.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_20.java index d76349e57c9..5d614fbe845 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_20.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_20.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_20 extends A5_02 { public A5_02_20(ERP1Message packet) { @@ -46,6 +48,6 @@ public class A5_02_20 extends A5_02 { @Override protected int getUnscaledTemperatureValue() { - return getDB_1Value() + ((getDB_2Value() & 0b11) << 8); + return getDB1Value() + ((getDB2Value() & 0b11) << 8); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_30.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_30.java index 30861effe9a..99ee411f6fd 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_30.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_02/A5_02_30.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_02; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_02_30 extends A5_02 { public A5_02_30(ERP1Message packet) { @@ -46,6 +48,6 @@ public class A5_02_30 extends A5_02 { @Override protected int getUnscaledTemperatureValue() { - return getDB_1Value() + ((getDB_2Value() & 0b11) << 8); + return getDB1Value() + ((getDB2Value() & 0b11) << 8); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04.java index cc8983330fe..a63242bda19 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -29,6 +31,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class A5_04 extends _4BSMessage { public A5_04(ERP1Message packet) { @@ -48,7 +51,7 @@ public abstract class A5_04 extends _4BSMessage { protected abstract double getScaledTemperatureMax(); protected int getUnscaledTemperatureValue() { - return getDB_1Value(); + return getDB1Value(); } protected double getUnscaledHumidityMax() { @@ -56,13 +59,12 @@ public abstract class A5_04 extends _4BSMessage { } protected int getUnscaledHumidityValue() { - return getDB_2Value(); + return getDB2Value(); } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_TEMPERATURE)) { double scaledTemp = getScaledTemperatureMin() + ((getUnscaledTemperatureValue() * (getScaledTemperatureMax() - getScaledTemperatureMin())) diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_01.java index 834bbcfe34d..e19634b3d4b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_01.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_04; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_04_01 extends A5_04 { public A5_04_01(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02.java index eca1cfe0338..f9da35cf77b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_04; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_04_02 extends A5_04 { public A5_04_02(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02_Eltako.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02_Eltako.java index 47a30b204e7..0d661d0ab00 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02_Eltako.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_02_Eltako.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.QuantityType; @@ -26,6 +28,7 @@ import org.openhab.core.types.State; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_04_02_Eltako extends A5_04_02 { public A5_04_02_Eltako(ERP1Message packet) { @@ -34,9 +37,9 @@ public class A5_04_02_Eltako extends A5_04_02 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_BATTERY_VOLTAGE)) { - double voltage = getDB_3Value() * 6.58 / 255.0; // not sure if this is right + double voltage = getDB3Value() * 6.58 / 255.0; // not sure if this is right return new QuantityType<>(voltage, Units.VOLT); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_03.java index 9e39ed10ec4..fcfe7e981ac 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_04/A5_04_03.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_04; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_04_03 extends A5_04 { public A5_04_03(ERP1Message packet) { @@ -41,7 +43,7 @@ public class A5_04_03 extends A5_04 { @Override protected int getUnscaledTemperatureValue() { - return getDB_1Value() + ((getDB_2Value() & 0b11) << 8); + return getDB1Value() + ((getDB2Value() & 0b11) << 8); } @Override @@ -51,6 +53,6 @@ public class A5_04_03 extends A5_04 { @Override protected int getUnscaledHumidityValue() { - return getDB_3Value(); + return getDB3Value(); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01.java index 5ca5977be8e..242da8c6012 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_06_01 extends _4BSMessage { public A5_06_01(ERP1Message packet) { @@ -35,7 +38,7 @@ public class A5_06_01 extends _4BSMessage { } private State getBatteryVoltage() { - int db3 = getDB_3Value(); + int db3 = getDB3Value(); double voltage = db3 / 50.0; // 0..255 = 0.0..5.1V @@ -43,16 +46,16 @@ public class A5_06_01 extends _4BSMessage { } private State getIllumination() { - boolean rs = getBit(getDB_0(), 0); + boolean rs = getBit(getDB0(), 0); - double illumination = rs ? getDB_2Value() * 116.48 + 300.0 : getDB_1Value() * 232.94 + 600.0; + double illumination = rs ? getDB2Value() * 116.48 + 300.0 : getDB1Value() * 232.94 + 600.0; return new QuantityType<>(illumination, Units.LUX); } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_BATTERY_VOLTAGE: return getBatteryVoltage(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01_ELTAKO.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01_ELTAKO.java index 7729bc1cfe2..dd84840d523 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01_ELTAKO.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_06/A5_06_01_ELTAKO.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_06_01_ELTAKO extends _4BSMessage { public A5_06_01_ELTAKO(ERP1Message packet) { @@ -35,10 +38,10 @@ public class A5_06_01_ELTAKO extends _4BSMessage { } private State getIllumination() { - int db2 = getDB_2Value(); + int db2 = getDB2Value(); if (db2 == 0) { - int db3 = getDB_3Value(); + int db3 = getDB3Value(); return new QuantityType<>(db3 * 0.5, Units.LUX); } else { return new QuantityType<>(db2 * 116.48 + 300.0, Units.LUX); @@ -47,7 +50,7 @@ public class A5_06_01_ELTAKO extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_ILLUMINATION: return getIllumination(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07.java index 94cb44b6cc9..1dc8a24e2f4 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class A5_07 extends _4BSMessage { public A5_07(ERP1Message packet) { @@ -52,8 +55,7 @@ public abstract class A5_07 extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_ILLUMINATION)) { return getIllumination(); } else if (channelId.equals(CHANNEL_MOTIONDETECTION)) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_01.java index f78afde675b..3555d6438e8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_01.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_07; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.OnOffType; import org.openhab.core.types.State; @@ -21,9 +22,10 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_07_01 extends A5_07 { - private final int PIR_OFF = 0x7f; + private static final int PIR_OFF = 0x7f; public A5_07_01(ERP1Message packet) { super(packet); @@ -36,15 +38,15 @@ public class A5_07_01 extends A5_07 { @Override protected State getMotion() { - return getDB_1Value() <= PIR_OFF ? OnOffType.OFF : OnOffType.ON; + return getDB1Value() <= PIR_OFF ? OnOffType.OFF : OnOffType.ON; } @Override protected State getSupplyVoltage() { - if (!getBit(getDB_0Value(), 0)) { + if (!getBit(getDB0Value(), 0)) { return UnDefType.UNDEF; } - return getSupplyVoltage(getDB_3Value()); + return getSupplyVoltage(getDB3Value()); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_02.java index 6f9e15ed89f..98b0723574b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_02.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_07; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.OnOffType; import org.openhab.core.types.State; @@ -21,6 +22,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_07_02 extends A5_07 { public A5_07_02(ERP1Message packet) { @@ -34,11 +36,11 @@ public class A5_07_02 extends A5_07 { @Override protected State getMotion() { - return getBit(getDB_0Value(), 7) ? OnOffType.ON : OnOffType.OFF; + return getBit(getDB0Value(), 7) ? OnOffType.ON : OnOffType.OFF; } @Override protected State getSupplyVoltage() { - return getSupplyVoltage(getDB_3Value()); + return getSupplyVoltage(getDB3Value()); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_03.java index 4a996b1c6d4..89f743663ef 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_07/A5_07_03.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_07; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.Units; @@ -21,6 +22,7 @@ import org.openhab.core.types.State; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_07_03 extends A5_07_02 { public A5_07_03(ERP1Message packet) { @@ -29,6 +31,6 @@ public class A5_07_03 extends A5_07_02 { @Override protected State getIllumination() { - return new QuantityType<>((getDB_2Value() << 8) + ((getDB_1Value() & 0b11000000) >>> 6), Units.LUX); + return new QuantityType<>((getDB2Value() << 8) + ((getDB1Value() & 0b11000000) >>> 6), Units.LUX); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08.java index a8eb2b25d22..13630dc2f35 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -30,6 +32,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class A5_08 extends _4BSMessage { public A5_08(ERP1Message packet) { @@ -61,17 +64,16 @@ public abstract class A5_08 extends _4BSMessage { protected abstract double getScaledIlluminationMax(); protected int getUnscaledTemperatureValue() { - return getDB_1Value(); + return getDB1Value(); } protected int getUnscaledIlluminationValue() { - return getDB_2Value(); + return getDB2Value(); } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_TEMPERATURE)) { double scaledTemp = getScaledTemperatureMin() + ((getUnscaledTemperatureValue() * (getScaledTemperatureMax() - getScaledTemperatureMin())) @@ -83,9 +85,9 @@ public abstract class A5_08 extends _4BSMessage { / (getUnscaledIlluminationMax() - getUnscaledIlluminationMin())); return new QuantityType<>(scaledIllumination, Units.LUX); } else if (channelId.equals(CHANNEL_MOTIONDETECTION)) { - return getBit(getDB_0(), 1) ? OnOffType.OFF : OnOffType.ON; + return getBit(getDB0(), 1) ? OnOffType.OFF : OnOffType.ON; } else if (channelId.equals(CHANNEL_OCCUPANCY)) { - return getBit(getDB_0(), 0) ? OnOffType.OFF : OnOffType.ON; + return getBit(getDB0(), 0) ? OnOffType.OFF : OnOffType.ON; } return UnDefType.UNDEF; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01.java index b0f45aab2e2..adfd2fac816 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_08; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_08_01 extends A5_08 { public A5_08_01(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01_FXBH.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01_FXBH.java index d5862f2557a..358316d2a1c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01_FXBH.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_01_FXBH.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_08; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_08_01_FXBH extends A5_08 { public A5_08_01_FXBH(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_02.java index 7dd70905804..43f96ea528a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_02.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_08; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_08_02 extends A5_08 { public A5_08_02(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_03.java index fd972ca3f2c..0c838287bc5 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_08/A5_08_03.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_08; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_08_03 extends A5_08 { public A5_08_03(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10.java index 1df6cae43ee..a7816925268 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -31,6 +33,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class A5_10 extends _4BSMessage { public A5_10(ERP1Message packet) { @@ -39,31 +42,30 @@ public abstract class A5_10 extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_FANSPEEDSTAGE: - if (getDB_3Value() > 209) { + if (getDB3Value() > 209) { return new StringType("-1"); - } else if (getDB_3Value() > 189) { + } else if (getDB3Value() > 189) { return new StringType("0"); - } else if (getDB_3Value() > 164) { + } else if (getDB3Value() > 164) { return new StringType("1"); - } else if (getDB_3Value() > 144) { + } else if (getDB3Value() > 144) { return new StringType("2"); } else { return new StringType("3"); } case CHANNEL_SETPOINT: - return new DecimalType(getDB_2Value()); + return new DecimalType(getDB2Value()); case CHANNEL_TEMPERATURE: - double temp = (getDB_1Value() - 255) / -6.375; + double temp = (getDB1Value() - 255) / -6.375; return new QuantityType<>(temp, SIUnits.CELSIUS); case CHANNEL_OCCUPANCY: - return getBit(getDB_0(), 0) ? OnOffType.OFF : OnOffType.ON; + return getBit(getDB0(), 0) ? OnOffType.OFF : OnOffType.ON; } return UnDefType.UNDEF; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_01.java index f22b2a9bd68..225cfb6b943 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_01.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_01 extends A5_10 { public A5_10_01(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_02.java index 40b0b8c97fd..f470b678b8d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_02.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_02 extends A5_10 { public A5_10_02(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_03.java index bdfab5b1d86..372a6bbd27f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_03.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_03 extends A5_10 { public A5_10_03(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_04.java index d93f9e79940..69da5b52594 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_04.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_04 extends A5_10 { public A5_10_04(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_05.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_05.java index 8dfc26a3455..96785ec1fd2 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_05.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_05.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_05 extends A5_10 { public A5_10_05(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_06.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_06.java index 8c169236e7a..42e8a21022f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_06.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_06.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_06 extends A5_10 { public A5_10_06(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_07.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_07.java index 8c6ebd9192a..c08e65ee918 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_07.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_07.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_07 extends A5_10 { public A5_10_07(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_08.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_08.java index 03877a410f7..a38cc728129 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_08.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_08.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_08 extends A5_10 { public A5_10_08(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_09.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_09.java index 8aa3b61fb85..3f683e55300 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_09.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_09.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_09 extends A5_10 { public A5_10_09(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0A.java index ce16dc5bc67..029799044f9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0A.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_0A extends A5_10 { public A5_10_0A(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0B.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0B.java index a59106119ed..5649ae8ee77 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0B.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0B.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_0B extends A5_10 { public A5_10_0B(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0C.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0C.java index 0deb7539b1e..7c47e6af64f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0C.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0C.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_0C extends A5_10 { public A5_10_0C(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0D.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0D.java index a028be3215a..fd9fd87006f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0D.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_0D.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_0D extends A5_10 { public A5_10_0D(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_10.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_10.java index 917438795c9..e6e98a1a31f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_10.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_10.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_10 extends A5_10 { public A5_10_10(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_11.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_11.java index 4d8f90b9196..78f53cd4c06 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_11.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_11.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_11 extends A5_10 { public A5_10_11(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_12.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_12.java index b3c1e0c89a8..e9a8b66653c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_12.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_12.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_12 extends A5_10 { public A5_10_12(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_13.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_13.java index 454c9d42cb0..f647693e4e9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_13.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_13.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_13 extends A5_10 { public A5_10_13(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_14.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_14.java index 73f669ef743..7085dac6263 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_14.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_14.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_14 extends A5_10 { public A5_10_14(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_15.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_15.java index 17fa58c45e7..2cb138589fd 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_15.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_15.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_15 extends A5_10 { public A5_10_15(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_16.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_16.java index d83d8d0837d..af61d6b2113 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_16.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_16.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_16 extends A5_10 { public A5_10_16(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_17.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_17.java index 8fa706c9ef8..544a625a6ea 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_17.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_17.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_17 extends A5_10 { public A5_10_17(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_18.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_18.java index 76d82ad0a74..519177ade7e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_18.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_18.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_18 extends A5_10 { public A5_10_18(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_19.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_19.java index 9dd5387d9f1..9cef98b3dcf 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_19.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_19.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_19 extends A5_10 { public A5_10_19(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1A.java index 489e19df064..e3552cbafe8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1A.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_1A extends A5_10 { public A5_10_1A(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1B.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1B.java index 95484747a3d..bcf8d06f8d9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1B.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1B.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_1B extends A5_10 { public A5_10_1B(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1C.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1C.java index 40dc181fcb2..e0d53831ac8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1C.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1C.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_1C extends A5_10 { public A5_10_1C(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1D.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1D.java index 841a963322d..462e7798f51 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1D.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1D.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_1D extends A5_10 { public A5_10_1D(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1E.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1E.java index 719f3bb243a..9e38b33c166 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1E.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1E.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_1E extends A5_10 { public A5_10_1E(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1F.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1F.java index 14b015df745..f23d5a7df74 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1F.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_1F.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_1F extends A5_10 { public A5_10_1F(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_20.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_20.java index c312d5cd61f..36b66763dc8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_20.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_20.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_20 extends A5_10 { public A5_10_20(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_21.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_21.java index 90c992f75bd..4fa75dcc8b6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_21.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_21.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_21 extends A5_10 { public A5_10_21(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_22.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_22.java index 92609d1fdd2..1a8d62a1706 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_22.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_22.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_22 extends A5_10 { public A5_10_22(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_23.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_23.java index b4b57fb95e8..b29dc632700 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_23.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_10/A5_10_23.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.A5_10; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_10_23 extends A5_10 { public A5_10_23(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_03.java index 7ae30eeea5c..e00d9dac70c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_03.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -29,6 +31,7 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_11_03 extends _4BSMessage { public A5_11_03(ERP1Message packet) { @@ -36,7 +39,7 @@ public class A5_11_03 extends _4BSMessage { } protected boolean isErrorState() { - byte db1 = getDB_1(); + byte db1 = getDB1(); int state = (db1 >> 4) & 0x03; @@ -45,14 +48,14 @@ public class A5_11_03 extends _4BSMessage { } protected State getPositionData() { - byte db1 = getDB_1(); + byte db1 = getDB1(); boolean pvf = getBit(db1, 7); if (pvf) { - byte db0 = getDB_0(); + byte db0 = getDB0(); boolean motp = getBit(db0, 6); - int bsp = getDB_3Value(); + int bsp = getDB3Value(); if ((bsp >= 0) && (bsp <= 100)) { return new PercentType(motp ? 100 - bsp : bsp); @@ -63,11 +66,11 @@ public class A5_11_03 extends _4BSMessage { } protected State getAngleData() { - byte db1 = getDB_1(); + byte db1 = getDB1(); boolean avf = getBit(db1, 6); if (avf) { - byte db2 = getDB_2(); + byte db2 = getDB2(); boolean as = getBit(db2, 7); int an = (db2 & 0x7F) * 2; @@ -82,7 +85,7 @@ public class A5_11_03 extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (isErrorState()) { return UnDefType.UNDEF; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_04.java index 7306976dcf4..05b5297180e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_11/A5_11_04.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.eep.EEPHelper; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -35,7 +37,7 @@ import org.slf4j.LoggerFactory; * * @author Vincent Bakker - Initial contribution */ - +@NonNullByDefault public class A5_11_04 extends _4BSMessage { private enum Error { @@ -64,14 +66,14 @@ public class A5_11_04 extends _4BSMessage { NOT_SUPPORTED } - private static Logger logger = LoggerFactory.getLogger(A5_11_04.class); + private Logger logger = LoggerFactory.getLogger(A5_11_04.class); public A5_11_04(ERP1Message packet) { super(packet); } protected boolean isErrorState() { - byte db0 = getDB_0(); + byte db0 = getDB0(); int state = (db0 >> 4) & 0x03; @@ -85,12 +87,12 @@ public class A5_11_04 extends _4BSMessage { } protected ParameterMode getParameterMode() { - int pm = (getDB_0() >> 1) & 0x03; + int pm = (getDB0() >> 1) & 0x03; return ParameterMode.values()[pm]; } protected EnergyUnit getEnergyUnit() { - int unit = getDB_1(); + int unit = getDB1(); if (unit < 8) { return EnergyUnit.values()[unit]; } @@ -99,7 +101,7 @@ public class A5_11_04 extends _4BSMessage { } protected State getLightingStatus() { - byte db0 = getDB_0(); + byte db0 = getDB0(); boolean lightOn = getBit(db0, 0); return lightOn ? OnOffType.ON : OnOffType.OFF; @@ -107,7 +109,7 @@ public class A5_11_04 extends _4BSMessage { protected State getDimmerStatus() { if (getParameterMode() == ParameterMode.EIGHT_BIT_DIMMER_VALUE_AND_LAMP_OPERATING_HOURS) { - return new PercentType(getDB_3Value() * 100 / 255); + return new PercentType(getDB3Value() * 100 / 255); } return UnDefType.UNDEF; } @@ -134,7 +136,7 @@ public class A5_11_04 extends _4BSMessage { } return new QuantityType<>( - Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2() }), 16) * factor, + Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2() }), 16) * factor, Units.KILOWATT_HOUR); } @@ -163,7 +165,7 @@ public class A5_11_04 extends _4BSMessage { } return new QuantityType<>( - Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2() }), 16) * factor, Units.WATT); + Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2() }), 16) * factor, Units.WATT); } return UnDefType.UNDEF; @@ -171,7 +173,7 @@ public class A5_11_04 extends _4BSMessage { protected State getOperatingHours() { if (getParameterMode() == ParameterMode.EIGHT_BIT_DIMMER_VALUE_AND_LAMP_OPERATING_HOURS) { - return new DecimalType(getDB_2Value() << 8 + getDB_1Value()); + return new DecimalType(getDB2Value() << 8 + getDB1Value()); } return UnDefType.UNDEF; @@ -179,7 +181,7 @@ public class A5_11_04 extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (isErrorState()) { return UnDefType.UNDEF; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12.java index 5b75806bfc2..539bd24f73d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelTariffInfoConfig; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.eep.EEPHelper; @@ -31,6 +33,7 @@ import org.openhab.core.util.HexUtils; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public abstract class A5_12 extends _4BSMessage { public A5_12(ERP1Message packet) { super(packet); @@ -45,7 +48,7 @@ public abstract class A5_12 extends _4BSMessage { } protected State getCumulativeValue() { - byte db0 = getDB_0(); + byte db0 = getDB0(); boolean dt = getBit(db0, 2); if (!dt) { @@ -70,8 +73,8 @@ public abstract class A5_12 extends _4BSMessage { return UnDefType.UNDEF; } - float cumulativeValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2(), getDB_1() }), - 16) * factor; + float cumulativeValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2(), getDB1() }), 16) + * factor; return calcCumulativeValue(cumulativeValue); } @@ -79,7 +82,7 @@ public abstract class A5_12 extends _4BSMessage { } protected State getCurrentValue() { - byte db0 = getDB_0(); + byte db0 = getDB0(); boolean dt = getBit(db0, 2); if (dt) { @@ -104,7 +107,7 @@ public abstract class A5_12 extends _4BSMessage { return UnDefType.UNDEF; } - float currentValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2(), getDB_1() }), 16) + float currentValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2(), getDB1() }), 16) * factor; return calcCurrentValue(currentValue); @@ -114,13 +117,12 @@ public abstract class A5_12 extends _4BSMessage { } protected int getTariffInfo() { - return ((getDB_0() >>> 4) & 0xff); + return ((getDB0() >>> 4) & 0xff); } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { EnOceanChannelTariffInfoConfig c = config.as(EnOceanChannelTariffInfoConfig.class); if (c.tariff != getTariffInfo()) { return UnDefType.UNDEF; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_00.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_00.java index c6742c8e592..7739afed900 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_00.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_00.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_12; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.Units; @@ -21,6 +22,7 @@ import org.openhab.core.types.State; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_12_00 extends A5_12 { public A5_12_00(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_01.java index 1061a68cf51..052f711a260 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_01.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_12; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.Units; @@ -21,6 +22,7 @@ import org.openhab.core.types.State; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_12_01 extends A5_12 { public A5_12_01(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_02.java index d58b5e6dcd1..312d7f0cc6e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_02.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_12; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SIUnits; @@ -22,6 +23,7 @@ import org.openhab.core.types.State; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_12_02 extends A5_12 { public A5_12_02(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_03.java index 8b88985b34a..46cb12c5486 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_12/A5_12_03.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_12; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SIUnits; @@ -22,6 +23,7 @@ import org.openhab.core.types.State; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_12_03 extends A5_12 { public A5_12_03(ERP1Message packet) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13.java index 2be92f29683..d1821d59a6f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_13; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -20,16 +21,17 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class A5_13 extends _4BSMessage { public A5_13(ERP1Message packet) { super(packet); } - protected final int PARTONE = 0x10; - protected final int PARTTWO = 0x20; + protected static final int PARTONE = 0x10; + protected static final int PARTTWO = 0x20; protected int getMessageIdentifier() { - return getDB_0Value() & 0xF0; + return getDB0Value() & 0xF0; } protected boolean isPartOne() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13_01.java index c31985851ba..d86109c62a3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_13/A5_13_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.OnOffType; @@ -30,6 +32,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_13_01 extends A5_13 { public A5_13_01(ERP1Message packet) { @@ -37,7 +40,7 @@ public class A5_13_01 extends A5_13 { } protected State getIllumination() { - return new QuantityType<>(((getDB_3Value() * 1000.0) / 255.0), Units.LUX); + return new QuantityType<>(((getDB3Value() * 1000.0) / 255.0), Units.LUX); } protected State getIllumination(double value) { @@ -45,32 +48,32 @@ public class A5_13_01 extends A5_13 { } protected State getIlluminationWest() { - return getIllumination(getDB_3Value()); + return getIllumination(getDB3Value()); } protected State getIlluminationSouthNorth() { - return getIllumination(getDB_2Value()); + return getIllumination(getDB2Value()); } protected State getIlluminationEast() { - return getIllumination(getDB_1Value()); + return getIllumination(getDB1Value()); } protected State getTemperature() { - return new QuantityType<>(-40.0 + ((getDB_2Value() * 120.0) / 255.0), SIUnits.CELSIUS); + return new QuantityType<>(-40.0 + ((getDB2Value() * 120.0) / 255.0), SIUnits.CELSIUS); } protected State getWindSpeed() { - return new QuantityType<>(((getDB_1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND); + return new QuantityType<>(((getDB1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND); } protected State getRainStatus() { - return getBit(getDB_0Value(), 1) ? OnOffType.ON : OnOffType.OFF; + return getBit(getDB0Value(), 1) ? OnOffType.ON : OnOffType.OFF; } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (isPartOne()) { switch (channelId) { case CHANNEL_ILLUMINATION: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14.java index c7e66a0f5eb..99e9c6148fe 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,13 +30,14 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public abstract class A5_14 extends _4BSMessage { public A5_14(ERP1Message packet) { super(packet); } private State getBatteryVoltage() { - int db3 = getDB_3Value(); + int db3 = getDB3Value(); if (db3 > 250) { logger.warn("EEP A5-14 error code {}", db3); @@ -48,7 +51,7 @@ public abstract class A5_14 extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_BATTERY_VOLTAGE: return getBatteryVoltage(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01.java index b839ceb1bf4..1f2d6f5c3f6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -27,6 +29,7 @@ import org.openhab.core.types.State; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_14_01 extends A5_14 { public A5_14_01(ERP1Message packet) { @@ -34,7 +37,7 @@ public class A5_14_01 extends A5_14 { } private State getContact(boolean inverted) { - boolean ct = getBit(getDB_0(), 0); + boolean ct = getBit(getDB0(), 0); if (inverted) { return ct ? OpenClosedType.CLOSED : OpenClosedType.OPEN; @@ -45,7 +48,7 @@ public class A5_14_01 extends A5_14 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_CONTACT: EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01_ELTAKO.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01_ELTAKO.java index 995f10cebc0..c8618197924 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01_ELTAKO.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_01_ELTAKO.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_14_01_ELTAKO extends _4BSMessage { public A5_14_01_ELTAKO(ERP1Message packet) { @@ -35,7 +38,7 @@ public class A5_14_01_ELTAKO extends _4BSMessage { } private State getEnergyStorage() { - int db3 = getDB_3Value(); + int db3 = getDB3Value(); double voltage = db3 / 51.0; // 0..255 = 0.0..5.0V @@ -43,7 +46,7 @@ public class A5_14_01_ELTAKO extends _4BSMessage { } private State getBatteryVoltage() { - int db2 = getDB_2Value(); + int db2 = getDB2Value(); double voltage = db2 / 51.0; // 0..255 = 0.0..5.0V @@ -52,7 +55,7 @@ public class A5_14_01_ELTAKO extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_ENERGY_STORAGE: return getEnergyStorage(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_09.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_09.java index 92207d8199a..50c1511accf 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_09.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_09.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -29,17 +31,18 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Krickl-Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_14_09 extends A5_14 { - public final byte CLOSED = (byte) 0x00; - public final byte TILTED = (byte) 0x01; - public final byte OPEN = (byte) 0x03; + public static final byte CLOSED = (byte) 0x00; + public static final byte TILTED = (byte) 0x01; + public static final byte OPEN = (byte) 0x03; public A5_14_09(ERP1Message packet) { super(packet); } private State getWindowhandleState() { - byte ct = (byte) ((getDB_0() & 0x06) >> 1); + byte ct = (byte) ((getDB0() & 0x06) >> 1); switch (ct) { case CLOSED: @@ -54,7 +57,7 @@ public class A5_14_09 extends A5_14 { } private State getContact(boolean inverted) { - byte ct = (byte) ((getDB_0() & 0x06) >> 1); + byte ct = (byte) ((getDB0() & 0x06) >> 1); switch (ct) { case CLOSED: @@ -69,7 +72,7 @@ public class A5_14_09 extends A5_14 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_WINDOWHANDLESTATE: return getWindowhandleState(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_0A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_0A.java index ebcac43e9cf..c52e3d5efa8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_0A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_14/A5_14_0A.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.OnOffType; @@ -27,19 +29,20 @@ import org.openhab.core.types.State; * * @author Stefan Schimanski - Initial contribution */ +@NonNullByDefault public class A5_14_0A extends A5_14_09 { public A5_14_0A(ERP1Message packet) { super(packet); } private State getVibration() { - boolean alarm = getBit(getDB_0(), 0); + boolean alarm = getBit(getDB0(), 0); return alarm ? OnOffType.ON : OnOffType.OFF; } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_VIBRATION)) { return getVibration(); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20.java index 52bc8303bc0..0f3954b97ba 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.A5_20; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -21,6 +22,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; * * @author Dominik Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_20 extends _4BSMessage { public A5_20() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java index 63df82925ba..d79601dc396 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java @@ -18,6 +18,8 @@ import java.util.function.Function; import javax.measure.quantity.Temperature; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.DecimalType; @@ -35,6 +37,7 @@ import org.openhab.core.types.UnDefType; * * @author Dominik Vorreiter - Initial contribution */ +@NonNullByDefault public class A5_20_04 extends A5_20 { public A5_20_04() { @@ -46,7 +49,7 @@ public class A5_20_04 extends A5_20 { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { switch (channelId) { case CHANNEL_STATUS_REQUEST_EVENT: @@ -57,14 +60,14 @@ public class A5_20_04 extends A5_20 { } private String getStatusRequestEvent() { - return Boolean.valueOf(getBit(getDB_0Value(), 6)).toString(); + return Boolean.valueOf(getBit(getDB0Value(), 6)).toString(); // return getBit(getDB_0Value(), 6) ? "triggered" : null; } private byte getPos(Function getCurrentStateFunc) { State current = getCurrentStateFunc.apply(CHANNEL_VALVE_POSITION); - if ((current != null) && (current instanceof DecimalType)) { + if (current instanceof DecimalType) { DecimalType state = current.as(DecimalType.class); if (state != null) { @@ -80,7 +83,7 @@ public class A5_20_04 extends A5_20 { double value = 20.0; // 20 °C - if ((current != null) && (current instanceof QuantityType)) { + if (current instanceof QuantityType) { @SuppressWarnings("unchecked") QuantityType raw = current.as(QuantityType.class); @@ -99,7 +102,7 @@ public class A5_20_04 extends A5_20 { private byte getMc(Function getCurrentStateFunc) { State current = getCurrentStateFunc.apply(CHANNEL_MEASUREMENT_CONTROL); - if ((current != null) && (current instanceof OnOffType)) { + if (current instanceof OnOffType) { OnOffType state = current.as(OnOffType.class); if (state != null) { @@ -113,7 +116,7 @@ public class A5_20_04 extends A5_20 { private byte getWuc(Function getCurrentStateFunc) { State current = getCurrentStateFunc.apply(CHANNEL_WAKEUPCYCLE); - if ((current != null) && (current instanceof DecimalType)) { + if (current instanceof DecimalType) { DecimalType state = current.as(DecimalType.class); if (state != null) { @@ -127,7 +130,7 @@ public class A5_20_04 extends A5_20 { private byte getDso(Function getCurrentStateFunc) { State current = getCurrentStateFunc.apply(CHANNEL_DISPLAY_ORIENTATION); - if ((current != null) && (current instanceof DecimalType)) { + if (current instanceof DecimalType) { DecimalType state = current.as(DecimalType.class); if (state != null) { @@ -141,7 +144,7 @@ public class A5_20_04 extends A5_20 { private byte getBlc(Function getCurrentStateFunc) { State current = getCurrentStateFunc.apply(CHANNEL_BUTTON_LOCK); - if ((current != null) && (current instanceof OnOffType)) { + if (current instanceof OnOffType) { OnOffType state = current.as(OnOffType.class); if (state != null) { @@ -155,7 +158,7 @@ public class A5_20_04 extends A5_20 { private byte getSer(Function getCurrentStateFunc) { State current = getCurrentStateFunc.apply(CHANNEL_SERVICECOMMAND); - if ((current != null) && (current instanceof DecimalType)) { + if (current instanceof DecimalType) { DecimalType state = current.as(DecimalType.class); if (state != null) { @@ -168,12 +171,12 @@ public class A5_20_04 extends A5_20 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (VIRTUALCHANNEL_SEND_COMMAND.equals(channelId)) { byte db3 = getPos(getCurrentStateFunc); byte db2 = getTsp(getCurrentStateFunc); byte db1 = (byte) (0x00 | getMc(getCurrentStateFunc) | getWuc(getCurrentStateFunc)); - byte db0 = (byte) (0x00 | getDso(getCurrentStateFunc) | TeachInBit | getBlc(getCurrentStateFunc) + byte db0 = (byte) (0x00 | getDso(getCurrentStateFunc) | TEACHIN_BIT | getBlc(getCurrentStateFunc) | getSer(getCurrentStateFunc)); setData(db3, db2, db1, db0); @@ -184,7 +187,7 @@ public class A5_20_04 extends A5_20 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_VALVE_POSITION: return getValvePosition(); @@ -206,62 +209,62 @@ public class A5_20_04 extends A5_20 { } private State getTemperature() { - boolean fl = getBit(getDB_0Value(), 0); - boolean mst = getBit(getDB_0Value(), 7); + boolean fl = getBit(getDB0Value(), 0); + boolean mst = getBit(getDB0Value(), 7); if (fl || mst) { return UnDefType.UNDEF; } - double value = getDB_1Value() * (20.0 / 255.0) + 10.0; + double value = getDB1Value() * (20.0 / 255.0) + 10.0; return new QuantityType<>(value, SIUnits.CELSIUS); } private State getFailureCode() { - boolean fl = getBit(getDB_0Value(), 0); + boolean fl = getBit(getDB0Value(), 0); if (!fl) { return new QuantityType<>(-1, Units.ONE); } - return new QuantityType<>(getDB_1Value(), Units.ONE); + return new QuantityType<>(getDB1Value(), Units.ONE); } private State getMeasurementControl() { - return getBit(getDB_0Value(), 7) ? OnOffType.OFF : OnOffType.ON; + return getBit(getDB0Value(), 7) ? OnOffType.OFF : OnOffType.ON; } private State getFeedTemperature() { - boolean ts = getBit(getDB_0Value(), 1); - boolean mst = getBit(getDB_0Value(), 7); + boolean ts = getBit(getDB0Value(), 1); + boolean mst = getBit(getDB0Value(), 7); if (ts || mst) { return UnDefType.UNDEF; } - double value = getDB_2Value() * (60.0 / 255.0) + 20.0; + double value = getDB2Value() * (60.0 / 255.0) + 20.0; return new QuantityType<>(value, SIUnits.CELSIUS); } private State getTemperatureSetpoint() { - boolean ts = getBit(getDB_0Value(), 1); + boolean ts = getBit(getDB0Value(), 1); if (!ts) { return UnDefType.UNDEF; } - double value = getDB_2Value() * (20.0 / 255.0) + 10.0; + double value = getDB2Value() * (20.0 / 255.0) + 10.0; return new QuantityType<>(value, SIUnits.CELSIUS); } private State getButtonLock() { - return getBit(getDB_0Value(), 2) ? OnOffType.ON : OnOffType.OFF; + return getBit(getDB0Value(), 2) ? OnOffType.ON : OnOffType.OFF; } private State getValvePosition() { - return new QuantityType<>(getDB_3Value(), Units.PERCENT); + return new QuantityType<>(getDB3Value(), Units.PERCENT); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03.java index 820adc14740..8c1646b7e0c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_30_03 extends _4BSMessage { protected static final byte ALL_DIGITALPINS_HIGH = 0x0F; @@ -47,10 +50,10 @@ public class A5_30_03 extends _4BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_TEMPERATURE: - double temp = (getDB_2Value() - 255) / -6.375; + double temp = (getDB2Value() - 255) / -6.375; return new QuantityType<>(temp, SIUnits.CELSIUS); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03_ELTAKO.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03_ELTAKO.java index f199ff2ed48..44869c9acc6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03_ELTAKO.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_30/A5_30_03_ELTAKO.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.OnOffType; @@ -27,6 +29,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_30_03_ELTAKO extends A5_30_03 { protected static final byte ALARM_ON = 0x0F; @@ -46,8 +49,8 @@ public class A5_30_03_ELTAKO extends A5_30_03 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - byte db1 = getDB_1(); + Function getCurrentStateFunc, Configuration config) { + byte db1 = getDB1(); switch (channelId) { case CHANNEL_SMOKEDETECTION: return db1 == ALARM_ON ? OnOffType.ON : (db1 == ALARM_OFF ? OnOffType.OFF : UnDefType.UNDEF); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java index 42ddcf1cc4f..a48bb39afbb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -34,6 +36,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_38_08_Blinds extends _4BSMessage { static final byte COMMAND_ID = 0x07; @@ -63,10 +66,10 @@ public class A5_38_08_Blinds extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { switch (channelId) { case CHANNEL_ROLLERSHUTTER: - byte db0 = ZERO | SEND_NEW_STATE | TeachInBit; + byte db0 = ZERO | SEND_NEW_STATE | TEACHIN_BIT; byte db1 = ZERO; byte db2 = ZERO; @@ -114,11 +117,11 @@ public class A5_38_08_Blinds extends _4BSMessage { } protected State getPositionData() { - byte db0 = getDB_0(); + byte db0 = getDB0(); boolean paf = getBit(db0, 1); if (paf) { - int bsp = getDB_2Value(); + int bsp = getDB2Value(); if ((bsp >= 0) && (bsp <= 100)) { return new PercentType(bsp); @@ -129,11 +132,11 @@ public class A5_38_08_Blinds extends _4BSMessage { } protected State getAngleData() { - byte db0 = getDB_0(); + byte db0 = getDB0(); boolean paf = getBit(db0, 1); if (paf) { - byte db1 = getDB_1(); + byte db1 = getDB1(); boolean as = getBit(db1, 7); int an = (db1 & 0x7F) * 2; @@ -147,8 +150,8 @@ public class A5_38_08_Blinds extends _4BSMessage { } @Override - public State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, - Configuration config) { + public State convertToStateImpl(String channelId, String channelTypeId, + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_ROLLERSHUTTER: return getPositionData(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java index 058291541fa..148b5fc7038 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java @@ -17,6 +17,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.ZERO; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelDimmerConfig; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -38,12 +40,13 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_38_08_Dimming extends _4BSMessage { - static final byte CommandId = 0x02; - static final byte SwitchOff = 0x00; - static final byte SwitchOn = 0x01; - static final byte Switch100Percent = 0x64; + static final byte COMMAND_ID = 0x02; + static final byte SWITCH_OFF = 0x00; + static final byte SWITCH_ON = 0x01; + static final byte SWITCH_100_PERCENT = 0x64; public A5_38_08_Dimming() { super(); @@ -55,7 +58,7 @@ public class A5_38_08_Dimming extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { switch (channelId) { case CHANNEL_DIMMER: byte dimmValue; @@ -63,58 +66,61 @@ public class A5_38_08_Dimming extends _4BSMessage { if (outputCommand instanceof DecimalType) { dimmValue = ((DecimalType) outputCommand).byteValue(); } else if (outputCommand instanceof OnOffType) { - dimmValue = ((OnOffType) outputCommand == OnOffType.ON) ? Switch100Percent : ZERO; + dimmValue = ((OnOffType) outputCommand == OnOffType.ON) ? SWITCH_100_PERCENT : ZERO; } else if (outputCommand instanceof IncreaseDecreaseType) { dimmValue = ((IncreaseDecreaseType) outputCommand == IncreaseDecreaseType.INCREASE) - ? Switch100Percent + ? SWITCH_100_PERCENT : ZERO; } else if (outputCommand instanceof UpDownType) { - dimmValue = ((UpDownType) outputCommand == UpDownType.UP) ? Switch100Percent : ZERO; + dimmValue = ((UpDownType) outputCommand == UpDownType.UP) ? SWITCH_100_PERCENT : ZERO; } else { throw new IllegalArgumentException(outputCommand.toFullString() + " is no valid dimming command."); } + if (config != null) { + EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class); - EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class); + byte storeByte = ZERO; // "Store final value" (standard) vs. "block value" (Eltako) - byte storeByte = ZERO; // "Store final value" (standard) vs. "block value" (Eltako) + if (!c.eltakoDimmer) { + dimmValue *= 2.55; // 0-100% = 0-255 - if (!c.eltakoDimmer) { - dimmValue *= 2.55; // 0-100% = 0-255 - - if (c.storeValue) { - storeByte = 0x02; // set DB0.1 + if (c.storeValue) { + storeByte = 0x02; // set DB0.1 + } + } else { + if (c.storeValue) { + storeByte = 0x04; // set DB0.2 + } } + + byte rampingTime = Integer.valueOf(c.rampingTime).byteValue(); + byte switchingCommand = (dimmValue == ZERO) ? SWITCH_OFF : SWITCH_ON; + + setData(COMMAND_ID, dimmValue, rampingTime, (byte) (TEACHIN_BIT | storeByte | switchingCommand)); } else { - if (c.storeValue) { - storeByte = 0x04; // set DB0.2 - } + logger.error("Cannot handle command {}, when configuration is null", outputCommand.toFullString()); } - byte rampingTime = Integer.valueOf(c.rampingTime).byteValue(); - byte switchingCommand = (dimmValue == ZERO) ? SwitchOff : SwitchOn; - - setData(CommandId, dimmValue, rampingTime, (byte) (TeachInBit | storeByte | switchingCommand)); - break; } } @Override - public State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, - Configuration config) { + public State convertToStateImpl(String channelId, String channelTypeId, + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_DIMMER: - if (!getBit(getDB_0(), 0)) { + if (!getBit(getDB0(), 0)) { // Switching Command is OFF (DB0.0==0), return 0% return new PercentType(0); } else { // DB2 contains the Dimming value (absolute[0...255] or relative/Eltako [0...100]) - int dimmValue = getDB_2Value(); + int dimmValue = getDB2Value(); EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class); // if Standard dimmer and Dimming Range is absolute (DB0.2==0), - if (!c.eltakoDimmer && !getBit(getDB_0(), 2)) { + if (!c.eltakoDimmer && !getBit(getDB0(), 2)) { // map range [0...255] to [0%...100%] dimmValue /= 2.55; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Switching.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Switching.java index a45dca4d672..da79e73d869 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Switching.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Switching.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.ZERO; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -27,11 +29,12 @@ import org.openhab.core.types.State; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_38_08_Switching extends _4BSMessage { - static final byte CommandId = 0x01; - static final byte SwitchOff = 0x00; - static final byte SwitchOn = 0x01; + static final byte COMMAND_ID = 0x01; + static final byte SWITCH_OFF = 0x00; + static final byte SWITCH_ON = 0x01; public A5_38_08_Switching() { super(); @@ -43,11 +46,11 @@ public class A5_38_08_Switching extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if ((OnOffType) outputCommand == OnOffType.ON) { - setData(CommandId, ZERO, ZERO, (byte) (TeachInBit | SwitchOn)); + setData(COMMAND_ID, ZERO, ZERO, (byte) (TEACHIN_BIT | SWITCH_ON)); } else { - setData(CommandId, ZERO, ZERO, (byte) (TeachInBit | SwitchOff)); + setData(COMMAND_ID, ZERO, ZERO, (byte) (TEACHIN_BIT | SWITCH_OFF)); } } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java index 4823f91e330..b10ba909675 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.ZERO; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,15 +30,16 @@ import org.openhab.core.types.UnDefType; /** * - * @author Andreas Hofinger + * @author Andreas Hofinger - Initial contribution */ +@NonNullByDefault public class A5_3F_7F_EltakoFRM extends _4BSMessage { - static final byte Stop = 0x00; - static final byte Move = 0x03; + static final byte STOP = 0x00; + static final byte MOVE = 0x03; - static final int Top = 0xC8; - static final int Bottom = 0x00; + static final int TOP = 0xC8; + static final int BOTTOM = 0x00; public A5_3F_7F_EltakoFRM() { super(); @@ -48,36 +51,34 @@ public class A5_3F_7F_EltakoFRM extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, @Nullable Configuration config) { if (command instanceof PercentType) { PercentType target = (PercentType) command; int rawPosition = Math.round( - (PercentType.HUNDRED.floatValue() - target.floatValue()) * Top / PercentType.HUNDRED.floatValue()); - int position = Math.min(Top, Math.max(Bottom, rawPosition)); - setData((byte) position, ZERO, Move, TeachInBit); + (PercentType.HUNDRED.floatValue() - target.floatValue()) * TOP / PercentType.HUNDRED.floatValue()); + int position = Math.min(TOP, Math.max(BOTTOM, rawPosition)); + setData((byte) position, ZERO, MOVE, TEACHIN_BIT); } else if (command instanceof UpDownType) { if ((UpDownType) command == UpDownType.UP) { - setData((byte) Top, ZERO, Move, TeachInBit); // => 0 percent + setData((byte) TOP, ZERO, MOVE, TEACHIN_BIT); // => 0 percent } else if ((UpDownType) command == UpDownType.DOWN) { - setData((byte) Bottom, ZERO, Move, TeachInBit); // => 100 percent + setData((byte) BOTTOM, ZERO, MOVE, TEACHIN_BIT); // => 100 percent } } else if (command instanceof StopMoveType) { if ((StopMoveType) command == StopMoveType.STOP) { - setData(ZERO, ZERO, Stop, TeachInBit); + setData(ZERO, ZERO, STOP, TEACHIN_BIT); } } } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { // 0x0A.. Move was locked for switch // 0x0E.. Move was not locked - if (getDB_2() == ZERO && getDB_1() == Move && (getDB_0() == 0x0A || getDB_0() == 0x0E)) { - int position = getDB_3Value(); - float percentage = 100.0f * (Top - position) / (float) (Top - Bottom); + if (getDB2() == ZERO && getDB1() == MOVE && (getDB0() == 0x0A || getDB0() == 0x0E)) { + int position = getDB3Value(); + float percentage = 100.0f * (TOP - position) / (float) (TOP - BOTTOM); return new PercentType(Math.round(Math.min(100, (Math.max(0, percentage))))); } return UnDefType.UNDEF; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java index df9dc445057..3d6e55d0c73 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.ZERO; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelRollershutterConfig; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -31,14 +33,15 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_3F_7F_EltakoFSB extends _4BSMessage { - static final byte Stop = 0x00; - static final byte MoveUp = 0x01; - static final byte MoveDown = 0x02; + static final byte STOP = 0x00; + static final byte MOVE_UP = 0x01; + static final byte MOVE_DOWN = 0x02; - static final byte Up = 0x70; - static final byte Down = 0x50; + static final byte UP = 0x70; + static final byte DOWN = 0x50; public A5_3F_7F_EltakoFSB() { super(); @@ -50,9 +53,11 @@ public class A5_3F_7F_EltakoFSB extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { int shutTime = 0xFF; - if (config != null) { + if (config == null) { + logger.debug("No configuration, shutTime fallback to {}", shutTime); + } else { shutTime = Math.min(255, config.as(EnOceanChannelRollershutterConfig.class).shutTime); } @@ -61,60 +66,57 @@ public class A5_3F_7F_EltakoFSB extends _4BSMessage { PercentType target = (PercentType) command; if (target.intValue() == PercentType.ZERO.intValue()) { - setData(ZERO, (byte) shutTime, MoveUp, TeachInBit); // => move completely up + setData(ZERO, (byte) shutTime, MOVE_UP, TEACHIN_BIT); // => move completely up } else if (target.intValue() == PercentType.HUNDRED.intValue()) { - setData(ZERO, (byte) shutTime, MoveDown, TeachInBit); // => move completely down + setData(ZERO, (byte) shutTime, MOVE_DOWN, TEACHIN_BIT); // => move completely down } else if (channelState != null) { PercentType current = channelState.as(PercentType.class); - if (config != null && current != null) { + if (current != null) { if (current.intValue() != target.intValue()) { - byte direction = current.intValue() > target.intValue() ? MoveUp : MoveDown; + byte direction = current.intValue() > target.intValue() ? MOVE_UP : MOVE_DOWN; byte duration = (byte) Math.min(255, (Math.abs(current.intValue() - target.intValue()) * shutTime) / PercentType.HUNDRED.intValue()); - setData(ZERO, duration, direction, TeachInBit); + setData(ZERO, duration, direction, TEACHIN_BIT); } } } } else if (command instanceof UpDownType) { if ((UpDownType) command == UpDownType.UP) { - setData(ZERO, (byte) shutTime, MoveUp, TeachInBit); // => 0 percent + setData(ZERO, (byte) shutTime, MOVE_UP, TEACHIN_BIT); // => 0 percent } else if ((UpDownType) command == UpDownType.DOWN) { - setData(ZERO, (byte) shutTime, MoveDown, TeachInBit); // => 100 percent + setData(ZERO, (byte) shutTime, MOVE_DOWN, TEACHIN_BIT); // => 100 percent } } else if (command instanceof StopMoveType) { if ((StopMoveType) command == StopMoveType.STOP) { - setData(ZERO, (byte) 0xFF, Stop, TeachInBit); + setData(ZERO, (byte) 0xFF, STOP, TEACHIN_BIT); } } } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { State currentState = getCurrentStateFunc.apply(channelId); if (currentState != null) { - int duration = ((getDB_3Value() << 8) + getDB_2Value()) / 10; // => Time in DB3 and DB2 is given - // in ms + int duration = ((getDB3Value() << 8) + getDB2Value()) / 10; // => Time in DB3 and DB2 is given + // in ms + EnOceanChannelRollershutterConfig c = config.as(EnOceanChannelRollershutterConfig.class); + if (duration == c.shutTime) { + return getDB1() == MOVE_UP ? PercentType.ZERO : PercentType.HUNDRED; + } else { + PercentType current = PercentType.ZERO; + if (currentState instanceof PercentType) { + current = currentState.as(PercentType.class); + } - if (config != null) { - EnOceanChannelRollershutterConfig c = config.as(EnOceanChannelRollershutterConfig.class); - if (duration == c.shutTime) { - return getDB_1() == MoveUp ? PercentType.ZERO : PercentType.HUNDRED; - } else { - PercentType current = PercentType.ZERO; - if (currentState instanceof PercentType) { - current = currentState.as(PercentType.class); - } - - int direction = getDB_1() == MoveUp ? -1 : 1; - if (c.shutTime != -1 && c.shutTime != 0) { - return new PercentType(Math.min(100, (Math.max(0, current.intValue() - + direction * ((duration * PercentType.HUNDRED.intValue()) / c.shutTime))))); - } + int direction = getDB1() == MOVE_UP ? -1 : 1; + if (current != null && c.shutTime != -1 && c.shutTime != 0) { + return new PercentType(Math.min(100, (Math.max(0, current.intValue() + + direction * ((duration * PercentType.HUNDRED.intValue()) / c.shutTime))))); } } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_Universal.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_Universal.java index 5279c4db1b1..276edf02f6a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_Universal.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_Universal.java @@ -14,6 +14,8 @@ package org.openhab.binding.enocean.internal.eep.A5_3F; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -27,6 +29,7 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class A5_3F_7F_Universal extends _4BSMessage { // This class is currently not used => instead use Generic4BS @@ -41,21 +44,22 @@ public class A5_3F_7F_Universal extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { - if (config != null) { - try { - EnOceanChannelTransformationConfig transformationInfo = config - .as(EnOceanChannelTransformationConfig.class); - String c = Transformation.transform(transformationInfo.transformationType, - transformationInfo.transformationFunction, command.toString()); + Function getCurrentStateFunc, @Nullable Configuration config) { + if (config == null) { + logger.error("Command {} could not transformed without proper configuration", command.toString()); + return; + } + try { + EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class); + String c = Transformation.transform(transformationInfo.transformationType, + transformationInfo.transformationFunction, command.toString()); - if (c != null && !c.equals(command.toString())) { - setData(HexUtils.hexToBytes(c)); - } - - } catch (Exception e) { - logger.debug("Command {} could not transformed", command.toString()); + if (c != null && !c.equals(command.toString())) { + setData(HexUtils.hexToBytes(c)); } + } catch (IllegalArgumentException e) { + logger.debug("Command {} could not transformed", command.toString()); + throw e; } } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/PTM200Message.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/PTM200Message.java index 281a958192a..40a850a623f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/PTM200Message.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/PTM200Message.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -30,14 +32,15 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class PTM200Message extends _RPSMessage { - static final byte On = 0x70; - static final byte Off = 0x50; - static final byte Up = 0x70; - static final byte Down = 0x50; - static final byte Open = (byte) 0xE0; - static final byte Closed = (byte) 0xF0; + static final byte SWITCH_ON = 0x70; + static final byte SWITCH_OFF = 0x50; + static final byte UP = 0x70; + static final byte DOWN = 0x50; + static final byte OPEN = (byte) 0xE0; + static final byte CLOSED = (byte) 0xF0; public PTM200Message() { super(); @@ -49,26 +52,25 @@ public class PTM200Message extends _RPSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_GENERAL_SWITCHING: - return bytes[0] == On ? OnOffType.ON : OnOffType.OFF; + return bytes[0] == SWITCH_ON ? OnOffType.ON : OnOffType.OFF; case CHANNEL_ROLLERSHUTTER: - return bytes[0] == Up ? PercentType.ZERO : (bytes[0] == Down ? PercentType.HUNDRED : UnDefType.UNDEF); + return bytes[0] == UP ? PercentType.ZERO : (bytes[0] == DOWN ? PercentType.HUNDRED : UnDefType.UNDEF); case CHANNEL_CONTACT: EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class); if (c.inverted) { - return bytes[0] == Open ? OpenClosedType.CLOSED - : (bytes[0] == Closed ? OpenClosedType.OPEN : UnDefType.UNDEF); + return bytes[0] == OPEN ? OpenClosedType.CLOSED + : (bytes[0] == CLOSED ? OpenClosedType.OPEN : UnDefType.UNDEF); } else { - return bytes[0] == Open ? OpenClosedType.OPEN - : (bytes[0] == Closed ? OpenClosedType.CLOSED : UnDefType.UNDEF); + return bytes[0] == OPEN ? OpenClosedType.OPEN + : (bytes[0] == CLOSED ? OpenClosedType.CLOSED : UnDefType.UNDEF); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/UTEResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/UTEResponse.java index 1da53766f66..8097205b248 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/UTEResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/UTEResponse.java @@ -14,18 +14,20 @@ package org.openhab.binding.enocean.internal.eep.Base; import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class UTEResponse extends _VLDMessage { - public static final byte TeachIn_MASK = 0x3f; - public static final byte CommunicationType_MASK = (byte) 0x80; - public static final byte ResponseNeeded_MASK = 0x40; - public static final byte TeachIn_NotSpecified = 0x20; + public static final byte TEACHIN_MASK = 0x3f; + public static final byte COMMUNICATION_TYPE_MASK = (byte) 0x80; + public static final byte RESPONSE_NEEDED_MASK = 0x40; + public static final byte TEACHIN_NPTSPECIFIED = 0x20; public UTEResponse(ERP1Message packet, boolean teachIn) { int dataLength = packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_1BSMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_1BSMessage.java index 318fa27baf3..08cfec6ffc5 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_1BSMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_1BSMessage.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.Base; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -19,9 +20,10 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class _1BSMessage extends EEP { - public static final int TeachInBit = 0x08; + public static final int TEACHIN_BIT = 0x08; public _1BSMessage(ERP1Message packet) { super(packet); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSMessage.java index 1c5fd6889e5..df1faddcdde 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSMessage.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.enocean.internal.eep.Base; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelTeachInConfig; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.eep.EEPType; @@ -23,6 +25,7 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class _4BSMessage extends EEP { protected boolean supportsTeachInVariation3 = false; @@ -39,49 +42,49 @@ public abstract class _4BSMessage extends EEP { super(); } - public static final byte TeachInBit = 0x08; - public static final byte LRN_Type_Mask = (byte) 0x80; + public static final byte TEACHIN_BIT = 0x08; + public static final byte LRN_TYPE_MASK = (byte) 0x80; - public byte getDB_0() { + public byte getDB0() { return bytes[3]; } - public int getDB_0Value() { - return (getDB_0() & 0xFF); + public int getDB0Value() { + return (getDB0() & 0xFF); } - public byte getDB_1() { + public byte getDB1() { return bytes[2]; } - public int getDB_1Value() { - return (getDB_1() & 0xFF); + public int getDB1Value() { + return (getDB1() & 0xFF); } - public byte getDB_2() { + public byte getDB2() { return bytes[1]; } - public int getDB_2Value() { - return (getDB_2() & 0xFF); + public int getDB2Value() { + return (getDB2() & 0xFF); } - public byte getDB_3() { + public byte getDB3() { return bytes[0]; } - public int getDB_3Value() { - return (getDB_3() & 0xFF); + public int getDB3Value() { + return (getDB3() & 0xFF); } @Override - protected void teachInQueryImpl(Configuration config) { + protected void teachInQueryImpl(@Nullable Configuration config) { if (config == null) { return; } EnOceanChannelTeachInConfig c = config.as(EnOceanChannelTeachInConfig.class); - if (c.teachInMSG == null || c.teachInMSG.isEmpty()) { + if (c.teachInMSG.isEmpty()) { EEPType type = getEEPType(); byte db3 = (byte) ((getEEPType().getFunc() << 2) | ((type.getType()) >>> 5)); @@ -95,12 +98,14 @@ public abstract class _4BSMessage extends EEP { } catch (Exception e) { } - setData(db3, db2, db1, LRN_Type_Mask); + setData(db3, db2, db1, LRN_TYPE_MASK); } else { try { byte[] msg = HexUtils.hexToBytes(c.teachInMSG); setData(msg); - } catch (Exception e) { + } catch (IllegalArgumentException e) { + logger.debug("Command TeachIn could not transformed"); + throw e; } } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSTeachInVariation3Response.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSTeachInVariation3Response.java index 30bc10d4921..61b7762baae 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSTeachInVariation3Response.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_4BSTeachInVariation3Response.java @@ -14,6 +14,7 @@ package org.openhab.binding.enocean.internal.eep.Base; import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -21,6 +22,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; * * @author Dominik Vorreiter - Initial contribution */ +@NonNullByDefault public class _4BSTeachInVariation3Response extends _4BSMessage { public _4BSTeachInVariation3Response(ERP1Message packet, boolean teachIn) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_RPSMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_RPSMessage.java index 67c660a2c6a..f595fdda111 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_RPSMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_RPSMessage.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.enocean.internal.eep.Base; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -19,13 +20,14 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class _RPSMessage extends EEP { protected boolean t21; protected boolean nu; - public static final byte T21Flag = 0x20; - public static final byte NUFlag = 0x10; + public static final byte T21_FLAG = 0x20; + public static final byte NU_FLAG = 0x10; public _RPSMessage() { super(); @@ -46,8 +48,8 @@ public abstract class _RPSMessage extends EEP { @Override public EEP setStatus(byte status) { super.setStatus(status); - t21 = (status & T21Flag) != 0; - nu = (status & NUFlag) != 0; + t21 = (status & T21_FLAG) != 0; + nu = (status & NU_FLAG) != 0; return this; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_SIGMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_SIGMessage.java index 77c55c5a43f..2be0d4f53a9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_SIGMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_SIGMessage.java @@ -14,6 +14,7 @@ package org.openhab.binding.enocean.internal.eep.Base; import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -21,6 +22,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class _SIGMessage extends EEP { public static final byte MID_ENERGY_STATUS = 0x06; @@ -35,8 +37,9 @@ public abstract class _SIGMessage extends EEP { @Override protected int getDataLength() { - if (packet != null) { - return packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; + ERP1Message localPacket = packet; + if (localPacket != null) { + return localPacket.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; } else { return bytes.length; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_VLDMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_VLDMessage.java index 409f64e33bb..fcfa1bc6450 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_VLDMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Base/_VLDMessage.java @@ -14,6 +14,7 @@ package org.openhab.binding.enocean.internal.eep.Base; import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -21,6 +22,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class _VLDMessage extends EEP { public _VLDMessage() { @@ -33,11 +35,11 @@ public abstract class _VLDMessage extends EEP { @Override protected int getDataLength() { - if (packet != null) { - return packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; - } else { - return bytes.length; + ERP1Message localPacket = packet; + if (localPacket != null) { + return localPacket.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; } + return bytes.length; } @Override diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D0/D0_06.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D0/D0_06.java index 56925790902..fce24d07d6c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D0/D0_06.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D0/D0_06.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._SIGMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D0_06 extends _SIGMessage { public D0_06() { @@ -39,8 +42,8 @@ public class D0_06 extends _SIGMessage { } @Override - public State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, - Configuration config) { + public State convertToStateImpl(String channelId, String channelTypeId, + Function getCurrentStateFunc, Configuration config) { if (CHANNEL_BATTERY_LEVEL.equals(channelId)) { return new QuantityType<>(bytes[1] & 0xFF, Units.PERCENT); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java index 8f5d502514b..074ba0af22b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelDimmerConfig; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.eep.EEPHelper; @@ -37,25 +39,26 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class D2_01 extends _VLDMessage { - protected final byte cmdMask = 0x0f; - protected final byte outputValueMask = 0x7f; - protected final byte outputChannelMask = 0x1f; + protected static final byte CMD_MASK = 0x0f; + protected static final byte OUTPUT_VALUE_MASK = 0x7f; + protected static final byte OUTPUT_CHANNEL_MASK = 0x1f; - protected final byte CMD_ACTUATOR_SET_STATUS = 0x01; - protected final byte CMD_ACTUATOR_STATUS_QUERY = 0x03; - protected final byte CMD_ACTUATOR_STATUS_RESPONE = 0x04; - protected final byte CMD_ACTUATOR_MEASUREMENT_QUERY = 0x06; - protected final byte CMD_ACTUATOR_MEASUREMENT_RESPONE = 0x07; + protected static final byte CMD_ACTUATOR_SET_STATUS = 0x01; + protected static final byte CMD_ACTUATOR_STATUS_QUERY = 0x03; + protected static final byte CMD_ACTUATOR_STATUS_RESPONE = 0x04; + protected static final byte CMD_ACTUATOR_MEASUREMENT_QUERY = 0x06; + protected static final byte CMD_ACTUATOR_MEASUREMENT_RESPONE = 0x07; - protected final byte AllChannels_Mask = 0x1e; - protected final byte ChannelA_Mask = 0x00; - protected final byte ChannelB_Mask = 0x01; + protected static final byte ALL_CHANNELS_MASK = 0x1e; + protected static final byte CHANNEL_A_MASK = 0x00; + protected static final byte CHANNEL_B_MASK = 0x01; - protected final byte STATUS_SWITCHING_ON = 0x01; - protected final byte STATUS_SWITCHING_OFF = 0x00; - protected final byte STATUS_DIMMING_100 = 0x64; + protected static final byte STATUS_SWITCHING_ON = 0x01; + protected static final byte STATUS_SWITCHING_OFF = 0x00; + protected static final byte STATUS_DIMMING_100 = 0x64; public D2_01() { super(); @@ -66,7 +69,7 @@ public abstract class D2_01 extends _VLDMessage { } protected byte getCMD() { - return (byte) (bytes[0] & cmdMask); + return (byte) (bytes[0] & CMD_MASK); } protected void setSwitchingData(OnOffType command, byte outputChannel) { @@ -83,19 +86,19 @@ public abstract class D2_01 extends _VLDMessage { protected State getSwitchingData() { if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE) { - return (bytes[bytes.length - 1] & outputValueMask) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON; + return (bytes[bytes.length - 1] & OUTPUT_VALUE_MASK) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON; } return UnDefType.UNDEF; } protected byte getChannel() { - return (byte) (bytes[1] & outputChannelMask); + return (byte) (bytes[1] & OUTPUT_CHANNEL_MASK); } protected State getSwitchingData(byte channel) { - if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE && (getChannel() == channel || getChannel() == AllChannels_Mask)) { - return (bytes[bytes.length - 1] & outputValueMask) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON; + if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE && (getChannel() == channel || getChannel() == ALL_CHANNELS_MASK)) { + return (bytes[bytes.length - 1] & OUTPUT_VALUE_MASK) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON; } return UnDefType.UNDEF; @@ -124,7 +127,7 @@ public abstract class D2_01 extends _VLDMessage { protected State getDimmingData() { if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE) { - return new PercentType((bytes[bytes.length - 1] & outputValueMask)); + return new PercentType((bytes[bytes.length - 1] & OUTPUT_VALUE_MASK)); } return UnDefType.UNDEF; @@ -197,48 +200,52 @@ public abstract class D2_01 extends _VLDMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (channelId.equals(CHANNEL_GENERAL_SWITCHING)) { if (command == RefreshType.REFRESH) { - setSwitchingQueryData(AllChannels_Mask); + setSwitchingQueryData(ALL_CHANNELS_MASK); } else { - setSwitchingData((OnOffType) command, AllChannels_Mask); + setSwitchingData((OnOffType) command, ALL_CHANNELS_MASK); } } else if (channelId.equals(CHANNEL_GENERAL_SWITCHINGA)) { if (command == RefreshType.REFRESH) { - setSwitchingQueryData(ChannelA_Mask); + setSwitchingQueryData(CHANNEL_A_MASK); } else { - setSwitchingData((OnOffType) command, ChannelA_Mask); + setSwitchingData((OnOffType) command, CHANNEL_A_MASK); } } else if (channelId.equals(CHANNEL_GENERAL_SWITCHINGB)) { if (command == RefreshType.REFRESH) { - setSwitchingQueryData(ChannelB_Mask); + setSwitchingQueryData(CHANNEL_B_MASK); } else { - setSwitchingData((OnOffType) command, ChannelB_Mask); + setSwitchingData((OnOffType) command, CHANNEL_B_MASK); } } else if (channelId.equals(CHANNEL_DIMMER)) { if (command == RefreshType.REFRESH) { - setSwitchingQueryData(AllChannels_Mask); + setSwitchingQueryData(ALL_CHANNELS_MASK); } else { - setDimmingData(command, AllChannels_Mask, config); + if (config != null) { + setDimmingData(command, ALL_CHANNELS_MASK, config); + } else { + logger.error("Cannot set dimming data when config is null"); + } } } else if (channelId.equals(CHANNEL_INSTANTPOWER) && command == RefreshType.REFRESH) { - setPowerMeasurementQueryData(AllChannels_Mask); + setPowerMeasurementQueryData(ALL_CHANNELS_MASK); } else if (channelId.equals(CHANNEL_TOTALUSAGE) && command == RefreshType.REFRESH) { - setEnergyMeasurementQueryData(AllChannels_Mask); + setEnergyMeasurementQueryData(ALL_CHANNELS_MASK); } } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_GENERAL_SWITCHING: return getSwitchingData(); case CHANNEL_GENERAL_SWITCHINGA: - return getSwitchingData(ChannelA_Mask); + return getSwitchingData(CHANNEL_A_MASK); case CHANNEL_GENERAL_SWITCHINGB: - return getSwitchingData(ChannelB_Mask); + return getSwitchingData(CHANNEL_B_MASK); case CHANNEL_DIMMER: return getDimmingData(); case CHANNEL_INSTANTPOWER: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_00.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_00.java index a6bdd27604e..34fdaa9b2c3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_00.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_00.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_00 extends D2_01 { public D2_01_00() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_01.java index f9f31429e3f..12d461e40ea 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_01.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_01 extends D2_01 { public D2_01_01() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_02.java index aca3594e4a4..3ba5d49a3d2 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_02.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_02 extends D2_01 { public D2_01_02() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_03.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_03.java index f5e06244775..57bbf38c441 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_03.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_03.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_03 extends D2_01 { public D2_01_03() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_04.java index 7fd1ec2368e..5be7d7741f5 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_04.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_04 extends D2_01 { public D2_01_04() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_05.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_05.java index 016db7b6e99..7168dc34155 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_05.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_05.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_05 extends D2_01 { public D2_01_05() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_06.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_06.java index d26e3c0d302..2f74387c187 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_06.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_06.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_06 extends D2_01 { public D2_01_06() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_07.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_07.java index 14e771f7813..d4c852f8b7a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_07.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_07.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_07 extends D2_01 { public D2_01_07() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_08.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_08.java index 99e3bb0ab1a..77da8981205 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_08.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_08.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_08 extends D2_01 { public D2_01_08() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09.java index e585829c0c7..0bad2c87c40 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_09 extends D2_01 { public D2_01_09() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java index 128be45716d..75bbde8fd48 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanBindingConstants; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -30,6 +32,7 @@ import org.openhab.core.types.State; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_09_Permundo extends D2_01 { public D2_01_09_Permundo() { @@ -42,7 +45,7 @@ public class D2_01_09_Permundo extends D2_01 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (channelId.equals(CHANNEL_REPEATERMODE)) { setRepeaterMode(command); } else if (channelId.equals(CHANNEL_ECOMODE)) { @@ -54,7 +57,7 @@ public class D2_01_09_Permundo extends D2_01 { private void setRepeaterMode(Command command) { if (command == RefreshType.REFRESH) { - senderId = null; // make this message invalid as we do not support refresh of repeater status + senderId = new byte[0]; // make this message invalid as we do not support refresh of repeater status } else if (command instanceof StringType) { switch (((StringType) command).toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: @@ -71,7 +74,7 @@ public class D2_01_09_Permundo extends D2_01 { private void setEcoMode(Command command) { if (command == RefreshType.REFRESH) { - senderId = null; // make this message invalid as we do not support refresh of ecomode status + senderId = new byte[0]; // make this message invalid as we do not support refresh of ecomode status } else if (command instanceof OnOffType) { if (((OnOffType) command) == OnOffType.ON) { setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x36, (byte) 0x01); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0A.java index a42ea2afdf0..5688b506c99 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0A.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0A extends D2_01 { public D2_01_0A() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0B.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0B.java index fec6d92f0e1..56bbff40e8c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0B.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0B.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0B extends D2_01 { public D2_01_0B() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0C.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0C.java index f36c194fab3..cbbfa4ce46a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0C.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0C.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0C extends D2_01 { public D2_01_0C() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0D.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0D.java index 6d166e08605..dd78d7412dd 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0D.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0D.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0D extends D2_01 { public D2_01_0D() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0E.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0E.java index dc40b5e8d78..5b61a3f231a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0E.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0E.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0E extends D2_01 { public D2_01_0E() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F.java index e94e4e13fd7..7f44f496dc6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0F extends D2_01 { public D2_01_0F() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java index 4aa35a81efe..dcea0e6f25e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanBindingConstants; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -29,6 +31,7 @@ import org.openhab.core.types.State; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_0F_NodON extends D2_01 { public D2_01_0F_NodON() { @@ -41,10 +44,10 @@ public class D2_01_0F_NodON extends D2_01 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (channelId.equalsIgnoreCase(CHANNEL_REPEATERMODE)) { if (command instanceof RefreshType) { - senderId = null; // make this message invalid as we do not support refresh of repeter status + senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status } else if (command instanceof StringType) { switch (((StringType) command).toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_11.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_11.java index bbee729797f..5d51947429a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_11.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_11.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_11 extends D2_01 { public D2_01_11() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12.java index baaee3572fe..826d5c6de03 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.eep.D2_01; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_12 extends D2_01 { public D2_01_12() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java index cd1c568d29a..28af568f22d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanBindingConstants; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -29,6 +31,7 @@ import org.openhab.core.types.State; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_01_12_NodON extends D2_01 { public D2_01_12_NodON() { @@ -41,10 +44,10 @@ public class D2_01_12_NodON extends D2_01 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (channelId.equalsIgnoreCase(CHANNEL_REPEATERMODE)) { if (command instanceof RefreshType) { - senderId = null; // make this message invalid as we do not support refresh of repeter status + senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status } else if (command instanceof StringType) { switch (((StringType) command).toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java index 08dc10e0c5c..824a5408f29 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -29,12 +31,13 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_03_0A extends _VLDMessage { - protected final byte ShortPress = 0x01; - protected final byte DoublePress = 0x02; - protected final byte LongPress = 0x03; - protected final byte LongRelease = 0x04; + protected static final byte SHORT_PRESS = 0x01; + protected static final byte DOUBLE_PRESS = 0x02; + protected static final byte LONG_PRESS = 0x03; + protected static final byte LONG_RELEASE = 0x04; public D2_03_0A() { super(); @@ -45,24 +48,24 @@ public class D2_03_0A extends _VLDMessage { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { switch (channelId) { case CHANNEL_PUSHBUTTON: - return (bytes[1] == ShortPress) ? CommonTriggerEvents.PRESSED : null; + return (bytes[1] == SHORT_PRESS) ? CommonTriggerEvents.PRESSED : null; case CHANNEL_DOUBLEPRESS: - return (bytes[1] == DoublePress) ? CommonTriggerEvents.PRESSED : null; + return (bytes[1] == DOUBLE_PRESS) ? CommonTriggerEvents.PRESSED : null; case CHANNEL_LONGPRESS: - return (bytes[1] == LongPress) ? CommonTriggerEvents.PRESSED - : ((bytes[1] == LongRelease) ? CommonTriggerEvents.RELEASED : null); + return (bytes[1] == LONG_PRESS) ? CommonTriggerEvents.PRESSED + : ((bytes[1] == LONG_RELEASE) ? CommonTriggerEvents.RELEASED : null); default: return null; } } @Override - public State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, - Configuration config) { + public State convertToStateImpl(String channelId, String channelTypeId, + Function getCurrentStateFunc, Configuration config) { if (CHANNEL_BATTERY_LEVEL.equals(channelId)) { return new QuantityType<>(bytes[0] & 0xFF, Units.PERCENT); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java index 972b9e02b9a..eeab198a8fb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -32,22 +34,23 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_05_00 extends _VLDMessage { - protected final byte cmdMask = 0x0f; - protected final byte outputValueMask = 0x7f; - protected final byte outputChannelMask = 0x1f; + protected static final byte CMD_MASK = 0x0f; + protected static final byte OUTPUT_VALUE_MASK = 0x7f; + protected static final byte OUTPUT_CHANNEL_MASK = 0x1f; - protected final byte CMD_ACTUATOR_SET_POSITION = 0x01; - protected final byte CMD_ACTUATOR_STOP = 0x02; - protected final byte CMD_ACTUATOR_POSITION_QUERY = 0x03; - protected final byte CMD_ACTUATOR_POSITION_RESPONE = 0x04; + protected static final byte CMD_ACTUATOR_SET_POSITION = 0x01; + protected static final byte CMD_ACTUATOR_STOP = 0x02; + protected static final byte CMD_ACTUATOR_POSITION_QUERY = 0x03; + protected static final byte CMD_ACTUATOR_POSITION_RESPONE = 0x04; - protected final byte AllChannels_Mask = 0x1e; - protected final byte ChannelA_Mask = 0x00; + protected static final byte ALL_CHANNELS_MASK = 0x1e; + protected static final byte CHANNEL_A_MASK = 0x00; - protected final byte DOWN = 0x64; // 100% - protected final byte UP = 0x00; // 0% + protected static final byte DOWN = 0x64; // 100% + protected static final byte UP = 0x00; // 0% public D2_05_00() { super(); @@ -58,7 +61,7 @@ public class D2_05_00 extends _VLDMessage { } protected byte getCMD() { - return (byte) (bytes[bytes.length - 1] & cmdMask); + return (byte) (bytes[bytes.length - 1] & CMD_MASK); } protected void setPositionData(Command command, byte outputChannel) { @@ -94,7 +97,7 @@ public class D2_05_00 extends _VLDMessage { } protected byte getChannel() { - return (byte) (bytes[1] & outputChannelMask); + return (byte) (bytes[1] & OUTPUT_CHANNEL_MASK); } @Override @@ -105,19 +108,19 @@ public class D2_05_00 extends _VLDMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (channelId.equals(CHANNEL_ROLLERSHUTTER)) { if (command == RefreshType.REFRESH) { - setPositionQueryData(ChannelA_Mask); + setPositionQueryData(CHANNEL_A_MASK); } else { - setPositionData(command, ChannelA_Mask); + setPositionData(command, CHANNEL_A_MASK); } } } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_ROLLERSHUTTER: return getPositionData(); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java index 9d4308a6c52..a74dcba4eeb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanBindingConstants; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -26,10 +28,11 @@ import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; /** - * + * @author MArcel Eckert - Initial contribution * @author Marcel Eckert - based on D2_01_0F_NodON.java and D2_01_12_NodOn.java * */ +@NonNullByDefault public class D2_05_00_NodON extends D2_05_00 { public D2_05_00_NodON() { @@ -42,10 +45,10 @@ public class D2_05_00_NodON extends D2_05_00 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (channelId.equals(CHANNEL_REPEATERMODE)) { if (command == RefreshType.REFRESH) { - senderId = null; // make this message invalid as we do not support refresh of repeter status + senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status } else if (command instanceof StringType) { switch (((StringType) command).toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java index ab96d95f8fb..8668c0ba6d8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java @@ -18,6 +18,8 @@ import java.util.Arrays; import java.util.Optional; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -39,10 +41,10 @@ import org.openhab.core.types.UnDefType; * * @author Thomas Lauterbach - Initial contribution */ +@NonNullByDefault public class D2_06_01 extends _VLDMessage { private enum MessageType { - SENSORVALUES(0x00), CONFIGURATIONREPORT(0x10), LOGDATA01(0x20), @@ -63,7 +65,6 @@ public class D2_06_01 extends _VLDMessage { } private enum SashState { - // WINDOWSTATEUNDEFINED(0x00, "UNDEFINED"), NOTTILTED(0x01, "NOT TILTED"), TILTED(0x02, "TILTED"); @@ -86,7 +87,6 @@ public class D2_06_01 extends _VLDMessage { } private enum HandleState { - // HANDLEPOSITIONUNDEFINED(0x00, "UNDEFINED"), HANDLEUP(0x01, "UP"), HANDLEDOWN(0x02, "DOWN"), @@ -111,7 +111,6 @@ public class D2_06_01 extends _VLDMessage { } private enum MotionState { - MOTIONNOTTRIGGERED(0x00, "OFF"), MOTIONTRIGGERED(0x01, "ON"); @@ -199,9 +198,8 @@ public class D2_06_01 extends _VLDMessage { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { - // Sensor values if (bytes[0] == MessageType.SENSORVALUES.getIntValue()) { switch (channelId) { @@ -248,9 +246,8 @@ public class D2_06_01 extends _VLDMessage { } @Override - public State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, - Configuration config) { - + public State convertToStateImpl(String channelId, String channelTypeId, + Function getCurrentStateFunc, Configuration config) { // Sensor values if (bytes[0] == MessageType.SENSORVALUES.getIntValue()) { switch (channelId) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java index 0cfc44f231b..63ad5c71e00 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -29,6 +31,7 @@ import org.openhab.core.types.UnDefType; * * @author Thomas Lauterbach - Initial contribution */ +@NonNullByDefault public class D2_06_50 extends _VLDMessage { public D2_06_50() { @@ -112,9 +115,8 @@ public class D2_06_50 extends _VLDMessage { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { - // Alarm if (bytes[0] == 0x02) { switch (channelId) { @@ -130,7 +132,6 @@ public class D2_06_50 extends _VLDMessage { @Override public State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, Configuration config) { - // Window status if (bytes[0] == 0x01) { switch (channelId) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_14/D2_14_30.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_14/D2_14_30.java index 7230f23f2c2..2674a27a372 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_14/D2_14_30.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_14/D2_14_30.java @@ -16,6 +16,7 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -32,6 +33,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_14_30 extends _VLDMessage { private final String[] hygroComfortIndexValues = { "GOOD", "MEDIUM", "BAD", "ERROR" }; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java index fedbfe35fdc..eb211b2f4eb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.Helper; import org.openhab.binding.enocean.internal.eep.Base._VLDMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -37,16 +39,17 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D2_50 extends _VLDMessage { - protected static final byte mtMask = (byte) 0xf0; + protected static final byte MT_MASK = (byte) 0xf0; protected static final byte MT_REMOTE_TRANSMISSION_REQUEST = 0x00; protected static final byte MT_CONTROL = 0x20; protected static final byte MT_BASIC_STATUS = 0x40; protected static final byte MT_EXTENDED_STATUS = 0x60; // not yet implemented protected static final byte MT_UNKNOWN_STATUS = (byte) 0x80; // Sent by some systems during teach in - protected static final byte rmtMask = (byte) 0x0f; + protected static final byte RMT_MASK = (byte) 0x0f; protected static final byte RMT_BASIC_STATUS = 0x00; protected static final byte RMT_EXTENDED_STATUS = 0x01; // not yet implemented @@ -65,7 +68,7 @@ public class D2_50 extends _VLDMessage { } protected byte getMessageType(byte b) { - return (byte) (b & mtMask); + return (byte) (b & MT_MASK); } @Override @@ -76,8 +79,7 @@ public class D2_50 extends _VLDMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, @Nullable Configuration config) { // we need to send just a single message to refresh all channel states, hence just send refresh for OM if (command == RefreshType.REFRESH && CHANNEL_VENTILATIONOPERATIONMODE.equals(channelId)) { setData((byte) (MT_REMOTE_TRANSMISSION_REQUEST + RMT_BASIC_STATUS)); @@ -104,7 +106,6 @@ public class D2_50 extends _VLDMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, Function getCurrentStateFunc, Configuration config) { - if (getMessageType(bytes[0]) != MT_BASIC_STATUS) { return UnDefType.UNDEF; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D5_00/D5_00_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D5_00/D5_00_01.java index 34606816f45..46acf9928bb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D5_00/D5_00_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D5_00/D5_00_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.eep.Base._1BSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -28,10 +30,11 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class D5_00_01 extends _1BSMessage { - final byte OPEN = 0 | TeachInBit; - final byte CLOSED = 1 | TeachInBit; + protected static final byte OPEN = 0 | TEACHIN_BIT; + protected static final byte CLOSED = 1 | TEACHIN_BIT; public D5_00_01() { super(); @@ -43,7 +46,7 @@ public class D5_00_01 extends _1BSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_CONTACT)) { EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class); if (c.inverted) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java index 50bc81f5ae6..353f75670d5 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java @@ -18,6 +18,8 @@ import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; import java.util.Arrays; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.Helper; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -37,29 +39,26 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class EEP { protected RORG newRORG = RORG.Unknown; - protected byte[] bytes; - protected byte[] optionalData; - protected byte[] senderId; - protected byte status; + protected byte[] bytes = new byte[0]; + protected byte[] optionalData = new byte[0]; + protected byte[] senderId = new byte[0]; + protected byte status = 0x00; - protected byte[] destinationId; + protected byte[] destinationId = new byte[0]; protected boolean suppressRepeating; protected Logger logger = LoggerFactory.getLogger(EEP.class); - private EEPType eepType = null; - protected ERP1Message packet = null; + private @Nullable EEPType eepType = null; + protected @Nullable ERP1Message packet = null; public EEP() { // ctor for sending - - status = 0x00; - senderId = null; - bytes = null; } public EEP(ERP1Message packet) { @@ -74,7 +73,7 @@ public abstract class EEP { } public EEP convertFromCommand(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (!getEEPType().isChannelSupported(channelId, channelTypeId)) { throw new IllegalArgumentException(String.format("Command %s of channel %s(%s) is not supported", command.toString(), channelId, channelTypeId)); @@ -89,7 +88,7 @@ public abstract class EEP { } public State convertToState(String channelId, String channelTypeId, Configuration config, - Function getCurrentStateFunc) { + Function getCurrentStateFunc) { if (!getEEPType().isChannelSupported(channelId, channelTypeId)) { throw new IllegalArgumentException( String.format("Channel %s(%s) is not supported", channelId, channelTypeId)); @@ -97,13 +96,13 @@ public abstract class EEP { switch (channelTypeId) { case CHANNEL_RSSI: - if (this.optionalData == null || this.optionalData.length < 6) { + if (this.optionalData.length < 6) { return UnDefType.UNDEF; } return new DecimalType((this.optionalData[5] & 0xFF) * -1); case CHANNEL_REPEATCOUNT: - if (this.optionalData == null || this.optionalData.length < 6) { + if (this.optionalData.length < 6) { return UnDefType.UNDEF; } @@ -115,7 +114,8 @@ public abstract class EEP { return convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config); } - public String convertToEvent(String channelId, String channelTypeId, String lastEvent, Configuration config) { + public @Nullable String convertToEvent(String channelId, String channelTypeId, String lastEvent, + Configuration config) { if (!getEEPType().isChannelSupported(channelId, channelTypeId)) { throw new IllegalArgumentException( String.format("Channel %s(%s) is not supported", channelId, channelTypeId)); @@ -129,7 +129,7 @@ public abstract class EEP { return this; } - public EEP setData(byte... bytes) { + public EEP setData(byte... bytes) throws IllegalArgumentException { if (!validateData(bytes)) { throw new IllegalArgumentException(); } @@ -139,11 +139,11 @@ public abstract class EEP { } public boolean hasData() { - return (this.bytes != null) && (this.bytes.length > 0); + return (this.bytes.length > 0); } public EEP setOptionalData(byte... bytes) { - if (bytes != null) { + if (bytes.length > 0) { this.optionalData = Arrays.copyOf(bytes, bytes.length); } @@ -151,7 +151,7 @@ public abstract class EEP { } public EEP setSenderId(byte[] senderId) { - if (senderId == null || senderId.length != ESP3_SENDERID_LENGTH) { + if (senderId.length != ESP3_SENDERID_LENGTH) { throw new IllegalArgumentException(); } @@ -169,15 +169,10 @@ public abstract class EEP { return this; } - public final ERP1Message getERP1Message() { + public final @Nullable ERP1Message getERP1Message() { if (isValid()) { - int optionalDataLength = 0; - if (optionalData != null) { - optionalDataLength = optionalData.length; - } - byte[] payLoad = new byte[ESP3_RORG_LENGTH + getDataLength() + ESP3_SENDERID_LENGTH + ESP3_STATUS_LENGTH - + optionalDataLength]; + + optionalData.length]; Arrays.fill(payLoad, ZERO); byte rorgValue = getEEPType().getRORG().getValue(); @@ -189,7 +184,7 @@ public abstract class EEP { payLoad = Helper.concatAll(new byte[] { rorgValue }, bytes, senderId, new byte[] { (byte) (status | (suppressRepeating ? 0b1111 : 0)) }, optionalData); - return new ERP1Message(payLoad.length - optionalDataLength, optionalDataLength, payLoad); + return new ERP1Message(payLoad.length - optionalData.length, optionalData.length, payLoad); } else { logger.warn("ERP1Message for EEP {} is not valid!", this.getClass().getName()); } @@ -198,45 +193,42 @@ public abstract class EEP { } protected boolean validateData(byte[] bytes) { - return bytes != null && bytes.length == getDataLength(); + return bytes.length == getDataLength(); } public boolean isValid() { - return validateData(bytes) && senderId != null && senderId.length == ESP3_SENDERID_LENGTH; + return validateData(bytes) && senderId.length == ESP3_SENDERID_LENGTH; } protected EEPType getEEPType() { - if (eepType == null) { - eepType = EEPType.getType(this.getClass()); + EEPType localType = eepType; + if (localType == null) { + localType = EEPType.getType(this.getClass()); } - return eepType; + return localType; } protected int getDataLength() { - if (getEEPType() != null) { - return getEEPType().getRORG().getDataLength(); - } - - return 0; + return getEEPType().getRORG().getDataLength(); } protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { logger.warn("No implementation for sending data from channel {}/{} for this EEP!", channelId, channelTypeId); } protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { return UnDefType.UNDEF; } - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { return null; } - protected void teachInQueryImpl(Configuration config) { + protected void teachInQueryImpl(@Nullable Configuration config) { logger.warn("No implementation for sending a response for this teach in!"); } @@ -245,7 +237,7 @@ public abstract class EEP { return (byteData & mask) != 0; } - public ThingTypeUID getThingTypeUID() { + public @Nullable ThingTypeUID getThingTypeUID() { return getEEPType().getThingTypeUID(); } @@ -258,7 +250,7 @@ public abstract class EEP { } public EEP setDestinationId(byte[] destinationId) { - if (destinationId != null) { + if (destinationId.length > 0) { this.destinationId = Arrays.copyOf(destinationId, destinationId.length); setOptionalData(Helper.concatAll(new byte[] { 0x01 }, destinationId, new byte[] { (byte) 0xff, 0x00 })); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java index 276f609d584..59d9b95407d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java @@ -17,6 +17,8 @@ import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base.UTEResponse; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; import org.openhab.binding.enocean.internal.eep.Base._4BSTeachInVariation3Response; @@ -32,7 +34,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; import org.openhab.binding.enocean.internal.messages.EventMessage; import org.openhab.binding.enocean.internal.messages.EventMessage.EventMessageType; -import org.openhab.binding.enocean.internal.messages.Responses.SMACKTeachInResponse; +import org.openhab.binding.enocean.internal.messages.responses.SMACKTeachInResponse; import org.openhab.core.util.HexUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +43,7 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EEPFactory { private static final Logger logger = LoggerFactory.getLogger(EEPFactory.class); @@ -76,7 +79,7 @@ public class EEPFactory { } } - private static EEPType getGenericEEPTypeFor(byte rorg) { + private static @Nullable EEPType getGenericEEPTypeFor(byte rorg) { logger.info("Received unsupported EEP teach in, trying to fallback to generic thing"); RORG r = RORG.getRORG(rorg); if (r == RORG._4BS) { @@ -91,7 +94,7 @@ public class EEPFactory { } } - public static EEP buildEEPFromTeachInERP1(ERP1Message msg) { + public static @Nullable EEP buildEEPFromTeachInERP1(ERP1Message msg) { if (!msg.getIsTeachIn() && !(msg.getRORG() == RORG.RPS)) { return null; } @@ -150,19 +153,19 @@ public class EEPFactory { case _1BS: return new D5_00_01(msg); case _4BS: { - int db_0 = msg.getPayload()[4]; - if ((db_0 & _4BSMessage.LRN_Type_Mask) == 0) { // Variation 1 + int db0 = msg.getPayload()[4]; + if ((db0 & _4BSMessage.LRN_TYPE_MASK) == 0) { // Variation 1 logger.info("Received 4BS Teach In variation 1 without EEP, fallback to generic thing"); return buildEEP(EEPType.Generic4BS, msg); } - byte db_3 = msg.getPayload()[1]; - byte db_2 = msg.getPayload()[2]; - byte db_1 = msg.getPayload()[3]; + byte db3 = msg.getPayload()[1]; + byte db2 = msg.getPayload()[2]; + byte db1 = msg.getPayload()[3]; - int func = (db_3 & 0xFF) >>> 2; - int type = ((db_3 & 0b11) << 5) + ((db_2 & 0xFF) >>> 3); - int manufId = ((db_2 & 0b111) << 8) + (db_1 & 0xff); + int func = (db3 & 0xFF) >>> 2; + int type = ((db3 & 0b11) << 5) + ((db2 & 0xFF) >>> 3); + int manufId = ((db2 & 0b111) << 8) + (db1 & 0xff); logger.debug("Received 4BS Teach In with EEP A5-{}-{} and manufacturerID {}", HexUtils.bytesToHex(new byte[] { (byte) func }), @@ -210,7 +213,7 @@ public class EEPFactory { return null; } - public static EEP buildEEPFromTeachInSMACKEvent(EventMessage event) { + public static @Nullable EEP buildEEPFromTeachInSMACKEvent(EventMessage event) { if (event.getEventMessageType() != EventMessageType.SA_CONFIRM_LEARN) { return null; } @@ -235,10 +238,10 @@ public class EEPFactory { eepType = getGenericEEPTypeFor(rorg); } - return createEEP(eepType).setSenderId(senderId); + return (eepType == null) ? null : createEEP(eepType).setSenderId(senderId); } - public static EEP buildResponseEEPFromTeachInERP1(ERP1Message msg, byte[] senderId, boolean teachIn) { + public static @Nullable EEP buildResponseEEPFromTeachInERP1(ERP1Message msg, byte[] senderId, boolean teachIn) { switch (msg.getRORG()) { case UTE: EEP result = new UTEResponse(msg, teachIn); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPHelper.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPHelper.java index 9aade0851b0..bce376790f0 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPHelper.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPHelper.java @@ -14,6 +14,8 @@ package org.openhab.binding.enocean.internal.eep; import javax.measure.quantity.Energy; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelTotalusageConfig; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.QuantityType; @@ -26,8 +28,9 @@ import org.openhab.core.types.UnDefType; * @author Dominik Vorreiter - initial contribution * */ +@NonNullByDefault public abstract class EEPHelper { - public static State validateTotalUsage(State value, State currentState, Configuration config) { + public static State validateTotalUsage(State value, @Nullable State currentState, Configuration config) { EnOceanChannelTotalusageConfig c = config.as(EnOceanChannelTotalusageConfig.class); if (c.validateValue && (value instanceof QuantityType) && (currentState instanceof QuantityType)) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPType.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPType.java index 259b68c7fb7..e9c25063924 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPType.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPType.java @@ -18,7 +18,8 @@ import java.util.Collections; import java.util.Hashtable; import java.util.Map; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanChannelDescription; import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig; import org.openhab.binding.enocean.internal.eep.A5_02.A5_02_01; @@ -150,9 +151,9 @@ import org.openhab.binding.enocean.internal.eep.F6_05.F6_05_02; import org.openhab.binding.enocean.internal.eep.F6_10.F6_10_00; import org.openhab.binding.enocean.internal.eep.F6_10.F6_10_00_EltakoFPE; import org.openhab.binding.enocean.internal.eep.F6_10.F6_10_01; -import org.openhab.binding.enocean.internal.eep.Generic.Generic4BS; -import org.openhab.binding.enocean.internal.eep.Generic.GenericRPS; -import org.openhab.binding.enocean.internal.eep.Generic.GenericVLD; +import org.openhab.binding.enocean.internal.eep.generic.Generic4BS; +import org.openhab.binding.enocean.internal.eep.generic.GenericRPS; +import org.openhab.binding.enocean.internal.eep.generic.GenericVLD; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; import org.openhab.core.config.core.Configuration; import org.openhab.core.thing.Channel; @@ -163,8 +164,9 @@ import org.openhab.core.thing.type.ChannelTypeUID; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public enum EEPType { - Undef(RORG.Unknown, 0, 0, false, null, null, 0), + Undef(RORG.Unknown, 0, 0, false, EEP.class, null, 0), UTEResponse(RORG.UTE, 0, 0, false, UTEResponse.class, null), _4BSTeachInVariation3Response(RORG._4BS, 0, 0, false, _4BSTeachInVariation3Response.class, null), @@ -402,7 +404,7 @@ public enum EEPType { put(CHANNEL_ROLLERSHUTTER, new Configuration()); put(CHANNEL_TEACHINCMD, new Configuration() { { - put(PARAMETER_CHANNEL_TeachInMSG, "fff80d80"); + put(PARAMETER_CHANNEL_TEACHINMSG, "fff80d80"); } }); } @@ -415,7 +417,7 @@ public enum EEPType { put(CHANNEL_ROLLERSHUTTER, new Configuration()); put(CHANNEL_TEACHINCMD, new Configuration() { { - put(PARAMETER_CHANNEL_TeachInMSG, "fff80d80"); + put(PARAMETER_CHANNEL_TEACHINMSG, "fff80d80"); } }); } @@ -529,7 +531,7 @@ public enum EEPType { private String manufactorSuffix; private int manufactorId; - private ThingTypeUID thingTypeUID; + private @Nullable ThingTypeUID thingTypeUID; private Hashtable channelIdsWithConfig = new Hashtable<>(); private Hashtable supportedChannels = new Hashtable<>(); @@ -539,7 +541,7 @@ public enum EEPType { private boolean requestsResponse; EEPType(RORG rorg, int func, int type, boolean supportsRefresh, Class eepClass, - ThingTypeUID thingTypeUID, String... channelIds) { + @Nullable ThingTypeUID thingTypeUID, String... channelIds) { this(rorg, func, type, supportsRefresh, eepClass, thingTypeUID, -1, channelIds); } @@ -555,7 +557,7 @@ public enum EEPType { } EEPType(RORG rorg, int func, int type, boolean supportsRefresh, Class eepClass, - ThingTypeUID thingTypeUID, int command, String... channelIds) { + @Nullable ThingTypeUID thingTypeUID, int command, String... channelIds) { this(rorg, func, type, supportsRefresh, false, "", 0, eepClass, thingTypeUID, command, channelIds); } @@ -565,7 +567,8 @@ public enum EEPType { } EEPType(RORG rorg, int func, int type, boolean supportsRefresh, boolean requestsResponse, String manufactorSuffix, - int manufId, Class eepClass, ThingTypeUID thingTypeUID, int command, String... channelIds) { + int manufId, Class eepClass, @Nullable ThingTypeUID thingTypeUID, int command, + String... channelIds) { this.rorg = rorg; this.func = func; this.type = type; @@ -578,15 +581,20 @@ public enum EEPType { this.requestsResponse = requestsResponse; for (String id : channelIds) { - this.channelIdsWithConfig.put(id, new Configuration()); - this.supportedChannels.put(id, CHANNELID2CHANNELDESCRIPTION.get(id)); + if (id != null) { + this.channelIdsWithConfig.put(id, new Configuration()); + EnOceanChannelDescription description = CHANNELID2CHANNELDESCRIPTION.get(id); + if (description != null) { + this.supportedChannels.put(id, description); + } + } } addDefaultChannels(); } EEPType(RORG rorg, int func, int type, boolean supportsRefresh, boolean requestsResponse, String manufactorSuffix, - int manufId, Class eepClass, ThingTypeUID thingTypeUID, int command, + int manufId, Class eepClass, @Nullable ThingTypeUID thingTypeUID, int command, Hashtable channelConfigs) { this.rorg = rorg; this.func = func; @@ -601,59 +609,72 @@ public enum EEPType { this.requestsResponse = requestsResponse; for (String id : channelConfigs.keySet()) { - this.supportedChannels.put(id, CHANNELID2CHANNELDESCRIPTION.get(id)); + this.supportedChannels = addChannelDescription(supportedChannels, id, CHANNELID2CHANNELDESCRIPTION.get(id)); } addDefaultChannels(); } private void addDefaultChannels() { - if (THING_TYPE_GENERICTHING.equals(this.thingTypeUID)) { this.channelIdsWithConfig.put(CHANNEL_GENERIC_SWITCH, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_SWITCH, + + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_SWITCH, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_SWITCH)); this.channelIdsWithConfig.put(CHANNEL_GENERIC_ROLLERSHUTTER, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_ROLLERSHUTTER, + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_ROLLERSHUTTER, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_ROLLERSHUTTER)); this.channelIdsWithConfig.put(CHANNEL_GENERIC_DIMMER, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_DIMMER, + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_DIMMER, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_DIMMER)); this.channelIdsWithConfig.put(CHANNEL_GENERIC_NUMBER, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_NUMBER, + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_NUMBER, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_NUMBER)); this.channelIdsWithConfig.put(CHANNEL_GENERIC_STRING, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_STRING, + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_STRING, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_STRING)); this.channelIdsWithConfig.put(CHANNEL_GENERIC_COLOR, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_COLOR, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_COLOR)); + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_COLOR, + CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_COLOR)); this.channelIdsWithConfig.put(CHANNEL_GENERIC_TEACHINCMD, new EnOceanChannelTransformationConfig()); - this.supportedChannels.put(CHANNEL_GENERIC_TEACHINCMD, + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_TEACHINCMD, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_TEACHINCMD)); } this.channelIdsWithConfig.put(CHANNEL_RSSI, new Configuration()); - this.supportedChannels.put(CHANNEL_RSSI, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_RSSI)); + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_RSSI, + CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_RSSI)); this.channelIdsWithConfig.put(CHANNEL_REPEATCOUNT, new Configuration()); - this.supportedChannels.put(CHANNEL_REPEATCOUNT, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_REPEATCOUNT)); + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_REPEATCOUNT, + CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_REPEATCOUNT)); this.channelIdsWithConfig.put(CHANNEL_LASTRECEIVED, new Configuration()); - this.supportedChannels.put(CHANNEL_LASTRECEIVED, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_LASTRECEIVED)); + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_LASTRECEIVED, + CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_LASTRECEIVED)); if (requestsResponse) { this.channelIdsWithConfig.put(CHANNEL_STATUS_REQUEST_EVENT, new Configuration()); - this.supportedChannels.put(CHANNEL_STATUS_REQUEST_EVENT, + this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_STATUS_REQUEST_EVENT, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_STATUS_REQUEST_EVENT)); } } + private static Hashtable addChannelDescription( + Hashtable channels, @Nullable String id, + @Nullable EnOceanChannelDescription channelDescription) { + if (id != null && channelDescription != null) { + channels.put(id, channelDescription); + } + return channels; + } + public Class getEEPClass() { return eepClass; } @@ -678,7 +699,7 @@ public enum EEPType { return requestsResponse; } - public Map GetSupportedChannels() { + public Map getSupportedChannels() { return Collections.unmodifiableMap(supportedChannels); } @@ -694,11 +715,10 @@ public enum EEPType { || supportedChannels.values().stream().anyMatch(c -> c.channelTypeUID.getId().equals(channelTypeId)); } - public ThingTypeUID getThingTypeUID() { + public @Nullable ThingTypeUID getThingTypeUID() { return thingTypeUID; } - @NonNull public String getId() { if (command == -1) { return String.format("%02X_%02X_%02X", rorg.getValue(), func, type); @@ -709,18 +729,14 @@ public enum EEPType { } } - @NonNull public Configuration getChannelConfig(String channelId) { Configuration c = null; - - if (channelIdsWithConfig != null) { + if (!channelIdsWithConfig.isEmpty()) { c = channelIdsWithConfig.get(channelId); + if (c != null) { + return c; + } } - - if (c != null) { - return c; - } - return new Configuration(); } @@ -736,7 +752,7 @@ public enum EEPType { public static EEPType getType(Class eepClass) { for (EEPType eep : values()) { - if (eep.eepClass != null && eep.eepClass.equals(eepClass)) { + if (eep.eepClass.equals(eepClass)) { return eep; } } @@ -744,7 +760,7 @@ public enum EEPType { throw new IllegalArgumentException(String.format("EEP with class %s could not be found", eepClass.getName())); } - public static EEPType getType(RORG rorg, int func, int type, int manufId) { + public static @Nullable EEPType getType(RORG rorg, int func, int type, int manufId) { EEPType fallback = null; for (EEPType eep : values()) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java index 0b2ee415bc4..60329e831d9 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.enocean.internal.eep.F6_01; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -21,6 +23,7 @@ import org.openhab.core.thing.CommonTriggerEvents; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class F6_01_01 extends _RPSMessage { public F6_01_01() { @@ -32,9 +35,8 @@ public class F6_01_01 extends _RPSMessage { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { - return getBit(bytes[0], 4) ? CommonTriggerEvents.PRESSED : CommonTriggerEvents.RELEASED; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02.java index 10f930a869b..b8feccd0a3f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02.java @@ -14,6 +14,8 @@ package org.openhab.binding.enocean.internal.eep.F6_02; import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.SwitchMode; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -28,18 +30,19 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class F6_02 extends _RPSMessage { - final byte AI = 0; - final byte A0 = 1; - final byte BI = 2; - final byte B0 = 3; - final byte PRESSED = 16; - final byte PRESSED_SEC = 1; + protected static final byte AI = 0; + protected static final byte A0 = 1; + protected static final byte BI = 2; + protected static final byte B0 = 3; + protected static final byte PRESSED = 16; + protected static final byte PRESSED_SEC = 1; - final String DIR1 = "DIR1"; - final String DIR2 = "DIR2"; - final String NODIR = "-"; + protected static final String DIR1 = "DIR1"; + protected static final String DIR2 = "DIR2"; + protected static final String NODIR = "-"; int secondByte = -1; int secondStatus = -1; @@ -83,7 +86,7 @@ public abstract class F6_02 extends _RPSMessage { return dirA + "|" + dirB; } - protected String getChannelEvent(byte dir1, byte dir2) { + protected @Nullable String getChannelEvent(byte dir1, byte dir2) { if ((bytes[0] & PRESSED_SEC) != 0) { // Do not emit an event if channelA is pressed together with channelB as it is undetermined which one gets // fired first diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java index d4d5fe1de76..36126907651 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.Channel; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; @@ -31,6 +33,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class F6_02_01 extends F6_02 { public F6_02_01() { @@ -42,9 +45,8 @@ public class F6_02_01 extends F6_02 { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { - if (t21 && nu) { if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) { return getRockerSwitchAction(config); @@ -58,9 +60,9 @@ public class F6_02_01 extends F6_02 { if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) { return CommonTriggerEvents.RELEASED; } else { - if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) { + if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) { return CommonTriggerEvents.DIR1_RELEASED; - } else if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) { + } else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) { return CommonTriggerEvents.DIR2_RELEASED; } } @@ -71,12 +73,12 @@ public class F6_02_01 extends F6_02 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (command instanceof StringType) { String s = ((StringType) command).toString(); if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) { - setStatus(_RPSMessage.T21Flag); + setStatus(_RPSMessage.T21_FLAG); setData((byte) 0x00); return; } @@ -85,10 +87,10 @@ public class F6_02_01 extends F6_02 { byte dir2 = channelTypeId.equalsIgnoreCase(CHANNEL_VIRTUALROCKERSWITCHB) ? BI : AI; if (s.equals(CommonTriggerEvents.DIR1_PRESSED)) { - setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag)); + setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG)); setData((byte) ((dir1 << 5) | PRESSED)); } else if (s.equals(CommonTriggerEvents.DIR2_PRESSED)) { - setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag)); + setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG)); setData((byte) ((dir2 << 5) | PRESSED)); } } @@ -96,11 +98,11 @@ public class F6_02_01 extends F6_02 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { // this method is used by the classic device listener channels to convert a rocker switch message into an // appropriate item update State currentState = getCurrentStateFunc.apply(channelId); - if (t21 && nu) { + if (t21 && nu && currentState != null) { EnOceanChannelRockerSwitchListenerConfig c = config.as(EnOceanChannelRockerSwitchListenerConfig.class); byte dir1 = c.getChannel() == Channel.ChannelA ? A0 : B0; byte dir2 = c.getChannel() == Channel.ChannelA ? AI : BI; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java index 4cb89535842..514c07eab7e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.Channel; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; @@ -31,6 +33,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class F6_02_02 extends F6_02 { public F6_02_02() { @@ -42,9 +45,8 @@ public class F6_02_02 extends F6_02 { } @Override - protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, + protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent, Configuration config) { - if (t21 && nu) { if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) { return getRockerSwitchAction(config); @@ -57,9 +59,9 @@ public class F6_02_02 extends F6_02 { if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) { return CommonTriggerEvents.RELEASED; } else { - if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) { + if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) { return CommonTriggerEvents.DIR1_RELEASED; - } else if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) { + } else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) { return CommonTriggerEvents.DIR2_RELEASED; } } @@ -70,12 +72,12 @@ public class F6_02_02 extends F6_02 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, @Nullable Configuration config) { if (command instanceof StringType) { String s = ((StringType) command).toString(); if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) { - setStatus(_RPSMessage.T21Flag); + setStatus(_RPSMessage.T21_FLAG); setData((byte) 0x00); return; } @@ -84,10 +86,10 @@ public class F6_02_02 extends F6_02 { byte dir2 = channelTypeId.equalsIgnoreCase(CHANNEL_VIRTUALROCKERSWITCHB) ? B0 : A0; if (s.equals(CommonTriggerEvents.DIR1_PRESSED)) { - setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag)); + setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG)); setData((byte) ((dir1 << 5) | PRESSED)); } else if (s.equals(CommonTriggerEvents.DIR2_PRESSED)) { - setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag)); + setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG)); setData((byte) ((dir2 << 5) | PRESSED)); } } @@ -95,11 +97,11 @@ public class F6_02_02 extends F6_02 { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { // this method is used by the classic device listener channels to convert a rocker switch message into an // appropriate item update State currentState = getCurrentStateFunc.apply(channelId); - if (t21 && nu) { + if (t21 && nu && currentState != null) { EnOceanChannelRockerSwitchListenerConfig c = config.as(EnOceanChannelRockerSwitchListenerConfig.class); byte dir1 = c.getChannel() == Channel.ChannelA ? AI : BI; byte dir2 = c.getChannel() == Channel.ChannelA ? A0 : B0; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_05/F6_05_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_05/F6_05_02.java index 7226158c788..4a92a2723ac 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_05/F6_05_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_05/F6_05_02.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; import org.openhab.core.config.core.Configuration; @@ -27,6 +29,7 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class F6_05_02 extends _RPSMessage { protected static final byte ALARM_OFF = 0x00; @@ -43,8 +46,7 @@ public class F6_05_02 extends _RPSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { switch (channelId) { case CHANNEL_SMOKEDETECTION: return bytes[0] == ALARM_OFF ? OnOffType.OFF : (bytes[0] == ALARM_ON ? OnOffType.ON : UnDefType.UNDEF); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00.java index ecc4b44d496..8af7707a2d8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -29,12 +31,13 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class F6_10_00 extends _RPSMessage { - public final byte Closed = (byte) 0xF0; // 1111xxxx - public final byte Open1 = (byte) 0xE0; // 1110xxxx - public final byte Open2 = (byte) 0xC0; // 1100xxxx - public final byte Tilted = (byte) 0xD0; // 1101xxxx + public static final byte CLOSED = (byte) 0xF0; // 1111xxxx + public static final byte OPEN_1 = (byte) 0xE0; // 1110xxxx + public static final byte OPEN_2 = (byte) 0xC0; // 1100xxxx + public static final byte TILTED = (byte) 0xD0; // 1101xxxx public F6_10_00() { super(); @@ -46,28 +49,27 @@ public class F6_10_00 extends _RPSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { byte data = (byte) (bytes[0] & 0xF0); // todo localization switch (channelId) { case CHANNEL_WINDOWHANDLESTATE: - if (data == Closed) { + if (data == CLOSED) { return new StringType("CLOSED"); - } else if (data == Tilted) { + } else if (data == TILTED) { return new StringType("TILTED"); - } else if (data == Open1 || data == Open2) { + } else if (data == OPEN_1 || data == OPEN_2) { return new StringType("OPEN"); } case CHANNEL_CONTACT: EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class); - if (data == Closed) { + if (data == CLOSED) { return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED; - } else if (data == Tilted) { + } else if (data == TILTED) { return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN; - } else if (data == Open1 || data == Open2) { + } else if (data == OPEN_1 || data == OPEN_2) { return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00_EltakoFPE.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00_EltakoFPE.java index 6a247a5c7a4..6c5b4f440cc 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00_EltakoFPE.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_00_EltakoFPE.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANN import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -28,10 +30,11 @@ import org.openhab.core.types.UnDefType; * * @author Holger Englert - Initial contribution */ +@NonNullByDefault public class F6_10_00_EltakoFPE extends _RPSMessage { - final byte OPEN = 0x00; - final byte CLOSED = 0x10; + protected static final byte OPEN = 0x00; + protected static final byte CLOSED = 0x10; public F6_10_00_EltakoFPE() { super(); @@ -43,7 +46,7 @@ public class F6_10_00_EltakoFPE extends _RPSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { + Function getCurrentStateFunc, Configuration config) { if (channelId.equals(CHANNEL_CONTACT)) { EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class); if (c.inverted) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_01.java index 62f8b665332..93aaac8f451 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_10/F6_10_01.java @@ -16,6 +16,8 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig; import org.openhab.binding.enocean.internal.eep.Base._RPSMessage; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -29,12 +31,13 @@ import org.openhab.core.types.UnDefType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class F6_10_01 extends _RPSMessage { - public final byte Closed = 0x0F; // xxxx1111 - public final byte Open1 = 0x0E; // xxxx1110 - public final byte Open2 = 0x0C; // xxxx1100 - public final byte Tilted = 0x0D; // xxxx1101 + public static final byte CLOSED = 0x0F; // xxxx1111 + public static final byte OPEN_1 = 0x0E; // xxxx1110 + public static final byte OPEN_2 = 0x0C; // xxxx1100 + public static final byte TILTED = 0x0D; // xxxx1101 public F6_10_01() { super(); @@ -46,28 +49,27 @@ public class F6_10_01 extends _RPSMessage { @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - + Function getCurrentStateFunc, Configuration config) { byte data = (byte) (bytes[0] & 0x0F); // todo localization switch (channelId) { case CHANNEL_WINDOWHANDLESTATE: - if (data == Closed) { + if (data == CLOSED) { return new StringType("CLOSED"); - } else if (data == Tilted) { + } else if (data == TILTED) { return new StringType("TILTED"); - } else if (data == Open1 || data == Open2) { + } else if (data == OPEN_1 || data == OPEN_2) { return new StringType("OPEN"); } case CHANNEL_CONTACT: EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class); - if (data == Closed) { + if (data == CLOSED) { return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED; - } else if (data == Tilted) { + } else if (data == TILTED) { return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN; - } else if (data == Open1 || data == Open2) { + } else if (data == OPEN_1 || data == OPEN_2) { return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/Generic4BS.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/Generic4BS.java similarity index 84% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/Generic4BS.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/Generic4BS.java index b449b4fc45a..e6dd3b4351f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/Generic4BS.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/Generic4BS.java @@ -10,14 +10,16 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.eep.Generic; +package org.openhab.binding.enocean.internal.eep.generic; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class Generic4BS extends GenericEEP { public Generic4BS() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericEEP.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericEEP.java similarity index 56% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericEEP.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericEEP.java index b69ec05c4b3..2c61a87f22e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericEEP.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericEEP.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.eep.Generic; +package org.openhab.binding.enocean.internal.eep.generic; import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*; @@ -21,6 +21,8 @@ import java.util.LinkedList; import java.util.List; import java.util.function.Function; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -48,11 +50,11 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class GenericEEP extends EEP { final List> supportedStates = Collections .unmodifiableList(new LinkedList>() { - private static final long serialVersionUID = 1L; { @@ -81,64 +83,69 @@ public class GenericEEP extends EEP { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, - Function getCurrentStateFunc, Configuration config) { - if (config != null) { - EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class); + Function getCurrentStateFunc, @Nullable Configuration config) { + if (config == null) { + logger.error("Cannot handle command {}, when transformation configuration is null", command.toString()); + return; + } + EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class); - String input = channelId + "|" + command.toString(); - String output = Transformation.transform(transformationInfo.transformationType, - transformationInfo.transformationFunction, input); + String input = channelId + "|" + command.toString(); + String output = Transformation.transform(transformationInfo.transformationType, + transformationInfo.transformationFunction, input); - if (output != null && !output.isEmpty() && !input.equals(output)) { - try { - setData(HexUtils.hexToBytes(output)); - } catch (Exception e) { - logger.debug("Command {} could not transformed", command.toString()); - } + if (output != null && !output.isEmpty() && !input.equals(output)) { + try { + setData(HexUtils.hexToBytes(output)); + } catch (IllegalArgumentException e) { + logger.debug("Command {} could not transformed", command.toString()); + throw e; } } } @Override protected State convertToStateImpl(String channelId, String channelTypeId, - Function getCurrentStateFunc, Configuration config) { - if (config != null) { - EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class); + Function getCurrentStateFunc, Configuration config) { + EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class); - String payload = HexUtils.bytesToHex(bytes); - String input = channelId + "|" + payload; - String output = Transformation.transform(transformationInfo.transformationType, - transformationInfo.transformationFunction, input); + String payload = HexUtils.bytesToHex(bytes); + String input = channelId + "|" + payload; + String output = Transformation.transform(transformationInfo.transformationType, + transformationInfo.transformationFunction, input); - if (output != null && !output.isEmpty() && !input.equals(output)) { - String[] parts = output.split("\\|"); + if (output != null && !output.isEmpty() && !input.equals(output)) { + String[] parts = output.split("\\|"); - if (parts.length == 2) { - Class state = supportedStates.stream().filter(s -> s.getName().contains(parts[0])) - .findFirst().orElse(null); + if (parts.length == 2) { + @Nullable + Class state = supportedStates.stream().filter(s -> s.getName().contains(parts[0])) + .findFirst().orElse(null); - if (state != null) { - if (state.isEnum()) { - for (State s : state.getEnumConstants()) { + if (state != null) { + if (state.isEnum()) { + State[] states; + if ((states = state.getEnumConstants()) != null) { + for (State s : states) { if (s.toString().equalsIgnoreCase(parts[1])) { return s; } } - logger.debug("Could not find value '{}' for state '{}'", parts[1], parts[0]); - } else { - try { - return state.getConstructor(String.class).newInstance(parts[1]); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - logger.debug("Could not create state '{}' with value '{}'", parts[0], parts[1]); - } } + logger.debug("Could not find value '{}' for state '{}'", parts[1], parts[0]); } else { - logger.debug("State '{}' not found", parts[0]); + try { + return state.getConstructor(String.class).newInstance(parts[1]); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + logger.debug("Could not create state '{}' with value '{}'", parts[0], parts[1]); + } } } else { - logger.debug("Transformation result malformed: {}", output); + logger.debug("State '{}' not found", parts[0]); } + } else { + logger.debug("Transformation result malformed: {}", output); } } @@ -147,8 +154,9 @@ public class GenericEEP extends EEP { @Override protected int getDataLength() { - if (packet != null) { - return packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; + ERP1Message localPacket = packet; + if (localPacket != null) { + return localPacket.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH; } else { return bytes.length; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericRPS.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericRPS.java similarity index 84% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericRPS.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericRPS.java index 9955d8fac51..68ab79fa7c6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericRPS.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericRPS.java @@ -10,14 +10,16 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.eep.Generic; +package org.openhab.binding.enocean.internal.eep.generic; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class GenericRPS extends GenericEEP { public GenericRPS() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericVLD.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericVLD.java similarity index 84% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericVLD.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericVLD.java index f26ac35953f..d25071b2488 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/Generic/GenericVLD.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/generic/GenericVLD.java @@ -10,14 +10,16 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.eep.Generic; +package org.openhab.binding.enocean.internal.eep.generic; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.ERP1Message; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class GenericVLD extends GenericEEP { public GenericVLD() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseActuatorHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseActuatorHandler.java index 8c4177c5be3..a5ffacc312b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseActuatorHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseActuatorHandler.java @@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanActuatorConfig; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.eep.EEPFactory; @@ -46,6 +48,7 @@ import org.openhab.core.util.HexUtils; * This class defines base functionality for sending eep messages. This class extends EnOceanBaseSensorHandler * class as most actuator things send status or response messages, too. */ +@NonNullByDefault public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { // List of thing types which support sending of eep messages @@ -53,12 +56,13 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { THING_TYPE_MEASUREMENTSWITCH, THING_TYPE_GENERICTHING, THING_TYPE_ROLLERSHUTTER, THING_TYPE_THERMOSTAT, THING_TYPE_HEATRECOVERYVENTILATION); - protected byte[] senderId; // base id of bridge + senderIdOffset, used for sending msg - protected byte[] destinationId; // in case of broadcast FFFFFFFF otherwise the enocean id of the device + protected byte[] senderId = new byte[0]; // base id of bridge + senderIdOffset, used for sending msg + protected byte[] destinationId = new byte[0]; // in case of broadcast FFFFFFFF otherwise the enocean id of the + // device - protected EEPType sendingEEPType = null; + protected @Nullable EEPType sendingEEPType = null; - private ScheduledFuture refreshJob; // used for polling current status of thing + private @Nullable ScheduledFuture refreshJob; // used for polling current status of thing public EnOceanBaseActuatorHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) { super(thing, itemChannelLinkRegistry); @@ -69,7 +73,7 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { * @param senderIdOffset to be validated * @return true if senderIdOffset is between ]0;128[ and is not used yet */ - private boolean validateSenderIdOffset(Integer senderIdOffset) { + private boolean validateSenderIdOffset(@Nullable Integer senderIdOffset) { if (senderIdOffset == null) { return true; } @@ -94,12 +98,16 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { } @Override + @Nullable Collection getEEPTypes() { Collection r = super.getEEPTypes(); + if (sendingEEPType == null) { return r; } - + if (r == null) { + r = Collections.emptyList(); + } return Collections.unmodifiableCollection(Stream .concat(r.stream(), Collections.singletonList(sendingEEPType).stream()).collect(Collectors.toList())); } @@ -107,18 +115,16 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { @Override boolean validateConfig() { EnOceanActuatorConfig config = getConfiguration(); - if (config == null) { - configurationErrorDescription = "Configuration is not valid"; - return false; - } - if (config.sendingEEPId == null || config.sendingEEPId.isEmpty()) { + if (config.sendingEEPId.isEmpty()) { configurationErrorDescription = "Sending EEP must be provided"; return false; } + EEPType localEEPType = null; try { - sendingEEPType = EEPType.getType(getConfiguration().sendingEEPId); + localEEPType = EEPType.getType(getConfiguration().sendingEEPId); + sendingEEPType = localEEPType; } catch (IllegalArgumentException e) { configurationErrorDescription = "Sending EEP is not supported"; return false; @@ -126,7 +132,7 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { if (super.validateConfig()) { try { - if (sendingEEPType.getSupportsRefresh()) { + if (localEEPType.getSupportsRefresh()) { if (getConfiguration().pollingInterval > 0) { refreshJob = scheduler.scheduleWithFixedDelay(() -> { try { @@ -166,28 +172,30 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { // Generic things are treated as actuator things, however to support also generic sensors one can omit // senderIdOffset // TODO: seperate generic actuators from generic sensors? - if ((getConfiguration().senderIdOffset == null - && THING_TYPE_GENERICTHING.equals(this.getThing().getThingTypeUID()))) { + Integer senderOffset = getConfiguration().senderIdOffset; + + if ((senderOffset == null && THING_TYPE_GENERICTHING.equals(this.getThing().getThingTypeUID()))) { return true; } // if senderIdOffset is not set, the next free senderIdOffset is determined - if (getConfiguration().senderIdOffset == null) { + if (senderOffset == null) { Configuration updateConfig = editConfiguration(); - getConfiguration().senderIdOffset = bridgeHandler.getNextSenderId(thing); - if (getConfiguration().senderIdOffset == null) { + senderOffset = bridgeHandler.getNextSenderId(thing); + getConfiguration().senderIdOffset = senderOffset; + if (senderOffset == null) { configurationErrorDescription = "Could not get a free sender Id from Bridge"; return false; } - updateConfig.put(PARAMETER_SENDERIDOFFSET, getConfiguration().senderIdOffset); + updateConfig.put(PARAMETER_SENDERIDOFFSET, senderOffset); updateConfiguration(updateConfig); } byte[] baseId = bridgeHandler.getBaseId(); - baseId[3] = (byte) ((baseId[3] + getConfiguration().senderIdOffset) & 0xFF); + baseId[3] = (byte) ((baseId[3] + senderOffset) & 0xFF); this.senderId = baseId; this.updateProperty(PROPERTY_SENDINGENOCEAN_ID, HexUtils.bytesToHex(this.senderId)); - bridgeHandler.addSender(getConfiguration().senderIdOffset, thing); + bridgeHandler.addSender(senderOffset, thing); return true; } @@ -205,21 +213,34 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { sendMessage(VIRTUALCHANNEL_SEND_COMMAND, VIRTUALCHANNEL_SEND_COMMAND, OnOffType.ON, null); } - protected void sendMessage(String channelId, String channelTypeId, Command command, Configuration channelConfig) { - EEP eep = EEPFactory.createEEP(sendingEEPType); + protected void sendMessage(String channelId, String channelTypeId, Command command, + @Nullable Configuration channelConfig) { + EEPType sendType = sendingEEPType; + if (sendType == null) { + logger.warn("cannot send a message with an empty EEPType"); + return; + } + EEP eep = EEPFactory.createEEP(sendType); if (eep.convertFromCommand(channelId, channelTypeId, command, id -> getCurrentState(id), channelConfig) .hasData()) { BasePacket msg = eep.setSenderId(senderId).setDestinationId(destinationId) .setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message(); - - getBridgeHandler().sendMessage(msg, null); + if (msg == null) { + logger.warn("cannot send an empty message"); + return; + } + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.sendMessage(msg, null); + } } } @Override public void handleCommand(ChannelUID channelUID, Command command) { // We must have a valid sendingEEPType and sender id to send commands - if (sendingEEPType == null || senderId == null) { + EEPType localsendingType = sendingEEPType; + if (localsendingType == null) { return; } @@ -235,7 +256,7 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { // check if we do support refreshs if (command == RefreshType.REFRESH) { - if (!sendingEEPType.getSupportsRefresh()) { + if (!localsendingType.getSupportsRefresh()) { return; } @@ -258,11 +279,11 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { @Override public void handleRemoval() { - EnOceanBridgeHandler bridgeHandler = getBridgeHandler(); if (bridgeHandler != null) { - if (getConfiguration().senderIdOffset != null && getConfiguration().senderIdOffset > 0) { - bridgeHandler.removeSender(getConfiguration().senderIdOffset); + Integer senderOffset = getConfiguration().senderIdOffset; + if (senderOffset != null && senderOffset > 0) { + bridgeHandler.removeSender(senderOffset); } if (bridgeHandler.isSmackClient(this.thing)) { @@ -275,8 +296,9 @@ public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler { @Override public void dispose() { - if (refreshJob != null && !refreshJob.isCancelled()) { - refreshJob.cancel(true); + ScheduledFuture localRefreshJob = refreshJob; + if (localRefreshJob != null && !localRefreshJob.isCancelled()) { + localRefreshJob.cancel(true); refreshJob = null; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java index 67d0790ddb4..b67e7ec2ccc 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java @@ -23,6 +23,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanBaseConfig; import org.openhab.binding.enocean.internal.eep.EEP; import org.openhab.binding.enocean.internal.eep.EEPFactory; @@ -48,6 +50,7 @@ import org.openhab.core.util.HexUtils; * @author Daniel Weber - Initial contribution * This class defines base functionality for receiving eep messages. */ +@NonNullByDefault public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements PacketListener { // List of all thing types which support receiving of eep messages @@ -60,7 +63,7 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements protected final Hashtable receivingEEPTypes = new Hashtable<>(); - protected ScheduledFuture responseFuture = null; + protected @Nullable ScheduledFuture responseFuture = null; public EnOceanBaseSensorHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) { super(thing, itemChannelLinkRegistry); @@ -72,6 +75,7 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements } @Override + @Nullable Collection getEEPTypes() { return Collections.unmodifiableCollection(receivingEEPTypes.values()); } @@ -82,7 +86,8 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements try { config.receivingEEPId.forEach(receivingEEP -> { EEPType receivingEEPType = EEPType.getType(receivingEEP); - if (receivingEEPTypes.putIfAbsent(receivingEEPType.getRORG(), receivingEEPType) != null) { + EEPType existingKey = receivingEEPTypes.putIfAbsent(receivingEEPType.getRORG(), receivingEEPType); + if (existingKey != null) { throw new IllegalArgumentException("Receiving more than one EEP of the same RORG is not supported"); } }); @@ -90,7 +95,9 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements receivingEEPTypes.put(EEPType.SigBatteryStatus.getRORG(), EEPType.SigBatteryStatus); } } catch (IllegalArgumentException e) { - configurationErrorDescription = e.getMessage(); + String eMessage = e.getMessage(); + configurationErrorDescription = eMessage != null ? eMessage + : "IllegalArgumentException without a message was thrown"; return false; } @@ -102,7 +109,10 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements } if (!config.enoceanId.equals(EMPTYENOCEANID)) { - getBridgeHandler().addPacketListener(this); + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.addPacketListener(this); + } } return true; @@ -115,8 +125,9 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements @Override public void handleRemoval() { - if (getBridgeHandler() != null) { - getBridgeHandler().removePacketListener(this); + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.removePacketListener(this); } super.handleRemoval(); } @@ -142,12 +153,13 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements @Override public void packetReceived(BasePacket packet) { ERP1Message msg = (ERP1Message) packet; - EEPType receivingEEPType = receivingEEPTypes.get(msg.getRORG()); - if (receivingEEPType == null) { + + EEPType localReceivingType = receivingEEPTypes.get(msg.getRORG()); + if (localReceivingType == null) { return; } - EEP eep = EEPFactory.buildEEP(receivingEEPType, (ERP1Message) packet); + EEP eep = EEPFactory.buildEEP(localReceivingType, (ERP1Message) packet); logger.debug("ESP Packet payload {} for {} received", HexUtils.bytesToHex(packet.getPayload()), HexUtils.bytesToHex(msg.getSenderId())); @@ -155,7 +167,7 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements byte[] senderId = msg.getSenderId(); // try to interpret received message for all linked or trigger channels - getThing().getChannels().stream().filter(channelFilter(receivingEEPType, senderId)) + getThing().getChannels().stream().filter(channelFilter(localReceivingType, senderId)) .sorted(Comparator.comparing(Channel::getKind)) // handle state channels first .forEachOrdered(channel -> { @@ -171,27 +183,31 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements this::getCurrentState); // if message can be interpreted (result != UnDefType.UNDEF) => update item state - if (result != null && result != UnDefType.UNDEF) { + if (result != UnDefType.UNDEF) { updateState(channelId, result); } break; case TRIGGER: String lastEvent = lastEvents.get(channelId); - String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, channelConfig); - if (event != null) { - triggerChannel(channel.getUID(), event); - lastEvents.put(channelId, event); + if (lastEvent != null) { + String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, + channelConfig); + if (event != null) { + triggerChannel(channel.getUID(), event); + lastEvents.put(channelId, event); + } } break; } }); - if (receivingEEPType.getRequstesResponse()) { + if (localReceivingType.getRequstesResponse()) { // fire trigger for receive triggerChannel(prepareAnswer, "requestAnswer"); // Send response after 100ms - if (responseFuture == null || responseFuture.isDone()) { - responseFuture = scheduler.schedule(this::sendRequestResponse, 100, TimeUnit.MILLISECONDS); + ScheduledFuture localResponseFuture = responseFuture; + if (localResponseFuture == null || localResponseFuture.isDone()) { + localResponseFuture = scheduler.schedule(this::sendRequestResponse, 100, TimeUnit.MILLISECONDS); } } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java index e308d4c6af4..c598caa3077 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java @@ -22,7 +22,8 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanChannelDescription; import org.openhab.binding.enocean.internal.config.EnOceanBaseConfig; import org.openhab.binding.enocean.internal.eep.EEPType; @@ -50,22 +51,23 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { - private EnOceanBridgeHandler gateway = null; + private @Nullable EnOceanBridgeHandler gateway = null; protected Logger logger = LoggerFactory.getLogger(EnOceanBaseThingHandler.class); - protected String configurationErrorDescription; + protected String configurationErrorDescription = ""; // There is no data structure which holds the last triggered event, so we have to implement it by ourself // This is especially needed for press and release events protected Hashtable lastEvents = new Hashtable<>(); - protected EnOceanBaseConfig config = null; + protected EnOceanBaseConfig config = new EnOceanBaseConfig(); private ItemChannelLinkRegistry itemChannelLinkRegistry; - protected @NonNull ChannelUID prepareAnswer; + protected ChannelUID prepareAnswer; public EnOceanBaseThingHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) { super(thing); @@ -77,7 +79,6 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { public void initialize() { logger.debug("Initializing enocean base thing handler."); this.gateway = null; // reset gateway in case we change the bridge - this.config = null; Bridge bridge = getBridge(); if (bridge == null) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "A bridge is required"); @@ -89,29 +90,24 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { private void initializeThing(ThingStatus bridgeStatus) { logger.debug("initializeThing thing {} bridge status {}", getThing().getUID(), bridgeStatus); - if (this.itemChannelLinkRegistry == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "ItemChannelLinkRegistry could not be found"); - } else { - if (getBridgeHandler() != null) { - if (bridgeStatus == ThingStatus.ONLINE) { - initializeConfig(); - if (validateConfig()) { - updateStatus(ThingStatus.ONLINE); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - configurationErrorDescription); - } + if (getBridgeHandler() != null) { + if (bridgeStatus == ThingStatus.ONLINE) { + initializeConfig(); + if (validateConfig()) { + updateStatus(ThingStatus.ONLINE); } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + configurationErrorDescription); } } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "A bridge is required"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE); } + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "A bridge is required"); } } - protected boolean validateEnoceanId(String id) { + protected boolean validateEnoceanId(@Nullable String id) { if (id == null || id.isEmpty()) { return false; } else { @@ -132,11 +128,10 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { abstract boolean validateConfig(); - abstract Collection getEEPTypes(); + abstract @Nullable Collection getEEPTypes(); protected void updateChannels() { - @NonNull - List<@NonNull Channel> channelList = new LinkedList<>(this.getThing().getChannels()); + List channelList = new LinkedList<>(this.getThing().getChannels()); Collection eeps = getEEPTypes(); if (eeps == null) { return; @@ -147,10 +142,10 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { channelList.removeIf(channel -> !eeps.stream().anyMatch(eep -> eep.isChannelSupported(channel)))); // Next create supported channels of each selected eep - eeps.stream().flatMap(eep -> eep.GetSupportedChannels().keySet().stream().map(id -> new SimpleEntry<>(id, eep))) + eeps.stream().flatMap(eep -> eep.getSupportedChannels().keySet().stream().map(id -> new SimpleEntry<>(id, eep))) .forEach(entry -> { String channelId = entry.getKey(); - EnOceanChannelDescription cd = entry.getValue().GetSupportedChannels().get(channelId); + EnOceanChannelDescription cd = entry.getValue().getSupportedChannels().get(channelId); if (cd == null) { return; @@ -189,7 +184,7 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { } } - protected State getCurrentState(Channel channel) { + protected State getCurrentState(@Nullable Channel channel) { if (channel != null) { Set items = itemChannelLinkRegistry.getLinkedItems(channel.getUID()); for (Item item : items) { @@ -207,7 +202,7 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { return getCurrentState(getThing().getChannel(channelId)); } - protected synchronized EnOceanBridgeHandler getBridgeHandler() { + protected synchronized @Nullable EnOceanBridgeHandler getBridgeHandler() { if (this.gateway == null) { Bridge bridge = getBridge(); if (bridge == null) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java index 91be555bcb3..cadb17f98de 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java @@ -23,6 +23,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanConfigStatusMessage; import org.openhab.binding.enocean.internal.config.EnOceanBaseConfig; import org.openhab.binding.enocean.internal.config.EnOceanBridgeConfig; @@ -31,12 +33,12 @@ import org.openhab.binding.enocean.internal.messages.BasePacket; import org.openhab.binding.enocean.internal.messages.ESP3PacketFactory; import org.openhab.binding.enocean.internal.messages.Response; import org.openhab.binding.enocean.internal.messages.Response.ResponseType; -import org.openhab.binding.enocean.internal.messages.Responses.BaseResponse; -import org.openhab.binding.enocean.internal.messages.Responses.RDBaseIdResponse; -import org.openhab.binding.enocean.internal.messages.Responses.RDLearnedClientsResponse; -import org.openhab.binding.enocean.internal.messages.Responses.RDLearnedClientsResponse.LearnedClient; -import org.openhab.binding.enocean.internal.messages.Responses.RDRepeaterResponse; -import org.openhab.binding.enocean.internal.messages.Responses.RDVersionResponse; +import org.openhab.binding.enocean.internal.messages.responses.BaseResponse; +import org.openhab.binding.enocean.internal.messages.responses.RDBaseIdResponse; +import org.openhab.binding.enocean.internal.messages.responses.RDLearnedClientsResponse; +import org.openhab.binding.enocean.internal.messages.responses.RDLearnedClientsResponse.LearnedClient; +import org.openhab.binding.enocean.internal.messages.responses.RDRepeaterResponse; +import org.openhab.binding.enocean.internal.messages.responses.RDVersionResponse; import org.openhab.binding.enocean.internal.transceiver.EnOceanESP2Transceiver; import org.openhab.binding.enocean.internal.transceiver.EnOceanESP3Transceiver; import org.openhab.binding.enocean.internal.transceiver.EnOceanTransceiver; @@ -69,16 +71,17 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements TransceiverErrorListener { private Logger logger = LoggerFactory.getLogger(EnOceanBridgeHandler.class); public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE); - private EnOceanTransceiver transceiver; // holds connection to serial/tcp port and sends/receives messages - private ScheduledFuture connectorTask; // is used for reconnection if something goes wrong + private @Nullable EnOceanTransceiver transceiver; // holds connection to serial/tcp port and sends/receives messages + private @Nullable ScheduledFuture connectorTask; // is used for reconnection if something goes wrong - private byte[] baseId = null; + private byte[] baseId = new byte[0]; private Thing[] sendingThings = new Thing[128]; private SerialPortManager serialPortManager; @@ -161,28 +164,26 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T @Override public void initialize() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "trying to connect to gateway..."); - if (this.serialPortManager == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "SerialPortManager could not be found"); - } else { - if (connectorTask == null || connectorTask.isDone()) { - connectorTask = scheduler.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - if (thing.getStatus() != ThingStatus.ONLINE) { - initTransceiver(); - } + + ScheduledFuture localConnectorTask = connectorTask; + if (localConnectorTask == null || localConnectorTask.isDone()) { + localConnectorTask = scheduler.scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + if (thing.getStatus() != ThingStatus.ONLINE) { + initTransceiver(); } - }, 0, 60, TimeUnit.SECONDS); - } + } + }, 0, 60, TimeUnit.SECONDS); } } private synchronized void initTransceiver() { try { EnOceanBridgeConfig c = getThing().getConfiguration().as(EnOceanBridgeConfig.class); - if (transceiver != null) { - transceiver.ShutDown(); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.shutDown(); } switch (c.getESPVersion()) { @@ -199,15 +200,22 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T break; } + localTransceiver = transceiver; + if (localTransceiver == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "Failed to initialize EnOceanTransceiver"); + return; + } + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "opening serial port..."); - transceiver.Initialize(); + localTransceiver.initilize(); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "starting rx thread..."); - transceiver.StartReceiving(scheduler); + localTransceiver.startReceiving(scheduler); logger.info("EnOceanSerialTransceiver RX thread up and running"); if (c.rs485) { - if (c.rs485BaseId != null && !c.rs485BaseId.isEmpty()) { + if (!c.rs485BaseId.isEmpty()) { baseId = HexUtils.hexToBytes(c.rs485BaseId); if (baseId.length != 4) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, @@ -224,18 +232,21 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T "trying to get bridge base id..."); logger.debug("request base id"); - transceiver.sendBasePacket(ESP3PacketFactory.CO_RD_IDBASE, + localTransceiver.sendBasePacket(ESP3PacketFactory.CO_RD_IDBASE, new ResponseListenerIgnoringTimeouts() { + @Override public void responseReceived(RDBaseIdResponse response) { logger.debug("received response for base id"); if (response.isValid() && response.isOK()) { baseId = response.getBaseId().clone(); updateProperty(PROPERTY_BASE_ID, HexUtils.bytesToHex(response.getBaseId())); - updateProperty(PROPERTY_REMAINING_WRITE_CYCLES_Base_ID, + updateProperty(PROPERTY_REMAINING_WRITE_CYCLES_BASE_ID, Integer.toString(response.getRemainingWriteCycles())); - transceiver.setFilteredDeviceId(baseId); - + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.setFilteredDeviceId(baseId); + } updateStatus(ThingStatus.ONLINE); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, @@ -246,12 +257,11 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T if (c.getESPVersion() == ESPVersion.ESP3) { logger.debug("set postmaster mailboxes"); - transceiver.sendBasePacket(ESP3PacketFactory.SA_WR_POSTMASTER((byte) (c.enableSmack ? 20 : 0)), + localTransceiver.sendBasePacket(ESP3PacketFactory.SA_WR_POSTMASTER((byte) (c.enableSmack ? 20 : 0)), new ResponseListenerIgnoringTimeouts() { @Override public void responseReceived(BaseResponse response) { - logger.debug("received response for postmaster mailboxes"); if (response.isOK()) { updateProperty("Postmaster mailboxes:", @@ -268,8 +278,9 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T } logger.debug("request version info"); - transceiver.sendBasePacket(ESP3PacketFactory.CO_RD_VERSION, + localTransceiver.sendBasePacket(ESP3PacketFactory.CO_RD_VERSION, new ResponseListenerIgnoringTimeouts() { + @Override public void responseReceived(RDVersionResponse response) { if (response.isValid() && response.isOK()) { @@ -292,13 +303,15 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T @Override public synchronized void dispose() { - if (transceiver != null) { - transceiver.ShutDown(); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.shutDown(); transceiver = null; } - if (connectorTask != null && !connectorTask.isDone()) { - connectorTask.cancel(true); + ScheduledFuture localConnectorTask = connectorTask; + if (localConnectorTask != null && !localConnectorTask.isDone()) { + localConnectorTask.cancel(true); connectorTask = null; } @@ -311,10 +324,13 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T // The serial port must be provided String path = getThing().getConfiguration().as(EnOceanBridgeConfig.class).path; - if (path == null || path.isEmpty()) { - configStatusMessages.add(ConfigStatusMessage.Builder.error(PATH) + if (path.isEmpty()) { + ConfigStatusMessage statusMessage = ConfigStatusMessage.Builder.error(PATH) .withMessageKeySuffix(EnOceanConfigStatusMessage.PORT_MISSING.getMessageKey()).withArguments(PATH) - .build()); + .build(); + if (statusMessage != null) { + configStatusMessages.add(statusMessage); + } } return configStatusMessages; @@ -328,19 +344,22 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T return smackClients.contains(sender.getConfiguration().as(EnOceanBaseConfig.class).enoceanId); } - public Integer getNextSenderId(Thing sender) { + public @Nullable Integer getNextSenderId(Thing sender) { return getNextSenderId(sender.getConfiguration().as(EnOceanBaseConfig.class).enoceanId); } - public Integer getNextSenderId(String enoceanId) { + public @Nullable Integer getNextSenderId(String enoceanId) { EnOceanBridgeConfig config = getConfigAs(EnOceanBridgeConfig.class); - - if (config.nextSenderId != null && sendingThings[config.nextSenderId] == null) { + Integer senderId = config.nextSenderId; + if (senderId == null) { + return null; + } + if (sendingThings[senderId] == null) { Configuration c = this.editConfiguration(); c.put(PARAMETER_NEXT_SENDERID, null); updateConfiguration(c); - return config.nextSenderId; + return senderId; } for (int i = 1; i < sendingThings.length; i++) { @@ -366,9 +385,14 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T sendingThings[id] = null; } - public void sendMessage(BasePacket message, ResponseListener responseListener) { + public void sendMessage(BasePacket message, + @Nullable ResponseListener responseListener) { try { - transceiver.sendBasePacket(message, responseListener); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver == null) { + throw new IOException("EnOceanTransceiver has state null"); + } + localTransceiver.sendBasePacket(message, responseListener); } catch (IOException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } @@ -379,8 +403,9 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T } public void addPacketListener(PacketListener listener, long senderIdToListenTo) { - if (transceiver != null) { - transceiver.addPacketListener(listener, senderIdToListenTo); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.addPacketListener(listener, senderIdToListenTo); } } @@ -389,24 +414,29 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T } public void removePacketListener(PacketListener listener, long senderIdToListenTo) { - if (transceiver != null) { - transceiver.removePacketListener(listener, senderIdToListenTo); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.removePacketListener(listener, senderIdToListenTo); } } public void startDiscovery(TeachInListener teachInListener) { - transceiver.startDiscovery(teachInListener); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.startDiscovery(teachInListener); + } if (smackAvailable) { // activate smack teach in logger.debug("activate smack teach in"); try { - transceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(true), + if (localTransceiver == null) { + throw new IOException("EnOceanTransceiver has state null"); + } + localTransceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(true), new ResponseListenerIgnoringTimeouts() { - @Override public void responseReceived(BaseResponse response) { - if (response.isOK()) { logger.debug("Smack teach in activated"); } @@ -420,10 +450,16 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T } public void stopDiscovery() { - transceiver.stopDiscovery(); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.stopDiscovery(); + } try { - transceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(false), null); + if (localTransceiver == null) { + throw new IOException("EnOceanTransceiver has state null"); + } + localTransceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(false), null); refreshProperties(); } catch (IOException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, @@ -433,41 +469,43 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T private void refreshProperties() { if (getThing().getStatus() == ThingStatus.ONLINE && smackAvailable) { - logger.debug("request learned smack clients"); try { - transceiver.sendBasePacket(ESP3PacketFactory.SA_RD_LEARNEDCLIENTS, - new ResponseListenerIgnoringTimeouts() { - - @Override - public void responseReceived(RDLearnedClientsResponse response) { - - logger.debug("received response for learned smack clients"); - if (response.isValid() && response.isOK()) { - LearnedClient[] clients = response.getLearnedClients(); - updateProperty("Learned smart ack clients", Integer.toString(clients.length)); - updateProperty("Smart ack clients", - Arrays.stream(clients) - .map(x -> String.format("%s (MB Idx: %d)", - HexUtils.bytesToHex(x.clientId), x.mailboxIndex)) - .collect(Collectors.joining(", "))); - smackClients = Arrays.stream(clients).map(x -> HexUtils.bytesToHex(x.clientId)) - .collect(Collectors.toSet()); + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.sendBasePacket(ESP3PacketFactory.SA_RD_LEARNEDCLIENTS, + new ResponseListenerIgnoringTimeouts() { + @Override + public void responseReceived(RDLearnedClientsResponse response) { + logger.debug("received response for learned smack clients"); + if (response.isValid() && response.isOK()) { + LearnedClient[] clients = response.getLearnedClients(); + updateProperty("Learned smart ack clients", Integer.toString(clients.length)); + updateProperty("Smart ack clients", + Arrays.stream(clients) + .map(x -> String.format("%s (MB Idx: %d)", + HexUtils.bytesToHex(x.clientId), x.mailboxIndex)) + .collect(Collectors.joining(", "))); + smackClients = Arrays.stream(clients).map(x -> HexUtils.bytesToHex(x.clientId)) + .collect(Collectors.toSet()); + } } - } - }); + }); + } } catch (IOException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Smack packet could not be send: " + e.getMessage()); - } } } @Override - public void ErrorOccured(Throwable exception) { - transceiver.ShutDown(); - transceiver = null; + public void errorOccured(Throwable exception) { + EnOceanTransceiver localTransceiver = transceiver; + if (localTransceiver != null) { + localTransceiver.shutDown(); + transceiver = null; + } updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, exception.getMessage()); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java index c670378b44e..f0d94de609b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java @@ -19,7 +19,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.config.EnOceanActuatorConfig; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.SwitchMode; import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig; @@ -51,12 +52,14 @@ import org.openhab.core.util.HexUtils; * This class defines base functionality for sending eep messages. This class extends EnOceanBaseSensorHandler * class as most actuator things send status or response messages, too. */ +@NonNullByDefault public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { // List of thing types which support sending of eep messages public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_CLASSICDEVICE); private StringType lastTriggerEvent = StringType.valueOf(CommonTriggerEvents.DIR1_PRESSED); + @Nullable ScheduledFuture releaseFuture = null; public EnOceanClassicDeviceHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) { @@ -76,7 +79,7 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { } @Override - public void channelLinked(@NonNull ChannelUID channelUID) { + public void channelLinked(ChannelUID channelUID) { super.channelLinked(channelUID); // if linked channel is a listening channel => put listener @@ -90,7 +93,10 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { // it seems that there does not exist a channel update callback // => remove all listeners and add them again - getBridgeHandler().removePacketListener(this); + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.removePacketListener(this); + } this.getThing().getChannels().forEach(c -> { if (isLinked(c.getUID()) && !addListener(c)) { @@ -100,7 +106,7 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { } @Override - public void channelUnlinked(@NonNull ChannelUID channelUID) { + public void channelUnlinked(ChannelUID channelUID) { super.channelUnlinked(channelUID); // if unlinked channel is listening channel => remove listener @@ -108,7 +114,7 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { removeListener(channel); } - protected boolean addListener(Channel channel) { + protected boolean addListener(@Nullable Channel channel) { if (channel == null) { return true; } @@ -120,7 +126,11 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { EnOceanChannelRockerSwitchListenerConfig config = channel.getConfiguration() .as(EnOceanChannelRockerSwitchListenerConfig.class); try { - getBridgeHandler().addPacketListener(this, Long.parseLong(config.enoceanId, 16)); + @Nullable + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.addPacketListener(this, Long.parseLong(config.enoceanId, 16)); + } return true; } catch (NumberFormatException e) { } @@ -130,7 +140,7 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { return true; } - protected void removeListener(Channel channel) { + protected void removeListener(@Nullable Channel channel) { if (channel == null) { return; } @@ -142,7 +152,10 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { EnOceanChannelRockerSwitchListenerConfig config = channel.getConfiguration() .as(EnOceanChannelRockerSwitchListenerConfig.class); try { - getBridgeHandler().removePacketListener(this, Long.parseLong(config.enoceanId, 16)); + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.removePacketListener(this, Long.parseLong(config.enoceanId, 16)); + } } catch (NumberFormatException e) { } } @@ -166,7 +179,7 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { : StringType.valueOf(CommonTriggerEvents.DIR2_RELEASED); } - private StringType convertToPressedCommand(Command command, SwitchMode switchMode) { + private @Nullable StringType convertToPressedCommand(Command command, SwitchMode switchMode) { if (command instanceof StringType) { return (StringType) command; } else if (command instanceof OnOffType) { @@ -203,9 +216,9 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { } @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { // We must have a valid sendingEEPType and sender id to send commands - if (sendingEEPType == null || senderId == null || command == RefreshType.REFRESH) { + if (sendingEEPType == null || senderId.length == 0 || command == RefreshType.REFRESH) { return; } @@ -228,22 +241,34 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { if (result != null) { lastTriggerEvent = result; - - EEP eep = EEPFactory.createEEP(sendingEEPType); - if (eep.setSenderId(senderId).setDestinationId(destinationId).convertFromCommand(channelId, channelTypeId, - result, id -> this.getCurrentState(id), channel.getConfiguration()).hasData()) { - BasePacket press = eep.setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message(); - - getBridgeHandler().sendMessage(press, null); - - if (channelConfig.duration > 0) { - releaseFuture = scheduler.schedule(() -> { - if (eep.convertFromCommand(channelId, channelTypeId, convertToReleasedCommand(lastTriggerEvent), - id -> this.getCurrentState(id), channel.getConfiguration()).hasData()) { - BasePacket release = eep.getERP1Message(); - getBridgeHandler().sendMessage(release, null); + EEPType localSendType = sendingEEPType; + if (localSendType != null) { + EEP eep = EEPFactory.createEEP(localSendType); + if (eep.setSenderId(senderId).setDestinationId(destinationId).convertFromCommand(channelId, + channelTypeId, result, id -> this.getCurrentState(id), channel.getConfiguration()).hasData()) { + BasePacket press = eep.setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message(); + if (press != null) { + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.sendMessage(press, null); } - }, channelConfig.duration, TimeUnit.MILLISECONDS); + } + + if (channelConfig.duration > 0) { + releaseFuture = scheduler.schedule(() -> { + if (eep.convertFromCommand(channelId, channelTypeId, + convertToReleasedCommand(lastTriggerEvent), id -> this.getCurrentState(id), + channel.getConfiguration()).hasData()) { + BasePacket release = eep.getERP1Message(); + if (release != null) { + EnOceanBridgeHandler handler = getBridgeHandler(); + if (handler != null) { + handler.sendMessage(release, null); + } + } + } + }, channelConfig.duration, TimeUnit.MILLISECONDS); + } } } } @@ -251,8 +276,10 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { @Override public void handleRemoval() { - if (releaseFuture != null && !releaseFuture.isDone()) { - releaseFuture.cancel(true); + ScheduledFuture future = releaseFuture; + if (future != null && !future.isDone()) { + future.cancel(true); + future = null; } releaseFuture = null; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/BasePacket.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/BasePacket.java index 6b4053982d4..9eb9cef3568 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/BasePacket.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/BasePacket.java @@ -15,10 +15,13 @@ package org.openhab.binding.enocean.internal.messages; import java.security.InvalidParameterException; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class BasePacket { public enum ESPPacketType { @@ -65,7 +68,7 @@ public abstract class BasePacket { protected ESPPacketType packetType; protected byte[] data; - protected byte[] optionalData; + protected byte[] optionalData = new byte[0]; public BasePacket(int dataLength, int optionalDataLength, ESPPacketType packetType, byte[] payload) { this(dataLength, optionalDataLength, packetType.value, payload); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/CCMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/CCMessage.java index bdfa00af298..a03a9a4393f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/CCMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/CCMessage.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.messages; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault class CCMessage extends BasePacket { public enum CCMessageType { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ERP1Message.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ERP1Message.java index 1b236027cd5..4c398ee6eae 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ERP1Message.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ERP1Message.java @@ -15,6 +15,7 @@ package org.openhab.binding.enocean.internal.messages; import java.security.InvalidParameterException; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.eep.Base.UTEResponse; import org.openhab.binding.enocean.internal.eep.Base._1BSMessage; import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; @@ -23,6 +24,7 @@ import org.openhab.binding.enocean.internal.eep.Base._4BSMessage; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class ERP1Message extends BasePacket { // these are just ESP3 RORGs, ESP2 ORGs are converted by ESP2PacketConverter @@ -87,13 +89,13 @@ public class ERP1Message extends BasePacket { case _1BS: if (dataLength >= 6) { senderId = Arrays.copyOfRange(payload, 2, 6); - teachIn = ((_1BSMessage.TeachInBit & payload[1]) == 0); + teachIn = ((_1BSMessage.TEACHIN_BIT & payload[1]) == 0); } break; case _4BS: if (dataLength >= 9) { senderId = Arrays.copyOfRange(payload, 5, 9); - teachIn = (_4BSMessage.TeachInBit & payload[4]) == 0; + teachIn = (_4BSMessage.TEACHIN_BIT & payload[4]) == 0; } break; case VLD: @@ -102,8 +104,8 @@ public class ERP1Message extends BasePacket { break; case UTE: if (dataLength >= 6) { - teachIn = (payload[1] & UTEResponse.TeachIn_MASK) == 0 - || (payload[1] & UTEResponse.TeachIn_MASK) == UTEResponse.TeachIn_NotSpecified; + teachIn = (payload[1] & UTEResponse.TEACHIN_MASK) == 0 + || (payload[1] & UTEResponse.TEACHIN_MASK) == UTEResponse.TEACHIN_NPTSPECIFIED; senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1); } break; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java index ad8dedab807..3f0e277b415 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java @@ -17,6 +17,7 @@ import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.ZERO; import java.security.InvalidParameterException; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.EnOceanException; import org.openhab.binding.enocean.internal.messages.BasePacket.ESPPacketType; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; @@ -25,6 +26,7 @@ import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class ESP2Packet { public static final byte ENOCEAN_ESP2_FIRSTSYNC_BYTE = (byte) 0xA5; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2PacketConverter.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2PacketConverter.java index 64a11def2ae..f74d0ddbd7d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2PacketConverter.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2PacketConverter.java @@ -15,6 +15,8 @@ package org.openhab.binding.enocean.internal.messages; import java.nio.charset.Charset; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.BasePacket.ESPPacketType; import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG; import org.openhab.binding.enocean.internal.messages.ESP2Packet.ESP2PacketType; @@ -27,6 +29,7 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class ESP2PacketConverter { protected static Logger logger = LoggerFactory.getLogger(ESP2PacketConverter.class); @@ -34,19 +37,19 @@ public class ESP2PacketConverter { private static final int ESP3PACKET_BASE_LENGTH = ESP3Packet.ESP3_RORG_LENGTH + ESP3Packet.ESP3_SENDERID_LENGTH + ESP3Packet.ESP3_STATUS_LENGTH; - private static BasePacket handleRadioTelegram(int dataLength, byte packetType, byte[] payload) { + private static @Nullable BasePacket handleRadioTelegram(int dataLength, byte packetType, byte[] payload) { switch (ESP2Packet.ORG.getORG(payload[1])) { case _RPS: - return ESP3PacketFactory.BuildPacket(ESP3PACKET_BASE_LENGTH + RORG.RPS.getDataLength(), 0, + return ESP3PacketFactory.buildPacket(ESP3PACKET_BASE_LENGTH + RORG.RPS.getDataLength(), 0, ESPPacketType.RADIO_ERP1.getValue(), new byte[] { RORG.RPS.getValue(), payload[2], payload[6], payload[7], payload[8], payload[9], payload[10] }); case _1BS: - return ESP3PacketFactory.BuildPacket(ESP3PACKET_BASE_LENGTH + RORG._1BS.getDataLength(), 0, + return ESP3PacketFactory.buildPacket(ESP3PACKET_BASE_LENGTH + RORG._1BS.getDataLength(), 0, ESPPacketType.RADIO_ERP1.getValue(), new byte[] { RORG._1BS.getValue(), payload[2], payload[6], payload[7], payload[8], payload[9], payload[10] }); case _4BS: - return ESP3PacketFactory.BuildPacket(ESP3PACKET_BASE_LENGTH + RORG._4BS.getDataLength(), 0, + return ESP3PacketFactory.buildPacket(ESP3PACKET_BASE_LENGTH + RORG._4BS.getDataLength(), 0, ESPPacketType.RADIO_ERP1.getValue(), new byte[] { RORG._4BS.getValue(), payload[2], payload[3], payload[4], payload[5], payload[6], payload[7], payload[8], payload[9], payload[10] }); default: @@ -55,13 +58,13 @@ public class ESP2PacketConverter { } } - private static BasePacket handleMessageTelegram(int dataLength, byte packetType, byte[] payload) { + private static @Nullable BasePacket handleMessageTelegram(int dataLength, byte packetType, byte[] payload) { switch (ESP2Packet.ESP2Response.getResponse(payload[1])) { case OK: - return ESP3PacketFactory.BuildPacket(1, 0, ESPPacketType.RESPONSE.getValue(), + return ESP3PacketFactory.buildPacket(1, 0, ESPPacketType.RESPONSE.getValue(), new byte[] { ResponseType.RET_OK.getValue() }); case ERR: - return ESP3PacketFactory.BuildPacket(1, 0, ESPPacketType.RESPONSE.getValue(), + return ESP3PacketFactory.buildPacket(1, 0, ESPPacketType.RESPONSE.getValue(), new byte[] { ResponseType.RET_ERROR.getValue() }); case INF_SW_VERSION: { byte[] data = new byte[33]; @@ -71,7 +74,7 @@ public class ESP2PacketConverter { byte[] description = "TCM 210".getBytes(Charset.forName("ASCII")); System.arraycopy(description, 0, data, 17, description.length); - return ESP3PacketFactory.BuildPacket(data.length, 0, ESPPacketType.RESPONSE.getValue(), data); + return ESP3PacketFactory.buildPacket(data.length, 0, ESPPacketType.RESPONSE.getValue(), data); } case UNKOWN: // try to interpret it as a radio telegram return handleRadioTelegram(dataLength, packetType, payload); @@ -95,7 +98,7 @@ public class ESP2PacketConverter { } } - public static BasePacket BuildPacket(int dataLength, byte packetType, byte[] payload) { + public static @Nullable BasePacket buildPacket(int dataLength, byte packetType, byte[] payload) { ESP2PacketType type = ESP2PacketType.getPacketType(packetType); switch (type) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java index fe1e62ee14a..b27a01f4109 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java @@ -12,15 +12,17 @@ */ package org.openhab.binding.enocean.internal.messages; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.EnOceanException; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class ESP3Packet { - private static byte[] crc8_table = new byte[] { (byte) 0x00, (byte) 0x07, (byte) 0x0e, (byte) 0x09, (byte) 0x1c, + private static byte[] crc8Table = new byte[] { (byte) 0x00, (byte) 0x07, (byte) 0x0e, (byte) 0x09, (byte) 0x1c, (byte) 0x1b, (byte) 0x12, (byte) 0x15, (byte) 0x38, (byte) 0x3f, (byte) 0x36, (byte) 0x31, (byte) 0x24, (byte) 0x23, (byte) 0x2a, (byte) 0x2d, (byte) 0x70, (byte) 0x77, (byte) 0x7e, (byte) 0x79, (byte) 0x6c, (byte) 0x6b, (byte) 0x62, (byte) 0x65, (byte) 0x48, (byte) 0x4f, (byte) 0x46, (byte) 0x41, (byte) 0x54, @@ -75,7 +77,7 @@ public class ESP3Packet { byte output = 0; for (int i = offset; i < offset + length; i++) { int index = (output ^ data[i]) & 0xff; - output = crc8_table[index]; + output = crc8Table[index]; } return (byte) (output & 0xff); } @@ -85,26 +87,24 @@ public class ESP3Packet { byte[] payload = basePacket.getPayload(); byte[] optionalPayload = basePacket.getOptionalPayload(); - int optionalLength = optionalPayload != null ? optionalPayload.length : 0; - byte[] result = new byte[ESP3_SYNC_BYTE_LENGTH + ESP3_HEADER_LENGTH + ESP3_CRC3_HEADER_LENGTH - + payload.length + optionalLength + ESP3_CRC8_DATA_LENGTH]; + + payload.length + optionalPayload.length + ESP3_CRC8_DATA_LENGTH]; result[0] = ESP3_SYNC_BYTE; result[1] = (byte) ((payload.length >> 8) & 0xff); result[2] = (byte) (payload.length & 0xff); - result[3] = (byte) (optionalLength & 0xff); + result[3] = (byte) (optionalPayload.length & 0xff); result[4] = basePacket.getPacketType().getValue(); result[5] = calcCRC8(result, ESP3_SYNC_BYTE_LENGTH, ESP3_HEADER_LENGTH); - for (int i = 0; i < payload.length; i++) { - result[6 + i] = payload[i]; + + System.arraycopy(payload, 0, result, 6, payload.length); + + for (int i = 0; i < optionalPayload.length; i++) { + result[6 + payload.length + i] = (byte) (optionalPayload[i] & 0xff); } - if (optionalPayload != null) { - for (int i = 0; i < optionalPayload.length; i++) { - result[6 + payload.length + i] = (byte) (optionalPayload[i] & 0xff); - } - } - result[6 + payload.length + optionalLength] = calcCRC8(result, 6, payload.length + optionalLength); + + result[6 + payload.length + optionalPayload.length] = calcCRC8(result, 6, + payload.length + optionalPayload.length); return result; } catch (Exception e) { @@ -116,7 +116,7 @@ public class ESP3Packet { byte output = 0; for (int i = 0; i < length; i++) { int index = (output ^ data[i]) & 0xff; - output = crc8_table[index]; + output = crc8Table[index]; } return output == crc8; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3PacketFactory.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3PacketFactory.java index 4fbf31a64ef..64287b61139 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3PacketFactory.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3PacketFactory.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.enocean.internal.messages; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanBindingConstants; import org.openhab.binding.enocean.internal.Helper; import org.openhab.binding.enocean.internal.messages.BasePacket.ESPPacketType; @@ -23,6 +25,7 @@ import org.openhab.core.library.types.StringType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class ESP3PacketFactory { public static final BasePacket CO_RD_VERSION = new CCMessage(CCMessageType.CO_RD_VERSION); @@ -66,7 +69,8 @@ public class ESP3PacketFactory { new byte[] { SAMessageType.SA_WR_CLIENTLEARNRQ.getValue(), manu1, manu2, rorg, func, type }); } - public static BasePacket BuildPacket(int dataLength, int optionalDataLength, byte packetType, byte[] payload) { + public static @Nullable BasePacket buildPacket(int dataLength, int optionalDataLength, byte packetType, + byte[] payload) { ESPPacketType type = ESPPacketType.getPacketType(packetType); switch (type) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/EventMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/EventMessage.java index 7f5bb514eca..3027b2131d6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/EventMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/EventMessage.java @@ -14,10 +14,13 @@ package org.openhab.binding.enocean.internal.messages; import java.util.stream.Stream; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EventMessage extends BasePacket { public enum EventMessageType { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Response.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Response.java index 649b071d683..cc9e300935c 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Response.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Response.java @@ -14,10 +14,13 @@ package org.openhab.binding.enocean.internal.messages; import java.security.InvalidParameterException; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class Response extends BasePacket { public enum ResponseType { @@ -55,7 +58,7 @@ public class Response extends BasePacket { } protected ResponseType responseType; - protected boolean _isValid = false; + protected boolean isValid = false; public Response(int dataLength, int optionalDataLength, byte[] payload) { super(dataLength, optionalDataLength, ESPPacketType.RESPONSE, payload); @@ -76,6 +79,6 @@ public class Response extends BasePacket { } public boolean isValid() { - return _isValid; + return isValid; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java index 3df820feb78..e1aa3642c12 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java @@ -10,8 +10,9 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.messages.Responses; +package org.openhab.binding.enocean.internal.messages.responses; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.Helper; import org.openhab.binding.enocean.internal.messages.Response; @@ -19,6 +20,7 @@ import org.openhab.binding.enocean.internal.messages.Response; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class BaseResponse extends Response { public BaseResponse(Response response) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java index 8b2c9543aab..c00672a8977 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java @@ -10,8 +10,9 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.messages.Responses; +package org.openhab.binding.enocean.internal.messages.responses; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.Helper; import org.openhab.binding.enocean.internal.messages.Response; @@ -19,9 +20,10 @@ import org.openhab.binding.enocean.internal.messages.Response; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class RDBaseIdResponse extends Response { - private byte[] baseId = null; + private byte[] baseId = new byte[0]; private int remainingWriteCycles = 0; public RDBaseIdResponse(Response response) { @@ -32,14 +34,14 @@ public class RDBaseIdResponse extends Response { RDBaseIdResponse(int dataLength, int optionalDataLength, byte[] payload) { super(dataLength, optionalDataLength, payload); - if (this.data == null || this.data.length != 5 || this.optionalData == null || this.optionalData.length != 1) { + if (this.data.length != 5 || this.optionalData.length != 1) { return; } baseId = getPayload(1, 4); remainingWriteCycles = optionalData[0] & 0xFF; - _isValid = true; + isValid = true; } public final byte[] getBaseId() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java index 8c8671a65bc..6c114878e81 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java @@ -10,10 +10,11 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.messages.Responses; +package org.openhab.binding.enocean.internal.messages.responses; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.Helper; import org.openhab.binding.enocean.internal.messages.Response; @@ -21,15 +22,16 @@ import org.openhab.binding.enocean.internal.messages.Response; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class RDLearnedClientsResponse extends Response { public class LearnedClient { - public byte[] clientId; - public byte[] controllerId; + public byte[] clientId = new byte[0]; + public byte[] controllerId = new byte[0]; public int mailboxIndex; } - LearnedClient[] learnedClients; + LearnedClient[] learnedClients = new LearnedClient[0]; public RDLearnedClientsResponse(Response response) { this(response.getPayload().length, response.getOptionalPayload().length, @@ -39,10 +41,10 @@ public class RDLearnedClientsResponse extends Response { RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) { super(dataLength, optionalDataLength, payload); - if (payload == null || ((payload.length - 1) % 9) != 0) { + if (payload.length == 0 || (payload.length - 1) % 9 != 0) { return; } else { - _isValid = true; + isValid = true; } learnedClients = new LearnedClient[(payload.length - 1) / 9]; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java index 953644f3448..d61ab7bfee6 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java @@ -10,11 +10,11 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.messages.Responses; +package org.openhab.binding.enocean.internal.messages.responses; import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.Response; import org.openhab.core.library.types.StringType; @@ -22,9 +22,10 @@ import org.openhab.core.library.types.StringType; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class RDRepeaterResponse extends Response { - protected String repeaterLevel; + protected String repeaterLevel = ""; public RDRepeaterResponse(Response response) { this(response.getPayload().length, 0, response.getPayload()); @@ -33,7 +34,7 @@ public class RDRepeaterResponse extends Response { RDRepeaterResponse(int dataLength, int optionalDataLength, byte[] payload) { super(dataLength, optionalDataLength, payload); - if (payload == null || payload.length < 3) { + if (payload.length < 3) { return; } @@ -54,11 +55,10 @@ public class RDRepeaterResponse extends Response { return; } - _isValid = true; + isValid = true; } } - @NonNull public StringType getRepeaterLevel() { return StringType.valueOf(repeaterLevel); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java index 2808093fe23..e041586aaf3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java @@ -10,11 +10,11 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.messages.Responses; +package org.openhab.binding.enocean.internal.messages.responses; import java.util.Arrays; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.Response; import org.openhab.core.util.HexUtils; @@ -22,6 +22,7 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class RDVersionResponse extends Response { protected String appVersion = ""; @@ -53,29 +54,25 @@ public class RDVersionResponse extends Response { sb.append((char) (payload[i] & 0xff)); } description = sb.toString(); - _isValid = true; + isValid = true; } catch (Exception e) { responseType = ResponseType.RET_ERROR; } } - @NonNull public String getAPPVersion() { return appVersion; } - @NonNull public String getAPIVersion() { return apiVersion; } - @NonNull public String getChipID() { return chipId; } - @NonNull public String getDescription() { return description; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java index d265b7b4391..b09dc582899 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java @@ -10,14 +10,16 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.enocean.internal.messages.Responses; +package org.openhab.binding.enocean.internal.messages.responses; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.Response; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class SMACKTeachInResponse extends Response { // set response time to 250ms diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/SAMessage.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/SAMessage.java index a1ebce44a21..9aee034f274 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/SAMessage.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/SAMessage.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.messages; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class SAMessage extends BasePacket { public enum SAMessageType { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/EnOceanProfileFactory.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/EnOceanProfileFactory.java index f1de2cde08e..76da602ed75 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/EnOceanProfileFactory.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/EnOceanProfileFactory.java @@ -78,7 +78,6 @@ public class EnOceanProfileFactory implements ProfileFactory, ProfileAdvisor, Pr @Override public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) { - if (CHANNELTYPE_ROCKERSWITCH_ACTION_UID.equals(channelType.getUID())) { if (CoreItemFactory.PLAYER.equalsIgnoreCase(itemType)) { return ROCKERSWITCHACTION_TOGGLE_PLAYER; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/RockerSwitchActionBaseProfile.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/RockerSwitchActionBaseProfile.java index 8584d50956c..69b942b668f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/RockerSwitchActionBaseProfile.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/profiles/RockerSwitchActionBaseProfile.java @@ -31,7 +31,7 @@ public abstract class RockerSwitchActionBaseProfile implements TriggerProfile { protected @Nullable State previousState; - final String ANYDIR = "*"; + protected static final String ANY_DIR = "*"; public RockerSwitchActionBaseProfile(ProfileCallback callback, ProfileContext context) { this.callback = callback; @@ -46,9 +46,9 @@ public abstract class RockerSwitchActionBaseProfile implements TriggerProfile { EnOceanProfileRockerSwitchActionConfig config = context.getConfiguration() .as(EnOceanProfileRockerSwitchActionConfig.class); - if (!(config.channelAFilter.equals(ANYDIR) || config.channelAFilter.equals(directions[0]))) { + if (!(config.channelAFilter.equals(ANY_DIR) || config.channelAFilter.equals(directions[0]))) { return false; - } else if (!(config.channelBFilter.equals(ANYDIR) || config.channelBFilter.equals(directions[1]))) { + } else if (!(config.channelBFilter.equals(ANY_DIR) || config.channelBFilter.equals(directions[1]))) { return false; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP2Transceiver.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP2Transceiver.java index 179d7aa2937..d7e9681f798 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP2Transceiver.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP2Transceiver.java @@ -13,9 +13,13 @@ package org.openhab.binding.enocean.internal.transceiver; import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanException; import org.openhab.binding.enocean.internal.messages.BasePacket; import org.openhab.binding.enocean.internal.messages.ERP1Message; @@ -30,10 +34,11 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanESP2Transceiver extends EnOceanTransceiver { public EnOceanESP2Transceiver(String path, TransceiverErrorListener errorListener, - ScheduledExecutorService scheduler, SerialPortManager serialPortManager) { + ScheduledExecutorService scheduler, @Nullable SerialPortManager serialPortManager) { super(path, errorListener, scheduler, serialPortManager); } @@ -54,33 +59,37 @@ public class EnOceanESP2Transceiver extends EnOceanTransceiver { protected void processMessage(byte firstByte) { byte[] readingBuffer = new byte[ENOCEAN_MAX_DATA]; int bytesRead = -1; - byte _byte; + byte byteBuffer; try { readingBuffer[0] = firstByte; - - bytesRead = this.inputStream.read(readingBuffer, 1, inputStream.available()); + InputStream localInputStream = inputStream; + if (localInputStream == null) { + throw new IOException("could not read from inputstream, it was null"); + } + bytesRead = localInputStream.read(readingBuffer, 1, localInputStream.available()); if (bytesRead == -1) { throw new IOException("could not read from inputstream"); } - if (readingTask == null || readingTask.isCancelled()) { + Future localReadingTask = readingTask; + if (localReadingTask == null || localReadingTask.isCancelled()) { return; } bytesRead++; for (int p = 0; p < bytesRead; p++) { - _byte = readingBuffer[p]; + byteBuffer = readingBuffer[p]; switch (state) { case WaitingForFirstSyncByte: - if (_byte == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE) { + if (byteBuffer == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE) { state = ReadingState.WaitingForSecondSyncByte; logger.trace("Received First Sync Byte"); } break; case WaitingForSecondSyncByte: - if (_byte == ESP2Packet.ENOCEAN_ESP2_SECONDSYNC_BYTE) { + if (byteBuffer == ESP2Packet.ENOCEAN_ESP2_SECONDSYNC_BYTE) { state = ReadingState.ReadingHeader; logger.trace("Received Second Sync Byte"); } @@ -89,7 +98,7 @@ public class EnOceanESP2Transceiver extends EnOceanTransceiver { state = ReadingState.ReadingData; currentPosition = 0; - dataBuffer[currentPosition++] = _byte; + dataBuffer[currentPosition++] = byteBuffer; dataLength = ((dataBuffer[0] & 0xFF) & 0b11111); packetType = (byte) ((dataBuffer[0] & 0xFF) >> 5); @@ -98,8 +107,8 @@ public class EnOceanESP2Transceiver extends EnOceanTransceiver { break; case ReadingData: if (currentPosition == dataLength) { - if (ESP2Packet.validateCheckSum(dataBuffer, dataLength, _byte)) { - BasePacket packet = ESP2PacketConverter.BuildPacket(dataLength, packetType, dataBuffer); + if (ESP2Packet.validateCheckSum(dataBuffer, dataLength, byteBuffer)) { + BasePacket packet = ESP2PacketConverter.buildPacket(dataLength, packetType, dataBuffer); if (packet != null) { switch (packet.getPacketType()) { case RADIO_ERP1: { @@ -128,30 +137,33 @@ public class EnOceanESP2Transceiver extends EnOceanTransceiver { } } else { if (dataBuffer[1] != (byte) 0xFC) { - logger.debug("Unknown/unsupported ESP2Packet: {}", - HexUtils.bytesToHex(Arrays.copyOf(dataBuffer, dataLength))); + byte[] array = Arrays.copyOf(dataBuffer, dataLength); + String packetString = array != null ? HexUtils.bytesToHex(array) : ""; + logger.debug("Unknown/unsupported ESP2Packet: {}", packetString); } } } else { logger.debug("ESP2Packet malformed: {}", HexUtils.bytesToHex(dataBuffer)); } - state = _byte == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE + state = byteBuffer == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE ? ReadingState.WaitingForSecondSyncByte : ReadingState.WaitingForFirstSyncByte; currentPosition = 0; dataLength = packetType = -1; } else { - dataBuffer[currentPosition++] = _byte; + dataBuffer[currentPosition++] = byteBuffer; } break; } } - } catch ( - - IOException ioexception) { - errorListener.ErrorOccured(ioexception); + } catch (IOException ioexception) { + logger.trace("Unable to process message", ioexception); + TransceiverErrorListener localListener = errorListener; + if (localListener != null) { + localListener.errorOccured(ioexception); + } return; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP3Transceiver.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP3Transceiver.java index a8713e7ec56..e9e350976c3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP3Transceiver.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanESP3Transceiver.java @@ -13,9 +13,13 @@ package org.openhab.binding.enocean.internal.transceiver; import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanException; import org.openhab.binding.enocean.internal.messages.BasePacket; import org.openhab.binding.enocean.internal.messages.ESP3Packet; @@ -28,10 +32,11 @@ import org.openhab.core.util.HexUtils; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public class EnOceanESP3Transceiver extends EnOceanTransceiver { public EnOceanESP3Transceiver(String path, TransceiverErrorListener errorListener, - ScheduledExecutorService scheduler, SerialPortManager serialPortManager) { + ScheduledExecutorService scheduler, @Nullable SerialPortManager serialPortManager) { super(path, errorListener, scheduler, serialPortManager); } @@ -52,34 +57,38 @@ public class EnOceanESP3Transceiver extends EnOceanTransceiver { protected void processMessage(byte firstByte) { byte[] readingBuffer = new byte[ENOCEAN_MAX_DATA]; int bytesRead = -1; - byte _byte; + byte byteBuffer; try { readingBuffer[0] = firstByte; - - bytesRead = this.inputStream.read(readingBuffer, 1, inputStream.available()); + InputStream localInPutStream = this.inputStream; + if (localInPutStream == null) { + throw new IOException("could not read from inputstream"); + } + bytesRead = localInPutStream.read(readingBuffer, 1, localInPutStream.available()); if (bytesRead == -1) { throw new IOException("could not read from inputstream"); } - if (readingTask == null || readingTask.isCancelled()) { + Future localReadingTask = readingTask; + if (localReadingTask == null || localReadingTask.isCancelled()) { return; } bytesRead++; for (int p = 0; p < bytesRead; p++) { - _byte = readingBuffer[p]; + byteBuffer = readingBuffer[p]; switch (state) { case WaitingForSyncByte: - if (_byte == ESP3Packet.ESP3_SYNC_BYTE) { + if (byteBuffer == ESP3Packet.ESP3_SYNC_BYTE) { state = ReadingState.ReadingHeader; logger.trace("Received Sync Byte"); } break; case ReadingHeader: if (currentPosition == ESP3Packet.ESP3_HEADER_LENGTH) { - if (ESP3Packet.checkCRC8(dataBuffer, ESP3Packet.ESP3_HEADER_LENGTH, _byte) + if (ESP3Packet.checkCRC8(dataBuffer, ESP3Packet.ESP3_HEADER_LENGTH, byteBuffer) && ((dataBuffer[0] & 0xFF) << 8) + (dataBuffer[1] & 0xFF) + (dataBuffer[2] & 0xFF) > 0) { state = ReadingState.ReadingData; @@ -110,23 +119,23 @@ public class EnOceanESP3Transceiver extends EnOceanTransceiver { ESP3Packet.ESP3_HEADER_LENGTH - copyFrom); state = ReadingState.ReadingHeader; currentPosition = ESP3Packet.ESP3_HEADER_LENGTH - copyFrom; - dataBuffer[currentPosition++] = _byte; + dataBuffer[currentPosition++] = byteBuffer; } else { currentPosition = 0; - state = _byte == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader + state = byteBuffer == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader : ReadingState.WaitingForSyncByte; } logger.trace("CrC8 header check not successful"); } } else { - dataBuffer[currentPosition++] = _byte; + dataBuffer[currentPosition++] = byteBuffer; } break; case ReadingData: if (currentPosition == dataLength + optionalLength) { - if (ESP3Packet.checkCRC8(dataBuffer, dataLength + optionalLength, _byte)) { + if (ESP3Packet.checkCRC8(dataBuffer, dataLength + optionalLength, byteBuffer)) { state = ReadingState.WaitingForSyncByte; - BasePacket packet = ESP3PacketFactory.BuildPacket(dataLength, optionalLength, + BasePacket packet = ESP3PacketFactory.buildPacket(dataLength, optionalLength, packetType, dataBuffer); if (packet != null) { @@ -166,7 +175,7 @@ public class EnOceanESP3Transceiver extends EnOceanTransceiver { .bytesToHex(Arrays.copyOf(dataBuffer, dataLength + optionalLength))); } } else { - state = _byte == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader + state = byteBuffer == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader : ReadingState.WaitingForSyncByte; logger.trace("ESP3Packet malformed: {}", HexUtils.bytesToHex(Arrays.copyOf(dataBuffer, dataLength + optionalLength))); @@ -175,13 +184,17 @@ public class EnOceanESP3Transceiver extends EnOceanTransceiver { currentPosition = 0; dataLength = optionalLength = packetType = -1; } else { - dataBuffer[currentPosition++] = _byte; + dataBuffer[currentPosition++] = byteBuffer; } break; } } } catch (IOException ioexception) { - errorListener.ErrorOccured(ioexception); + logger.trace("Unable to process message", ioexception); + TransceiverErrorListener localListener = errorListener; + if (localListener != null) { + localListener.errorOccured(ioexception); + } return; } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java index 6fac447240d..298d1b1f061 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java @@ -25,6 +25,8 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanBindingConstants; import org.openhab.binding.enocean.internal.EnOceanException; import org.openhab.binding.enocean.internal.Helper; @@ -50,26 +52,29 @@ import org.slf4j.LoggerFactory; * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public abstract class EnOceanTransceiver implements SerialPortEventListener { public static final int ENOCEAN_MAX_DATA = 65790; // Thread management - protected Future readingTask = null; - private Future timeOut = null; + protected @Nullable Future readingTask = null; + private @Nullable Future timeOut = null; protected Logger logger = LoggerFactory.getLogger(EnOceanTransceiver.class); - private SerialPortManager serialPortManager; + private @Nullable SerialPortManager serialPortManager; private static final int ENOCEAN_DEFAULT_BAUD = 57600; protected String path; - SerialPort serialPort; + private @Nullable SerialPort serialPort; class Request { - BasePacket RequestPacket; - - Response ResponsePacket; - ResponseListener ResponseListener; + @Nullable + BasePacket requestPacket; + @Nullable + Response responsePacket; + @Nullable + ResponseListener responseListener; } private class RequestQueue { @@ -101,32 +106,41 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { if (!queue.isEmpty()) { currentRequest = queue.peek(); try { - if (currentRequest != null && currentRequest.RequestPacket != null) { - synchronized (currentRequest) { - logger.debug("Sending data, type {}, payload {}{}", - currentRequest.RequestPacket.getPacketType().name(), - HexUtils.bytesToHex(currentRequest.RequestPacket.getPayload()), - HexUtils.bytesToHex(currentRequest.RequestPacket.getOptionalPayload())); - - byte[] b = serializePacket(currentRequest.RequestPacket); - logger.trace("Sending raw data: {}", HexUtils.bytesToHex(b)); - outputStream.write(b); - outputStream.flush(); - - if (timeOut != null) { - timeOut.cancel(true); - } - - // slowdown sending of message to avoid hickups at receivers - // Todo tweak sending intervall (250 ist just a first try) - timeOut = scheduler.schedule(() -> { - try { - sendNext(); - } catch (IOException e) { - errorListener.ErrorOccured(e); - return; + Request localCurrentRequest = currentRequest; + if (localCurrentRequest != null && localCurrentRequest.requestPacket != null) { + synchronized (localCurrentRequest) { + BasePacket rqPacket = localCurrentRequest.requestPacket; + if (currentRequest != null && rqPacket != null) { + logger.debug("Sending data, type {}, payload {}{}", rqPacket.getPacketType().name(), + HexUtils.bytesToHex(rqPacket.getPayload()), + HexUtils.bytesToHex(rqPacket.getOptionalPayload())); + byte[] b = serializePacket(rqPacket); + logger.trace("Sending raw data: {}", HexUtils.bytesToHex(b)); + OutputStream localOutPutStream = outputStream; + if (localOutPutStream != null) { + localOutPutStream.write(b); + localOutPutStream.flush(); } - }, 250, TimeUnit.MILLISECONDS); + Future localTimeOut = timeOut; + if (localTimeOut != null) { + localTimeOut.cancel(true); + } + + // slowdown sending of message to avoid hickups at receivers + // Todo tweak sending intervall (250 ist just a first try) + timeOut = scheduler.schedule(() -> { + try { + sendNext(); + } catch (IOException e) { + logger.trace("Unable to process message", e); + TransceiverErrorListener localListener = errorListener; + if (localListener != null) { + localListener.errorOccured(e); + } + return; + } + }, 250, TimeUnit.MILLISECONDS); + } } } else { sendNext(); @@ -139,20 +153,22 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { } RequestQueue requestQueue; + @Nullable Request currentRequest = null; protected Map> listeners; protected HashSet eventListeners; - protected TeachInListener teachInListener; + protected @Nullable TeachInListener teachInListener; - protected InputStream inputStream; - protected OutputStream outputStream; + protected @Nullable InputStream inputStream; + protected @Nullable OutputStream outputStream; - private byte[] filteredDeviceId; + private byte[] filteredDeviceId = new byte[0]; + @Nullable TransceiverErrorListener errorListener; public EnOceanTransceiver(String path, TransceiverErrorListener errorListener, ScheduledExecutorService scheduler, - SerialPortManager serialPortManager) { + @Nullable SerialPortManager serialPortManager) { requestQueue = new RequestQueue(scheduler); listeners = new HashMap<>(); @@ -164,34 +180,51 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { this.path = path; } - public void Initialize() + public void initilize() throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException { - SerialPortIdentifier id = serialPortManager.getIdentifier(path); + SerialPortManager localSerialPortManager = serialPortManager; + if (localSerialPortManager == null) { + throw new IOException("Could access the SerialPortManager, it was null"); + } + SerialPortIdentifier id = localSerialPortManager.getIdentifier(path); if (id == null) { throw new IOException("Could not find a gateway on given path '" + path + "', " - + serialPortManager.getIdentifiers().count() + " ports available."); + + localSerialPortManager.getIdentifiers().count() + " ports available."); } - serialPort = id.open(EnOceanBindingConstants.BINDING_ID, 1000); - serialPort.setSerialPortParams(ENOCEAN_DEFAULT_BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, + try { + serialPort = id.open(EnOceanBindingConstants.BINDING_ID, 1000); + } catch (PortInUseException e) { + logger.warn("EnOceanSerialTransceiver not initialized, port allready in use", e); + return; + } + SerialPort localSerialPort = serialPort; + if (localSerialPort == null) { + logger.debug("EnOceanSerialTransceiver not initialized, serialPort was null"); + return; + } + localSerialPort.setSerialPortParams(ENOCEAN_DEFAULT_BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); try { - serialPort.enableReceiveThreshold(1); - serialPort.enableReceiveTimeout(100); // In ms. Small values mean faster shutdown but more cpu usage. + localSerialPort.enableReceiveThreshold(1); + localSerialPort.enableReceiveTimeout(100); // In ms. Small values mean faster shutdown but more cpu usage. } catch (UnsupportedCommOperationException e) { // rfc connections do not allow a ReceiveThreshold + logger.debug("EnOceanSerialTransceiver encountered an UnsupportedCommOperationException while initilizing", + e); } - inputStream = serialPort.getInputStream(); - outputStream = serialPort.getOutputStream(); - + inputStream = localSerialPort.getInputStream(); + outputStream = localSerialPort.getOutputStream(); logger.info("EnOceanSerialTransceiver initialized"); } - public void StartReceiving(ScheduledExecutorService scheduler) { - if (readingTask == null || readingTask.isCancelled()) { - readingTask = scheduler.submit(new Runnable() { + public void startReceiving(ScheduledExecutorService scheduler) { + @Nullable + Future localReadingTask = readingTask; + if (localReadingTask == null || localReadingTask.isCancelled()) { + localReadingTask = scheduler.submit(new Runnable() { @Override public void run() { receivePackets(); @@ -201,19 +234,26 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { logger.info("EnOceanSerialTransceiver RX thread started"); } - public void ShutDown() { + public void shutDown() { logger.debug("shutting down transceiver"); logger.debug("Interrupt rx Thread"); - if (timeOut != null) { - timeOut.cancel(true); + Future localTimeOut = timeOut; + if (localTimeOut != null) { + localTimeOut.cancel(true); } - if (readingTask != null) { - readingTask.cancel(true); - try { - inputStream.close(); - } catch (Exception e) { + Future localReadingTask = readingTask; + if (localReadingTask != null) { + localReadingTask.cancel(true); + + InputStream localInputStream = inputStream; + if (localInputStream != null) { + try { + localInputStream.close(); + } catch (IOException e) { + logger.debug("IOException occured while closing the stream", e); + } } } @@ -224,26 +264,28 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { teachInListener = null; errorListener = null; - if (outputStream != null) { - logger.debug("Closing serial output stream"); + OutputStream localOutputStream = outputStream; + if (localOutputStream != null) { try { - outputStream.close(); + localOutputStream.close(); } catch (IOException e) { - logger.debug("Error while closing the output stream: {}", e.getMessage()); - } - } - if (inputStream != null) { - logger.debug("Closeing serial input stream"); - try { - inputStream.close(); - } catch (IOException e) { - logger.debug("Error while closing the input stream: {}", e.getMessage()); + logger.debug("IOException occured while closing the output stream", e); } } - if (serialPort != null) { - logger.debug("Closing serial port"); - serialPort.close(); + InputStream localInputStream = inputStream; + if (localInputStream != null) { + try { + localInputStream.close(); + } catch (IOException e) { + logger.debug("IOException occured while closing the input stream", e); + } + } + + SerialPort localSerialPort = serialPort; + if (localSerialPort != null) { + logger.debug("Closing the serial port"); + localSerialPort.close(); } serialPort = null; @@ -256,7 +298,8 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { private void receivePackets() { byte[] buffer = new byte[1]; - while (readingTask != null && !readingTask.isCancelled()) { + Future localReadingTask = readingTask; + while (localReadingTask != null && !localReadingTask.isCancelled()) { int bytesRead = read(buffer, 1); if (bytesRead > 0) { processMessage(buffer[0]); @@ -267,11 +310,16 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { protected abstract void processMessage(byte firstByte); protected int read(byte[] buffer, int length) { - try { - return this.inputStream.read(buffer, 0, length); - } catch (IOException e) { - return 0; + InputStream localInputStream = inputStream; + if (localInputStream != null) { + try { + localInputStream.read(buffer, 0, length); + } catch (IOException e) { + logger.debug("IOException occured while reading the input stream", e); + return 0; + } } + return 0; } protected void informListeners(BasePacket packet) { @@ -285,8 +333,8 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { msg.getRORG().name(), HexUtils.bytesToHex(msg.getSenderId()), HexUtils.bytesToHex(d)); if (msg.getRORG() != RORG.Unknown) { - if (senderId != null) { - if (filteredDeviceId != null && senderId[0] == filteredDeviceId[0] + if (senderId.length > 0) { + if (senderId.length > 2 && filteredDeviceId.length > 2 && senderId[0] == filteredDeviceId[0] && senderId[1] == filteredDeviceId[1] && senderId[2] == filteredDeviceId[2]) { // filter away own messages which are received through a repeater return; @@ -294,7 +342,11 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { if (teachInListener != null && (msg.getIsTeachIn() || msg.getRORG() == RORG.RPS)) { logger.info("Received teach in message from {}", HexUtils.bytesToHex(msg.getSenderId())); - teachInListener.packetReceived(msg); + + TeachInListener localListener = teachInListener; + if (localListener != null) { + localListener.packetReceived(msg); + } return; } else if (teachInListener == null && msg.getIsTeachIn()) { logger.info("Discard message because this is a teach-in telegram from {}!", @@ -325,7 +377,10 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { if (teachInListener != null) { logger.info("Received smart teach in from {}", HexUtils.bytesToHex(senderId)); - teachInListener.eventReceived(event); + TeachInListener localListener = teachInListener; + if (localListener != null) { + localListener.eventReceived(event); + } return; } else { logger.info("Discard message because this is a smart teach-in telegram from {}!", @@ -344,11 +399,13 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { } protected void handleResponse(Response response) throws IOException { - if (currentRequest != null) { - if (currentRequest.ResponseListener != null) { - currentRequest.ResponsePacket = response; + Request localCurrentRequest = currentRequest; + if (localCurrentRequest != null) { + ResponseListener listener = localCurrentRequest.responseListener; + if (listener != null) { + localCurrentRequest.responsePacket = response; try { - currentRequest.ResponseListener.handleResponse(response); + listener.handleResponse(response); } catch (Exception e) { logger.debug("Exception during response handling"); } finally { @@ -362,8 +419,8 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { } } - public void sendBasePacket(BasePacket packet, ResponseListener responseCallback) - throws IOException { + public void sendBasePacket(@Nullable BasePacket packet, + @Nullable ResponseListener responseCallback) throws IOException { if (packet == null) { return; } @@ -371,8 +428,8 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { logger.debug("Enqueue new send request with ESP3 type {} {} callback", packet.getPacketType().name(), responseCallback == null ? "without" : "with"); Request r = new Request(); - r.RequestPacket = packet; - r.ResponseListener = responseCallback; + r.requestPacket = packet; + r.responseListener = responseCallback; requestQueue.enqueRequest(r); } @@ -412,9 +469,7 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener { } public void setFilteredDeviceId(byte[] filteredDeviceId) { - if (filteredDeviceId != null) { - System.arraycopy(filteredDeviceId, 0, filteredDeviceId, 0, filteredDeviceId.length); - } + System.arraycopy(filteredDeviceId, 0, filteredDeviceId, 0, filteredDeviceId.length); } @Override diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EventListener.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EventListener.java index 99fbb4cf2a4..213b9d51246 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EventListener.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EventListener.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.transceiver; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.EventMessage; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public interface EventListener { public void eventReceived(EventMessage event); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/PacketListener.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/PacketListener.java index 32783ff1b3e..94caf5c9cd4 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/PacketListener.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/PacketListener.java @@ -12,12 +12,14 @@ */ package org.openhab.binding.enocean.internal.transceiver; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.enocean.internal.messages.BasePacket; /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public interface PacketListener { public void packetReceived(BasePacket packet); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListener.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListener.java index 1cf7ec73bd3..9ff933aacca 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListener.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListener.java @@ -14,6 +14,8 @@ package org.openhab.binding.enocean.internal.transceiver; import java.lang.reflect.ParameterizedType; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.EnOceanException; import org.openhab.binding.enocean.internal.messages.Response; @@ -21,11 +23,12 @@ import org.openhab.binding.enocean.internal.messages.Response; * * @author Daniel Weber - Initial contribution */ -public abstract class ResponseListener { +@NonNullByDefault +public abstract class ResponseListener { protected Class persistentClass; - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "null" }) public ResponseListener() { this.persistentClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()) .getActualTypeArguments()[0]; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListenerIgnoringTimeouts.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListenerIgnoringTimeouts.java index c74c3611d1a..314efc7a0cb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListenerIgnoringTimeouts.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/ResponseListenerIgnoringTimeouts.java @@ -14,15 +14,18 @@ package org.openhab.binding.enocean.internal.transceiver; import java.lang.reflect.ParameterizedType; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.enocean.internal.messages.Response; /** * * @author Daniel Weber - Initial contribution */ -public abstract class ResponseListenerIgnoringTimeouts extends ResponseListener { +@NonNullByDefault +public abstract class ResponseListenerIgnoringTimeouts extends ResponseListener { - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "null" }) public ResponseListenerIgnoringTimeouts() { this.persistentClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()) .getActualTypeArguments()[0]; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TeachInListener.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TeachInListener.java index 972995fbdc6..e87cec7f6a3 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TeachInListener.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TeachInListener.java @@ -12,10 +12,13 @@ */ package org.openhab.binding.enocean.internal.transceiver; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public interface TeachInListener extends PacketListener, EventListener { } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TransceiverErrorListener.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TransceiverErrorListener.java index b2191d2ce0e..99b6f452b91 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TransceiverErrorListener.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/TransceiverErrorListener.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.enocean.internal.transceiver; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * * @author Daniel Weber - Initial contribution */ +@NonNullByDefault public interface TransceiverErrorListener { - public void ErrorOccured(Throwable exception); + public void errorOccured(Throwable exception); }