[pulseaudio] Fix #8843. Stop spamming logs when pulseaudio device is offline (#8850)

Signed-off-by: Robert von Könemann <lordtaifleh@gmail.com>
This commit is contained in:
Robert von Könemann 2020-10-24 21:00:17 +02:00 committed by GitHub
parent 91fbe746e9
commit fa9e3db34b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 40 deletions

View File

@ -17,6 +17,7 @@ import static org.openhab.binding.pulseaudio.internal.PulseaudioBindingConstants
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.NoRouteToHostException;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
@ -132,7 +133,7 @@ public class PulseaudioClient {
}
public boolean isConnected() {
return client.isConnected();
return client != null ? client.isConnected() : false;
}
/**
@ -539,6 +540,7 @@ public class PulseaudioClient {
private void sendRawCommand(String command) {
checkConnection();
if (client != null) {
try {
PrintStream out = new PrintStream(client.getOutputStream(), true);
logger.trace("sending command {} to pa-server {}", command, host);
@ -549,11 +551,13 @@ public class PulseaudioClient {
logger.error("{}", e.getLocalizedMessage(), e);
}
}
}
private String sendRawRequest(String command) {
logger.trace("_sendRawRequest({})", command);
checkConnection();
String result = "";
if (client != null) {
try {
PrintStream out = new PrintStream(client.getOutputStream(), true);
out.print(command + "\r\n");
@ -590,6 +594,7 @@ public class PulseaudioClient {
} catch (IOException e) {
logger.error("{}", e.getLocalizedMessage(), e);
}
}
return result;
}
@ -612,6 +617,8 @@ public class PulseaudioClient {
client.setSoTimeout(500);
} catch (UnknownHostException e) {
logger.error("unknown socket host {}", host);
} catch (NoRouteToHostException e) {
logger.error("no route to host {}", host);
} catch (SocketException e) {
logger.error("{}", e.getLocalizedMessage(), e);
}