[denonmarantz] Fix NPE on connection problem (#15422)

* Checkstyle cleanup
* Fix #15444

Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-08-18 16:33:39 +02:00 committed by GitHub
parent a435ed2cd0
commit 5c6fabbb62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 25 deletions

View File

@ -12,11 +12,11 @@
*/ */
package org.openhab.binding.denonmarantz.internal; package org.openhab.binding.denonmarantz.internal;
import org.openhab.binding.denonmarantz.internal.handler.DenonMarantzHandler;
import org.openhab.core.types.State; import org.openhab.core.types.State;
/** /**
* Interface to notify the {@link DenonMarantzHandler} about state changes. * Interface to notify the {@link org.openhab.binding.denonmarantz.internal.handler.DenonMarantzHandler} about state
* changes.
* *
* @author Jan-Willem Veldhuis - Initial contribution * @author Jan-Willem Veldhuis - Initial contribution
* *

View File

@ -20,6 +20,7 @@ import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.denonmarantz.internal.config.DenonMarantzConfiguration; import org.openhab.binding.denonmarantz.internal.config.DenonMarantzConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -48,7 +49,7 @@ public class DenonMarantzTelnetClientThread extends Thread {
private OutputStreamWriter out; private OutputStreamWriter out;
private BufferedReader in; private @Nullable BufferedReader in;
public DenonMarantzTelnetClientThread(DenonMarantzConfiguration config, DenonMarantzTelnetListener listener) { public DenonMarantzTelnetClientThread(DenonMarantzConfiguration config, DenonMarantzTelnetListener listener) {
logger.debug("Denon listener created"); logger.debug("Denon listener created");
@ -65,7 +66,11 @@ public class DenonMarantzTelnetClientThread extends Thread {
do { do {
try { try {
String line = in.readLine(); String line = null;
BufferedReader in = this.in;
if (in != null) {
line = in.readLine();
}
if (line == null) { if (line == null) {
logger.debug("No more data read from client. Disconnecting.."); logger.debug("No more data read from client. Disconnecting..");
listener.telnetClientConnected(false); listener.telnetClientConnected(false);

View File

@ -157,8 +157,8 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement
state.setInput(value); state.setInput(value);
break; break;
case "PW": // Power case "PW": // Power
if (value.equals("ON") || value.equals("STANDBY")) { if ("ON".equals(value) || "STANDBY".equals(value)) {
state.setPower(value.equals("ON")); state.setPower("ON".equals(value));
} }
break; break;
case "MS": // Main zone surround program case "MS": // Main zone surround program
@ -170,18 +170,18 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement
} }
break; break;
case "MU": // Main zone mute case "MU": // Main zone mute
if (value.equals("ON") || value.equals("OFF")) { if ("ON".equals(value) || "OFF".equals(value)) {
state.setMute(value.equals("ON")); state.setMute("ON".equals(value));
} }
break; break;
case "NS": // Now playing information case "NS": // Now playing information
processTitleCommand(value); processTitleCommand(value);
break; break;
case "Z2": // Zone 2 case "Z2": // Zone 2
if (value.equals("ON") || value.equals("OFF")) { if ("ON".equals(value) || "OFF".equals(value)) {
state.setZone2Power(value.equals("ON")); state.setZone2Power("ON".equals(value));
} else if (value.equals("MUON") || value.equals("MUOFF")) { } else if ("MUON".equals(value) || "MUOFF".equals(value)) {
state.setZone2Mute(value.equals("MUON")); state.setZone2Mute("MUON".equals(value));
} else if (value.chars().allMatch(Character::isDigit)) { } else if (value.chars().allMatch(Character::isDigit)) {
state.setZone2Volume(fromDenonValue(value)); state.setZone2Volume(fromDenonValue(value));
} else { } else {
@ -189,10 +189,10 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement
} }
break; break;
case "Z3": // Zone 3 case "Z3": // Zone 3
if (value.equals("ON") || value.equals("OFF")) { if ("ON".equals(value) || "OFF".equals(value)) {
state.setZone3Power(value.equals("ON")); state.setZone3Power("ON".equals(value));
} else if (value.equals("MUON") || value.equals("MUOFF")) { } else if ("MUON".equals(value) || "MUOFF".equals(value)) {
state.setZone3Mute(value.equals("MUON")); state.setZone3Mute("MUON".equals(value));
} else if (value.chars().allMatch(Character::isDigit)) { } else if (value.chars().allMatch(Character::isDigit)) {
state.setZone3Volume(fromDenonValue(value)); state.setZone3Volume(fromDenonValue(value));
} else { } else {
@ -200,10 +200,10 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement
} }
break; break;
case "Z4": // Zone 4 case "Z4": // Zone 4
if (value.equals("ON") || value.equals("OFF")) { if ("ON".equals(value) || "OFF".equals(value)) {
state.setZone4Power(value.equals("ON")); state.setZone4Power("ON".equals(value));
} else if (value.equals("MUON") || value.equals("MUOFF")) { } else if ("MUON".equals(value) || "MUOFF".equals(value)) {
state.setZone4Mute(value.equals("MUON")); state.setZone4Mute("MUON".equals(value));
} else if (value.chars().allMatch(Character::isDigit)) { } else if (value.chars().allMatch(Character::isDigit)) {
state.setZone4Volume(fromDenonValue(value)); state.setZone4Volume(fromDenonValue(value));
} else { } else {
@ -211,8 +211,8 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement
} }
break; break;
case "ZM": // Main zone case "ZM": // Main zone
if (value.equals("ON") || value.equals("OFF")) { if ("ON".equals(value) || "OFF".equals(value)) {
state.setMainZonePower(value.equals("ON")); state.setMainZonePower("ON".equals(value));
} }
break; break;
} }

View File

@ -12,10 +12,9 @@
*/ */
package org.openhab.binding.denonmarantz.internal.connector.telnet; package org.openhab.binding.denonmarantz.internal.connector.telnet;
import org.openhab.binding.denonmarantz.internal.connector.DenonMarantzConnector;
/** /**
* Listener interface used to notify the {@link DenonMarantzConnector} about received messages over Telnet * Listener interface used to notify the
* {@link org.openhab.binding.denonmarantz.internal.connector.DenonMarantzConnector} about received messages over Telnet
* *
* @author Jan-Willem Veldhuis - Initial contribution * @author Jan-Willem Veldhuis - Initial contribution
* *