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

[nikobus] open connection on refresh even if no modules exist #9603

Merged
merged 4 commits into from
Jan 4, 2021
Merged
Changes from all 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 @@ -50,8 +50,8 @@
import org.slf4j.LoggerFactory;

/**
* The {@link NikobusPcLinkHandler} is responsible for handling commands, which are
* sent or received from the PC-Link Nikobus component.
* The {@link NikobusPcLinkHandler} is responsible for handling commands, which
* are sent or received from the PC-Link Nikobus component.
*
* @author Boris Krivonog - Initial contribution
*/
Expand Down Expand Up @@ -329,6 +329,21 @@ private void refresh() {
List<Thing> things = getThing().getThings().stream()
.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()) {
logger.debug("Nothing to refresh");
return;
Expand All @@ -349,8 +364,8 @@ private synchronized void connectIfNeeded(NikobusConnection connection) throws I
if (!connection.isConnected()) {
connection.connect();

// Send connection sequence, mimicking the Nikobus software. If this is not send, PC-Link
// sometimes does not forward button presses via serial interface.
// Send connection sequence, mimicking the Nikobus software. If this is not
// sent, PC-Link sometimes does not forward button presses via serial interface.
Stream.of(new String[] { "++++", "ATH0", "ATZ", "$10110000B8CF9D", "#L0", "#E0", "#L0", "#E1" })
.map(NikobusCommand::new).forEach(this::sendCommand);

Expand Down