[irtrans] Remove org.apache.common (#14408)

* Fix warnings

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-11-06 15:30:57 +01:00 committed by GitHub
parent 6196de7742
commit 4e7d7363c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 41 deletions

View File

@ -43,8 +43,8 @@ public class IrCommand {
* *
*/ */
private class PulsePair { private class PulsePair {
public int Pulse; public int pulse;
public int Pause; public int pause;
} }
private String remote; private String remote;
@ -254,7 +254,7 @@ public class IrCommand {
// Pause timings - 8 Shorts = 16 bytes // Pause timings - 8 Shorts = 16 bytes
for (int i = 0; i < pulsePairs.size(); i++) { for (int i = 0; i < pulsePairs.size(); i++) {
byteBuffer.putShort((short) Math.round(pulsePairs.get(i).Pause / 8)); byteBuffer.putShort((short) Math.round(pulsePairs.get(i).pause / 8));
} }
for (int i = pulsePairs.size(); i <= 7; i++) { for (int i = pulsePairs.size(); i <= 7; i++) {
byteBuffer.putShort((short) 0); byteBuffer.putShort((short) 0);
@ -262,7 +262,7 @@ public class IrCommand {
// Pulse timings - 8 Shorts = 16 bytes // Pulse timings - 8 Shorts = 16 bytes
for (int i = 0; i < pulsePairs.size(); i++) { for (int i = 0; i < pulsePairs.size(); i++) {
byteBuffer.putShort((short) Math.round(pulsePairs.get(i).Pulse / 8)); byteBuffer.putShort((short) Math.round(pulsePairs.get(i).pulse / 8));
} }
for (int i = pulsePairs.size(); i <= 7; i++) { for (int i = pulsePairs.size(); i <= 7; i++) {
byteBuffer.putShort((short) 0); byteBuffer.putShort((short) 0);

View File

@ -14,7 +14,6 @@ package org.openhab.binding.irtrans.internal.handler;
import static org.openhab.binding.irtrans.internal.IRtransBindingConstants.CHANNEL_IO; import static org.openhab.binding.irtrans.internal.IRtransBindingConstants.CHANNEL_IO;
import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.irtrans.internal.IRtransBindingConstants.Led; import org.openhab.binding.irtrans.internal.IRtransBindingConstants.Led;
import org.openhab.binding.irtrans.internal.IrCommand; import org.openhab.binding.irtrans.internal.IrCommand;
import org.openhab.core.library.types.StringType; import org.openhab.core.library.types.StringType;
@ -70,12 +69,15 @@ public class BlasterHandler extends BaseThingHandler implements TransceiverStatu
if (!(command instanceof RefreshType)) { if (!(command instanceof RefreshType)) {
if (channelUID.getId().equals(CHANNEL_IO)) { if (channelUID.getId().equals(CHANNEL_IO)) {
if (command instanceof StringType) { if (command instanceof StringType) {
String remoteName = StringUtils.substringBefore(command.toString(), ","); String[] remoteCommand = command.toString().split(",", 2);
String irCommandName = StringUtils.substringAfter(command.toString(), ","); if (remoteCommand.length < 2) {
logger.warn("Ignoring invalid command '{}'", command);
return;
}
IrCommand ircommand = new IrCommand(); IrCommand ircommand = new IrCommand();
ircommand.setRemote(remoteName); ircommand.setRemote(remoteCommand[0]);
ircommand.setCommand(irCommandName); ircommand.setCommand(remoteCommand[1]);
IrCommand thingCompatibleCommand = new IrCommand(); IrCommand thingCompatibleCommand = new IrCommand();
thingCompatibleCommand.setRemote((String) getConfig().get(REMOTE)); thingCompatibleCommand.setRemote((String) getConfig().get(REMOTE));

View File

@ -35,8 +35,6 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.openhab.binding.irtrans.internal.IRtransBindingConstants; import org.openhab.binding.irtrans.internal.IRtransBindingConstants;
import org.openhab.binding.irtrans.internal.IRtransBindingConstants.Led; import org.openhab.binding.irtrans.internal.IRtransBindingConstants.Led;
import org.openhab.binding.irtrans.internal.IrCommand; import org.openhab.binding.irtrans.internal.IrCommand;
@ -51,6 +49,7 @@ import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType; import org.openhab.core.types.RefreshType;
import org.openhab.core.util.HexUtils; import org.openhab.core.util.HexUtils;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -179,11 +178,11 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
} }
} }
public boolean registerTransceiverStatusListener(@NonNull TransceiverStatusListener transceiverStatusListener) { public boolean registerTransceiverStatusListener(TransceiverStatusListener transceiverStatusListener) {
return transceiverStatusListeners.add(transceiverStatusListener); return transceiverStatusListeners.add(transceiverStatusListener);
} }
public boolean unregisterTransceiverStatusListener(@NonNull TransceiverStatusListener transceiverStatusListener) { public boolean unregisterTransceiverStatusListener(TransceiverStatusListener transceiverStatusListener) {
return transceiverStatusListeners.remove(transceiverStatusListener); return transceiverStatusListeners.remove(transceiverStatusListener);
} }
@ -277,12 +276,15 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
if (channel.getChannelTypeUID() != null if (channel.getChannelTypeUID() != null
&& channel.getChannelTypeUID().getId().equals(IRtransBindingConstants.BLASTER_CHANNEL_TYPE)) { && channel.getChannelTypeUID().getId().equals(IRtransBindingConstants.BLASTER_CHANNEL_TYPE)) {
if (command instanceof StringType) { if (command instanceof StringType) {
String remoteName = StringUtils.substringBefore(command.toString(), ","); String[] remoteCommand = command.toString().split(",", 2);
String irCommandName = StringUtils.substringAfter(command.toString(), ","); if (remoteCommand.length < 2) {
logger.warn("Ignoring invalid command '{}'", command);
return;
}
IrCommand ircommand = new IrCommand(); IrCommand ircommand = new IrCommand();
ircommand.setRemote(remoteName); ircommand.setRemote(remoteCommand[0]);
ircommand.setCommand(irCommandName); ircommand.setCommand(remoteCommand[1]);
IrCommand thingCompatibleCommand = new IrCommand(); IrCommand thingCompatibleCommand = new IrCommand();
thingCompatibleCommand.setRemote((String) channelConfiguration.get(REMOTE)); thingCompatibleCommand.setRemote((String) channelConfiguration.get(REMOTE));
@ -343,14 +345,12 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
if (response != null) { if (response != null) {
String message = stripByteCount(response).split("\0")[0]; String message = stripByteCount(response).split("\0")[0];
if (message != null) { if (message.contains("VERSION")) {
if (message.contains("VERSION")) { logger.info("'{}' matches an IRtrans device with firmware {}", getThing().getUID(), message);
logger.info("'{}' matches an IRtrans device with firmware {}", getThing().getUID(), message); getConfig().put(FIRMWARE_VERSION, message);
getConfig().put(FIRMWARE_VERSION, message); } else {
} else { logger.debug("Received some non-compliant garbage ({})", message);
logger.debug("Received some non-compliant garbage ({})", message); onConnectionLost();
onConnectionLost();
}
} }
} else { } else {
try { try {
@ -441,20 +441,17 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
if (response != null) { if (response != null) {
String message = stripByteCount(response).split("\0")[0]; String message = stripByteCount(response).split("\0")[0];
logger.trace("commands returned {}", message); logger.trace("commands returned {}", message);
if (message != null) { if (message.contains("COMMANDLIST")) {
if (message.contains("COMMANDLIST")) { commandList = message.split(",");
commandList = message.split(","); } else {
} else { logger.debug("Received some non-compliant command ({})", message);
logger.debug("Received some non-compliant command ({})", message); onConnectionLost();
onConnectionLost();
}
} }
} else { } else {
logger.debug("Did not receive an answer from the IRtrans transceiver for '{}' - Parsing is skipped", logger.debug("Did not receive an answer from the IRtrans transceiver for '{}' - Parsing is skipped",
getThing().getUID()); getThing().getUID());
onConnectionLost(); onConnectionLost();
} }
return commandList; return commandList;
} }
@ -466,13 +463,11 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
if (response != null) { if (response != null) {
String message = stripByteCount(response).split("\0")[0]; String message = stripByteCount(response).split("\0")[0];
logger.trace("remotes returned {}", message); logger.trace("remotes returned {}", message);
if (message != null) { if (message.contains("REMOTELIST")) {
if (message.contains("REMOTELIST")) { remoteList = message.split(",");
remoteList = message.split(","); } else {
} else { logger.debug("Received some non-compliant command ({})", message);
logger.debug("Received some non-compliant command ({})", message); onConnectionLost();
onConnectionLost();
}
} }
} else { } else {
logger.debug("Did not receive an answer from the IRtrans transceiver for '{}' - Parsing is skipped", logger.debug("Did not receive an answer from the IRtrans transceiver for '{}' - Parsing is skipped",
@ -493,7 +488,7 @@ public class EthernetBridgeHandler extends BaseBridgeHandler implements Transcei
if (response != null) { if (response != null) {
String message = stripByteCount(response).split("\0")[0]; String message = stripByteCount(response).split("\0")[0];
if (message != null && message.contains("RESULT OK")) { if (message.contains("RESULT OK")) {
return true; return true;
} else { } else {
logger.debug("Received an unexpected response from the IRtrans transceiver: '{}'", message); logger.debug("Received an unexpected response from the IRtrans transceiver: '{}'", message);