Skip to content

Commit

Permalink
[denonmarantz] Fix NPE on connection problem (#15422)
Browse files Browse the repository at this point in the history
* Checkstyle cleanup
* Fix #15444

Signed-off-by: lsiepel <leosiepel@gmail.com>
  • Loading branch information
lsiepel authored Aug 18, 2023
1 parent a435ed2 commit 5c6fabb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
package org.openhab.binding.denonmarantz.internal;

import org.openhab.binding.denonmarantz.internal.handler.DenonMarantzHandler;
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.Socket;
import java.net.SocketTimeoutException;

import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.denonmarantz.internal.config.DenonMarantzConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class DenonMarantzTelnetClientThread extends Thread {

private OutputStreamWriter out;

private BufferedReader in;
private @Nullable BufferedReader in;

public DenonMarantzTelnetClientThread(DenonMarantzConfiguration config, DenonMarantzTelnetListener listener) {
logger.debug("Denon listener created");
Expand All @@ -65,7 +66,11 @@ public void run() {

do {
try {
String line = in.readLine();
String line = null;
BufferedReader in = this.in;
if (in != null) {
line = in.readLine();
}
if (line == null) {
logger.debug("No more data read from client. Disconnecting..");
listener.telnetClientConnected(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public void receivedLine(String line) {
state.setInput(value);
break;
case "PW": // Power
if (value.equals("ON") || value.equals("STANDBY")) {
state.setPower(value.equals("ON"));
if ("ON".equals(value) || "STANDBY".equals(value)) {
state.setPower("ON".equals(value));
}
break;
case "MS": // Main zone surround program
Expand All @@ -170,49 +170,49 @@ public void receivedLine(String line) {
}
break;
case "MU": // Main zone mute
if (value.equals("ON") || value.equals("OFF")) {
state.setMute(value.equals("ON"));
if ("ON".equals(value) || "OFF".equals(value)) {
state.setMute("ON".equals(value));
}
break;
case "NS": // Now playing information
processTitleCommand(value);
break;
case "Z2": // Zone 2
if (value.equals("ON") || value.equals("OFF")) {
state.setZone2Power(value.equals("ON"));
} else if (value.equals("MUON") || value.equals("MUOFF")) {
state.setZone2Mute(value.equals("MUON"));
if ("ON".equals(value) || "OFF".equals(value)) {
state.setZone2Power("ON".equals(value));
} else if ("MUON".equals(value) || "MUOFF".equals(value)) {
state.setZone2Mute("MUON".equals(value));
} else if (value.chars().allMatch(Character::isDigit)) {
state.setZone2Volume(fromDenonValue(value));
} else {
state.setZone2Input(value);
}
break;
case "Z3": // Zone 3
if (value.equals("ON") || value.equals("OFF")) {
state.setZone3Power(value.equals("ON"));
} else if (value.equals("MUON") || value.equals("MUOFF")) {
state.setZone3Mute(value.equals("MUON"));
if ("ON".equals(value) || "OFF".equals(value)) {
state.setZone3Power("ON".equals(value));
} else if ("MUON".equals(value) || "MUOFF".equals(value)) {
state.setZone3Mute("MUON".equals(value));
} else if (value.chars().allMatch(Character::isDigit)) {
state.setZone3Volume(fromDenonValue(value));
} else {
state.setZone3Input(value);
}
break;
case "Z4": // Zone 4
if (value.equals("ON") || value.equals("OFF")) {
state.setZone4Power(value.equals("ON"));
} else if (value.equals("MUON") || value.equals("MUOFF")) {
state.setZone4Mute(value.equals("MUON"));
if ("ON".equals(value) || "OFF".equals(value)) {
state.setZone4Power("ON".equals(value));
} else if ("MUON".equals(value) || "MUOFF".equals(value)) {
state.setZone4Mute("MUON".equals(value));
} else if (value.chars().allMatch(Character::isDigit)) {
state.setZone4Volume(fromDenonValue(value));
} else {
state.setZone4Input(value);
}
break;
case "ZM": // Main zone
if (value.equals("ON") || value.equals("OFF")) {
state.setMainZonePower(value.equals("ON"));
if ("ON".equals(value) || "OFF".equals(value)) {
state.setMainZonePower("ON".equals(value));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
*/
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
*
Expand Down

0 comments on commit 5c6fabb

Please sign in to comment.