[enocean] Fix unusable bundle after a refactoring about null annotation (#15302)

Fix bundle unusable after #14023 (closes #15181)
Fix a case issue with some directory
Fix trigger channel issue

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
This commit is contained in:
Gwendal Roulleau 2023-07-26 13:21:59 +02:00 committed by Jacob Laursen
parent fdb10451ec
commit 8f5fab45fa
17 changed files with 33 additions and 25 deletions

View File

@ -49,7 +49,7 @@ public class A5_20_04 extends A5_20 {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
switch (channelId) {
case CHANNEL_STATUS_REQUEST_EVENT:

View File

@ -48,7 +48,7 @@ public class D2_03_0A extends _VLDMessage {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
switch (channelId) {
case CHANNEL_PUSHBUTTON:

View File

@ -164,7 +164,7 @@ public class D2_06_01 extends _VLDMessage {
}
protected State getTemperature() {
double unscaledTemp = (double) (bytes[5] & 0xFF);
double unscaledTemp = bytes[5] & 0xFF;
if (unscaledTemp <= 250) {
double scaledTemp = unscaledTemp * 0.32 - 20;
return new QuantityType<>(scaledTemp, SIUnits.CELSIUS);
@ -198,7 +198,7 @@ public class D2_06_01 extends _VLDMessage {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
// Sensor values
if (bytes[0] == MessageType.SENSORVALUES.getIntValue()) {

View File

@ -115,7 +115,7 @@ public class D2_06_50 extends _VLDMessage {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
// Alarm
if (bytes[0] == 0x02) {

View File

@ -114,7 +114,7 @@ public abstract class EEP {
return convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);
}
public @Nullable String convertToEvent(String channelId, String channelTypeId, String lastEvent,
public @Nullable String convertToEvent(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
if (!getEEPType().isChannelSupported(channelId, channelTypeId)) {
throw new IllegalArgumentException(
@ -223,7 +223,7 @@ public abstract class EEP {
return UnDefType.UNDEF;
}
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
return null;
}

View File

@ -35,7 +35,7 @@ public class F6_01_01 extends _RPSMessage {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
return getBit(bytes[0], 4) ? CommonTriggerEvents.PRESSED : CommonTriggerEvents.RELEASED;
}

View File

@ -45,7 +45,7 @@ public class F6_02_01 extends F6_02 {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
if (t21 && nu) {
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
@ -59,7 +59,7 @@ public class F6_02_01 extends F6_02 {
} else if (t21 && !nu) {
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
return CommonTriggerEvents.RELEASED;
} else {
} else if (lastEvent != null) {
if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
return CommonTriggerEvents.DIR1_RELEASED;
} else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {

View File

@ -45,7 +45,7 @@ public class F6_02_02 extends F6_02 {
}
@Override
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
Configuration config) {
if (t21 && nu) {
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
@ -58,7 +58,7 @@ public class F6_02_02 extends F6_02 {
} else if (t21 && !nu) {
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
return CommonTriggerEvents.RELEASED;
} else {
} else if (lastEvent != null) {
if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
return CommonTriggerEvents.DIR1_RELEASED;
} else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {

View File

@ -189,14 +189,11 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements
break;
case TRIGGER:
String lastEvent = lastEvents.get(channelId);
if (lastEvent != null) {
String event = eep.convertToEvent(channelId, channelTypeId, lastEvent,
channelConfig);
String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, channelConfig);
if (event != null) {
triggerChannel(channel.getUID(), event);
lastEvents.put(channelId, event);
}
}
break;
}
});

View File

@ -208,7 +208,7 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "opening serial port...");
localTransceiver.initilize();
localTransceiver.initialize();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "starting rx thread...");
localTransceiver.startReceiving(scheduler);

View File

@ -180,7 +180,7 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener {
this.path = path;
}
public void initilize()
public void initialize()
throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException {
SerialPortManager localSerialPortManager = serialPortManager;
if (localSerialPortManager == null) {
@ -224,7 +224,7 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener {
@Nullable
Future<?> localReadingTask = readingTask;
if (localReadingTask == null || localReadingTask.isCancelled()) {
localReadingTask = scheduler.submit(new Runnable() {
readingTask = scheduler.submit(new Runnable() {
@Override
public void run() {
receivePackets();
@ -313,14 +313,25 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener {
InputStream localInputStream = inputStream;
if (localInputStream != null) {
try {
localInputStream.read(buffer, 0, length);
return localInputStream.read(buffer, 0, length);
} catch (IOException e) {
logger.debug("IOException occured while reading the input stream", e);
return 0;
}
} else {
logger.warn("Cannot read from null stream");
Future<?> localReadingTask = readingTask;
if (localReadingTask != null) {
localReadingTask.cancel(true);
readingTask = null;
}
TransceiverErrorListener localListener = errorListener;
if (localListener != null) {
localListener.errorOccured(new IOException("Cannot read from null stream"));
}
return 0;
}
}
protected void informListeners(BasePacket packet) {
try {