From 2961593cfd3d0b96f26a8742ce8b7fa4177d1255 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Wed, 26 Jul 2023 13:21:59 +0200 Subject: [PATCH] [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 --- .../enocean/internal/eep/A5_20/A5_20_04.java | 2 +- .../enocean/internal/eep/D2_03/D2_03_0A.java | 2 +- .../enocean/internal/eep/D2_06/D2_06_01.java | 6 +++--- .../enocean/internal/eep/D2_06/D2_06_50.java | 2 +- .../binding/enocean/internal/eep/EEP.java | 4 ++-- .../enocean/internal/eep/F6_01/F6_01_01.java | 2 +- .../enocean/internal/eep/F6_02/F6_02_01.java | 4 ++-- .../enocean/internal/eep/F6_02/F6_02_02.java | 4 ++-- .../handler/EnOceanBaseSensorHandler.java | 11 ++++------- .../handler/EnOceanBridgeHandler.java | 2 +- .../BaseResponse.java | 0 .../RDBaseIdResponse.java | 0 .../RDLearnedClientsResponse.java | 0 .../RDRepeaterResponse.java | 0 .../RDVersionResponse.java | 0 .../SMACKTeachInResponse.java | 0 .../transceiver/EnOceanTransceiver.java | 19 +++++++++++++++---- 17 files changed, 33 insertions(+), 25 deletions(-) rename bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/{Responses => responses}/BaseResponse.java (100%) rename bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/{Responses => responses}/RDBaseIdResponse.java (100%) rename bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/{Responses => responses}/RDLearnedClientsResponse.java (100%) rename bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/{Responses => responses}/RDRepeaterResponse.java (100%) rename bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/{Responses => responses}/RDVersionResponse.java (100%) rename bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/{Responses => responses}/SMACKTeachInResponse.java (100%) 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 d79601dc3..5924c7845 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 @@ -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: 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 824a5408f..91ea0aa39 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 @@ -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: 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 8668c0ba6..db4b35f5f 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 @@ -38,7 +38,7 @@ import org.openhab.core.types.UnDefType; * battery channels may be not supported by the physical device (depending on the actual model). If a channel is not * supported by a device it will transmit a 'not supported' message which is ignored by this implementation. * Consequently channels that are not supported by the physical device will never send updates to linked items. - * + * * @author Thomas Lauterbach - Initial contribution */ @NonNullByDefault @@ -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()) { 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 63ad5c71e..d8a58c7c2 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 @@ -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) { 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 353f75670..e5f832099 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 @@ -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; } 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 60329e831..14c6a9c90 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 @@ -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; } 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 361269076..80e7db349 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 @@ -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)) { 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 514c07eab..ed63201e8 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 @@ -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)) { 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 e26b3663f..d242e0f29 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 @@ -189,13 +189,10 @@ 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); - if (event != null) { - triggerChannel(channel.getUID(), event); - lastEvents.put(channelId, event); - } + String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, channelConfig); + if (event != null) { + triggerChannel(channel.getUID(), event); + lastEvents.put(channelId, event); } break; } 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 cadb17f98..0a4cb5f3f 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 @@ -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); 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 similarity index 100% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/BaseResponse.java 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 similarity index 100% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDBaseIdResponse.java 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 similarity index 100% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDLearnedClientsResponse.java 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 similarity index 100% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDRepeaterResponse.java 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 similarity index 100% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDVersionResponse.java 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 similarity index 100% rename from bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java rename to bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/SMACKTeachInResponse.java 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 298d1b1f0..145d8ae39 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 @@ -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,13 +313,24 @@ 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; } - return 0; } protected void informListeners(BasePacket packet) {