[nikobus] open connection on refresh even if no modules exist (#9603)
* open connection on refresh even if no modules exist Signed-off-by: Wouter Denayer <wouter@denayer.com> * ran mvn spotless:apply Signed-off-by: Wouter Denayer <wouter@denayer.com> * removed unnecessary file Signed-off-by: Wouter Denayer <wouter@denayer.com> * returning when the connection is offline since following code won't work either. Signed-off-by: Wouter Denayer <wouter@denayer.com> Co-authored-by: Wouter Denayer <wouter@denayer.com>pull/9718/head
parent
9ff37fbdd2
commit
1f3b0e2865
|
@ -50,8 +50,8 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link NikobusPcLinkHandler} is responsible for handling commands, which are
|
* The {@link NikobusPcLinkHandler} is responsible for handling commands, which
|
||||||
* sent or received from the PC-Link Nikobus component.
|
* are sent or received from the PC-Link Nikobus component.
|
||||||
*
|
*
|
||||||
* @author Boris Krivonog - Initial contribution
|
* @author Boris Krivonog - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@ -329,6 +329,21 @@ public class NikobusPcLinkHandler extends BaseBridgeHandler {
|
||||||
List<Thing> things = getThing().getThings().stream()
|
List<Thing> things = getThing().getThings().stream()
|
||||||
.filter(thing -> thing.getHandler() instanceof NikobusModuleHandler).collect(Collectors.toList());
|
.filter(thing -> thing.getHandler() instanceof NikobusModuleHandler).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// if there are command listeners (buttons) then we need an open connection even if no modules exist
|
||||||
|
if (!commandListeners.isEmpty()) {
|
||||||
|
NikobusConnection connection = this.connection;
|
||||||
|
if (connection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
connectIfNeeded(connection);
|
||||||
|
} catch (IOException e) {
|
||||||
|
connection.close();
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (things.isEmpty()) {
|
if (things.isEmpty()) {
|
||||||
logger.debug("Nothing to refresh");
|
logger.debug("Nothing to refresh");
|
||||||
return;
|
return;
|
||||||
|
@ -349,8 +364,8 @@ public class NikobusPcLinkHandler extends BaseBridgeHandler {
|
||||||
if (!connection.isConnected()) {
|
if (!connection.isConnected()) {
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
// Send connection sequence, mimicking the Nikobus software. If this is not send, PC-Link
|
// Send connection sequence, mimicking the Nikobus software. If this is not
|
||||||
// sometimes does not forward button presses via serial interface.
|
// sent, PC-Link sometimes does not forward button presses via serial interface.
|
||||||
Stream.of(new String[] { "++++", "ATH0", "ATZ", "$10110000B8CF9D", "#L0", "#E0", "#L0", "#E1" })
|
Stream.of(new String[] { "++++", "ATH0", "ATZ", "$10110000B8CF9D", "#L0", "#E0", "#L0", "#E1" })
|
||||||
.map(NikobusCommand::new).forEach(this::sendCommand);
|
.map(NikobusCommand::new).forEach(this::sendCommand);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue