[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 GitHub
parent 6dccbcb005
commit 2961593cfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 33 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -114,7 +114,7 @@ public abstract class EEP {
return convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config); 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) { Configuration config) {
if (!getEEPType().isChannelSupported(channelId, channelTypeId)) { if (!getEEPType().isChannelSupported(channelId, channelTypeId)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -223,7 +223,7 @@ public abstract class EEP {
return UnDefType.UNDEF; 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) { Configuration config) {
return null; return null;
} }

View File

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

View File

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

View File

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

View File

@ -189,14 +189,11 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements
break; break;
case TRIGGER: case TRIGGER:
String lastEvent = lastEvents.get(channelId); 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) { if (event != null) {
triggerChannel(channel.getUID(), event); triggerChannel(channel.getUID(), event);
lastEvents.put(channelId, event); lastEvents.put(channelId, event);
} }
}
break; break;
} }
}); });

View File

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

View File

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