mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
Fix NPE when reading reply from device (#12956)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
parent
b2087e3807
commit
4182595c19
@ -130,11 +130,6 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
if (command == null) {
|
|
||||||
logger.warn("Command passed to handler for thing {} is null", thingID());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't try to send command if the device is not online
|
// Don't try to send command if the device is not online
|
||||||
if (!isOnline()) {
|
if (!isOnline()) {
|
||||||
logger.debug("Can't handle command {} because handler for thing {} is not ONLINE", command, thingID());
|
logger.debug("Can't handle command {} because handler for thing {} is not ONLINE", command, thingID());
|
||||||
@ -538,12 +533,10 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
|||||||
*/
|
*/
|
||||||
private void writeCommandToDevice(RequestMessage requestMessage) throws IOException {
|
private void writeCommandToDevice(RequestMessage requestMessage) throws IOException {
|
||||||
logger.trace("Processor for thing {} writing command to device", thingID());
|
logger.trace("Processor for thing {} writing command to device", thingID());
|
||||||
|
|
||||||
if (connectionManager.getCommandOut() == null) {
|
if (connectionManager.getCommandOut() == null) {
|
||||||
logger.debug("Error writing to device because output stream object is null");
|
logger.debug("Error writing to device because output stream object is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] deviceCommand = (requestMessage.getDeviceCommand() + '\r').getBytes();
|
byte[] deviceCommand = (requestMessage.getDeviceCommand() + '\r').getBytes();
|
||||||
connectionManager.getCommandOut().write(deviceCommand);
|
connectionManager.getCommandOut().write(deviceCommand);
|
||||||
connectionManager.getCommandOut().flush();
|
connectionManager.getCommandOut().flush();
|
||||||
@ -554,14 +547,16 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
|||||||
*/
|
*/
|
||||||
private String readReplyFromDevice(RequestMessage requestMessage) throws IOException {
|
private String readReplyFromDevice(RequestMessage requestMessage) throws IOException {
|
||||||
logger.trace("Processor for thing {} reading reply from device", thingID());
|
logger.trace("Processor for thing {} reading reply from device", thingID());
|
||||||
|
|
||||||
if (connectionManager.getCommandIn() == null) {
|
if (connectionManager.getCommandIn() == null) {
|
||||||
logger.debug("Error reading from device because input stream object is null");
|
logger.debug("Error reading from device because input stream object is null");
|
||||||
return "ERROR: BufferedReader is null!";
|
return "ERROR: BufferedReader is null!";
|
||||||
}
|
}
|
||||||
|
String reply = connectionManager.getCommandIn().readLine();
|
||||||
logger.trace("Processor for thing {} reading response from device", thingID());
|
if (reply == null) {
|
||||||
return connectionManager.getCommandIn().readLine().trim();
|
logger.debug("Read of reply from device returned null!");
|
||||||
|
return "ERROR: reply is null!";
|
||||||
|
}
|
||||||
|
return reply.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -573,11 +568,9 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
|||||||
logger.warn("Can't send serial command; output stream is null!");
|
logger.warn("Can't send serial command; output stream is null!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] deviceCommand;
|
byte[] deviceCommand;
|
||||||
deviceCommand = URLDecoder.decode(requestMessage.getDeviceCommand(), StandardCharsets.ISO_8859_1)
|
deviceCommand = URLDecoder.decode(requestMessage.getDeviceCommand(), StandardCharsets.ISO_8859_1)
|
||||||
.getBytes(StandardCharsets.ISO_8859_1);
|
.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
logger.debug("Writing decoded deviceCommand byte array: {}", getAsHexString(deviceCommand));
|
logger.debug("Writing decoded deviceCommand byte array: {}", getAsHexString(deviceCommand));
|
||||||
out.write(deviceCommand);
|
out.write(deviceCommand);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user