Skip to content

Commit

Permalink
When trying to send a message while the bridge was not connected an N…
Browse files Browse the repository at this point in the history
…PE occurred (openhab#2299)

Also no exception will be rethrown since we actually handle it so no reason to rethrow the error as well.

fixes openhab#2298

Signed-off-by: Martin van Wingerden <[email protected]>
  • Loading branch information
martinvw authored and kaikreuzer committed May 30, 2017
1 parent 4642179 commit 7a66fb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -41,11 +41,9 @@
import org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage;
import org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.Commands;
import org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.SubType;
import org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.TransceiverType;
import org.openhab.binding.rfxcom.internal.messages.RFXComMessage;
import org.openhab.binding.rfxcom.internal.messages.RFXComMessageFactory;
import org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage;
import org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -110,7 +108,6 @@ public synchronized void send() throws IOException {

private TransmitQueue transmitQueue = new TransmitQueue();


public RFXComBridgeHandler(Bridge br) {
super(br);
}
Expand Down Expand Up @@ -224,7 +221,7 @@ public void sendMessage(RFXComMessage msg) throws RFXComException {
transmitQueue.enqueue(baseMsg);
} catch (IOException e) {
logger.error("I/O Error", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}

Expand Down Expand Up @@ -259,12 +256,14 @@ public void packetReceived(byte[] packet) {
logger.warn("Failed to parse setMode data", ee);
}
} else {
RFXComInterfaceControlMessage modeMsg = new RFXComInterfaceControlMessage(msg.transceiverType, configuration);
RFXComInterfaceControlMessage modeMsg = new RFXComInterfaceControlMessage(
msg.transceiverType, configuration);
setMode = modeMsg.decodeMessage();
}

if (setMode != null) {
logger.debug("Setting RFXCOM mode using: {}", DatatypeConverter.printHexBinary(setMode));
logger.debug("Setting RFXCOM mode using: {}",
DatatypeConverter.printHexBinary(setMode));
connector.sendMessage(setMode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public void disconnect() {
readerThread.interrupt();
try {
readerThread.join();
} catch (InterruptedException e) {}
} catch (InterruptedException e) {
}
}

if (out != null) {
Expand All @@ -117,6 +118,10 @@ public void disconnect() {

@Override
public void sendMessage(byte[] data) throws IOException {
if (out == null) {
throw new IOException("Not connected sending messages is not possible");
}

logger.trace("Send data (len={}): {}", data.length, DatatypeConverter.printHexBinary(data));
out.write(data);
out.flush();
Expand Down

0 comments on commit 7a66fb3

Please sign in to comment.