Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enocean] Add null annotations #14023

Merged
merged 23 commits into from Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Expand Up @@ -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;

/**
Expand All @@ -21,10 +22,10 @@
* 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;
Expand All @@ -49,15 +50,11 @@ public EnOceanChannelDescription(ChannelTypeUID channelTypeUID, String itemType)
* @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;
Expand Down
Expand Up @@ -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"),
Expand Down
Expand Up @@ -12,18 +12,22 @@
*/
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 {

/**
*
*/
private static final long serialVersionUID = 1L;

public EnOceanException(String msg) {
public EnOceanException(@Nullable String msg) {
super(msg);
}
}
Expand Up @@ -19,6 +19,8 @@
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;
Expand All @@ -36,6 +38,7 @@
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;

Expand All @@ -45,6 +48,7 @@
*
* @author Daniel Weber - Initial contribution
*/
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.enocean")
public class EnOceanHandlerFactory extends BaseThingHandlerFactory {

Expand All @@ -55,24 +59,28 @@ public class EnOceanHandlerFactory extends BaseThingHandlerFactory {

private Map<ThingUID, ServiceRegistration<?>> 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) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}

@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);
Expand All @@ -90,12 +98,10 @@ protected ThingHandler createHandler(Thing thing) {

@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());
}
}

Expand Down
Expand Up @@ -14,14 +14,17 @@

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;
}

Expand All @@ -40,7 +43,7 @@ public static byte[] concatAll(byte[] a, byte[]... rest) {
offset += array.length;
}
}
return result;
return result != null ? result : new byte[0];
}

public static int tryParseInt(String value, int defaultValue) {
Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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 {
Expand All @@ -40,24 +44,17 @@ public static ESPVersion getESPVersion(String espVersion) {
}
}

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);
}
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -14,10 +14,14 @@

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;
Expand All @@ -39,7 +43,7 @@ public String getValue() {
return value;
}

public static SwitchMode getSwitchMode(String value) {
public static SwitchMode getSwitchMode(@Nullable String value) {
if (value == null) {
return SwitchMode.Unkown;
}
Expand All @@ -65,7 +69,7 @@ public enum Channel {
this.value = value;
}

public static Channel getChannel(String value) {
public static Channel getChannel(@Nullable String value) {
if (value == null) {
return Channel.Unkown;
}
Expand Down
Expand Up @@ -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;
}
}
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
}