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

[denonmarantz] Fix NullPointerException on connection problem #15422

Merged
merged 6 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 @@ public void run() {

do {
try {
String line = in.readLine();
String line = null;
if (in != null) {
line = in.readLine();
lsiepel marked this conversation as resolved.
Show resolved Hide resolved
}
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