Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[irtrans] Remove org.apache.common #14408

Merged
merged 17 commits into from
Nov 6, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class IrCommand {
*
*/
private class PulsePair {
public int Pulse;
public int Pause;
public int pulse;
public int pause;
}

private String remote;
Expand Down Expand Up @@ -254,15 +254,15 @@ public ByteBuffer toByteBuffer() {

// Pause timings - 8 Shorts = 16 bytes
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++) {
byteBuffer.putShort((short) 0);
}

// Pulse timings - 8 Shorts = 16 bytes
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++) {
byteBuffer.putShort((short) 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

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.IrCommand;
import org.openhab.core.library.types.StringType;
Expand Down Expand Up @@ -70,12 +69,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (!(command instanceof RefreshType)) {
if (channelUID.getId().equals(CHANNEL_IO)) {
if (command instanceof StringType) {
String remoteName = StringUtils.substringBefore(command.toString(), ",");
String irCommandName = StringUtils.substringAfter(command.toString(), ",");
String[] remoteCommand = command.toString().split(",", 2);
if (remoteCommand.length < 2) {
logger.warn("Ignoring invalid command '{}'", command);
return;
}
lsiepel marked this conversation as resolved.
Show resolved Hide resolved

IrCommand ircommand = new IrCommand();
ircommand.setRemote(remoteName);
ircommand.setCommand(irCommandName);
ircommand.setRemote(remoteCommand[0]);
ircommand.setCommand(remoteCommand[1]);

IrCommand thingCompatibleCommand = new IrCommand();
thingCompatibleCommand.setRemote((String) getConfig().get(REMOTE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import java.util.regex.Matcher;
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.Led;
import org.openhab.binding.irtrans.internal.IrCommand;
Expand All @@ -51,6 +49,7 @@
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.util.HexUtils;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -179,11 +178,11 @@ public void dispose() {
}
}

public boolean registerTransceiverStatusListener(@NonNull TransceiverStatusListener transceiverStatusListener) {
public boolean registerTransceiverStatusListener(TransceiverStatusListener transceiverStatusListener) {
return transceiverStatusListeners.add(transceiverStatusListener);
}

public boolean unregisterTransceiverStatusListener(@NonNull TransceiverStatusListener transceiverStatusListener) {
public boolean unregisterTransceiverStatusListener(TransceiverStatusListener transceiverStatusListener) {
return transceiverStatusListeners.remove(transceiverStatusListener);
}

Expand Down Expand Up @@ -277,12 +276,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (channel.getChannelTypeUID() != null
&& channel.getChannelTypeUID().getId().equals(IRtransBindingConstants.BLASTER_CHANNEL_TYPE)) {
if (command instanceof StringType) {
String remoteName = StringUtils.substringBefore(command.toString(), ",");
String irCommandName = StringUtils.substringAfter(command.toString(), ",");
String[] remoteCommand = command.toString().split(",", 2);
if (remoteCommand.length < 2) {
logger.warn("Ignoring invalid command '{}'", command);
return;
}

IrCommand ircommand = new IrCommand();
ircommand.setRemote(remoteName);
ircommand.setCommand(irCommandName);
ircommand.setRemote(remoteCommand[0]);
ircommand.setCommand(remoteCommand[1]);

IrCommand thingCompatibleCommand = new IrCommand();
thingCompatibleCommand.setRemote((String) channelConfiguration.get(REMOTE));
Expand Down Expand Up @@ -343,14 +345,12 @@ protected void configureTransceiver() {

if (response != null) {
String message = stripByteCount(response).split("\0")[0];
if (message != null) {
if (message.contains("VERSION")) {
logger.info("'{}' matches an IRtrans device with firmware {}", getThing().getUID(), message);
getConfig().put(FIRMWARE_VERSION, message);
} else {
logger.debug("Received some non-compliant garbage ({})", message);
onConnectionLost();
}
if (message.contains("VERSION")) {
logger.info("'{}' matches an IRtrans device with firmware {}", getThing().getUID(), message);
getConfig().put(FIRMWARE_VERSION, message);
} else {
logger.debug("Received some non-compliant garbage ({})", message);
onConnectionLost();
}
} else {
try {
Expand Down Expand Up @@ -441,20 +441,17 @@ private String[] getRemoteCommands(String remote, int index) {
if (response != null) {
String message = stripByteCount(response).split("\0")[0];
logger.trace("commands returned {}", message);
if (message != null) {
if (message.contains("COMMANDLIST")) {
commandList = message.split(",");
} else {
logger.debug("Received some non-compliant command ({})", message);
onConnectionLost();
}
if (message.contains("COMMANDLIST")) {
commandList = message.split(",");
} else {
logger.debug("Received some non-compliant command ({})", message);
onConnectionLost();
}
} else {
logger.debug("Did not receive an answer from the IRtrans transceiver for '{}' - Parsing is skipped",
getThing().getUID());
onConnectionLost();
}

return commandList;
}

Expand All @@ -466,13 +463,11 @@ private String[] getRemoteList(int index) {
if (response != null) {
String message = stripByteCount(response).split("\0")[0];
logger.trace("remotes returned {}", message);
if (message != null) {
if (message.contains("REMOTELIST")) {
remoteList = message.split(",");
} else {
logger.debug("Received some non-compliant command ({})", message);
onConnectionLost();
}
if (message.contains("REMOTELIST")) {
remoteList = message.split(",");
} else {
logger.debug("Received some non-compliant command ({})", message);
onConnectionLost();
}
} else {
logger.debug("Did not receive an answer from the IRtrans transceiver for '{}' - Parsing is skipped",
Expand All @@ -493,7 +488,7 @@ public boolean sendIRcommand(IrCommand command, Led led) {

if (response != null) {
String message = stripByteCount(response).split("\0")[0];
if (message != null && message.contains("RESULT OK")) {
if (message.contains("RESULT OK")) {
return true;
} else {
logger.debug("Received an unexpected response from the IRtrans transceiver: '{}'", message);
Expand Down