Skip to content

Commit

Permalink
[enocean] Fix unusable bundle after a refactoring about null annotati…
Browse files Browse the repository at this point in the history
…on (#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>
  • Loading branch information
dalgwen authored Jul 26, 2023
1 parent 6dccbcb commit 2961593
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public A5_20_04(ERP1Message packet) {
}

@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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public D2_03_0A(ERP1Message packet) {
}

@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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* 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
Expand Down Expand Up @@ -164,7 +164,7 @@ protected State getMotionState() {
}

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);
Expand Down Expand Up @@ -198,7 +198,7 @@ protected State getBatteryLevel() {
}

@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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected State getCalibrationStep() {
}

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public State convertToState(String channelId, String channelTypeId, Configuratio
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(
Expand Down Expand Up @@ -223,7 +223,7 @@ protected State convertToStateImpl(String channelId, String channelTypeId,
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public F6_01_01(ERP1Message packet) {
}

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public F6_02_01(ERP1Message packet) {
}

@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)) {
Expand All @@ -59,7 +59,7 @@ public F6_02_01(ERP1Message packet) {
} 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public F6_02_02(ERP1Message packet) {
}

@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)) {
Expand All @@ -58,7 +58,7 @@ public F6_02_02(ERP1Message packet) {
} 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,10 @@ public void packetReceived(BasePacket packet) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private synchronized void initTransceiver() {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public EnOceanTransceiver(String path, TransceiverErrorListener errorListener, S
this.path = path;
}

public void initilize()
public void initialize()
throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException {
SerialPortManager localSerialPortManager = serialPortManager;
if (localSerialPortManager == null) {
Expand Down Expand Up @@ -224,7 +224,7 @@ public void startReceiving(ScheduledExecutorService scheduler) {
@Nullable
Future<?> localReadingTask = readingTask;
if (localReadingTask == null || localReadingTask.isCancelled()) {
localReadingTask = scheduler.submit(new Runnable() {
readingTask = scheduler.submit(new Runnable() {
@Override
public void run() {
receivePackets();
Expand Down Expand Up @@ -313,13 +313,24 @@ protected int read(byte[] buffer, int length) {
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) {
Expand Down

0 comments on commit 2961593

Please sign in to comment.