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

[intesis] Fix blocking calls in initialize/dispose #16620

Merged
merged 4 commits into from
Apr 6, 2024
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 @@ -112,11 +112,10 @@ public void initialize() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Password not set");
return;
} else {
logger.trace("trying to log in - current session ID: {}", sessionId);
login();

// start background initialization:
scheduler.submit(() -> {
logger.trace("initialize() - trying to log in");
jlaur marked this conversation as resolved.
Show resolved Hide resolved
login();
populateProperties();
// query available dataPoints and build dynamic channels
postRequestInSession(sessionId -> "{\"command\":\"getavailabledatapoints\",\"data\":{\"sessionID\":\""
Expand All @@ -136,7 +135,10 @@ public void dispose() {
this.refreshJob = null;
}

logout(sessionId);
// start background dispose:
scheduler.submit(() -> {
logout();
});
}

@Override
Expand Down Expand Up @@ -230,7 +232,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
Data data = gson.fromJson(resp.data, Data.class);
ResponseError error = gson.fromJson(resp.error, ResponseError.class);
if (error != null) {
logger.debug("Login - Error: {}", error);
logger.debug("login() - error: {}", error);
}
if (data != null) {
Id id = gson.fromJson(data.id, Id.class);
Expand All @@ -239,7 +241,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
});
logger.trace("Login - received session ID: {}", sessionId);
logger.trace("login() - received session ID: {}", sessionId);
if (sessionId != null && !sessionId.isEmpty()) {
updateStatus(ThingStatus.ONLINE);
} else {
Expand All @@ -249,9 +251,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
return sessionId;
}

public @Nullable String logout(String sessionId) {
String contentString = "{\"command\":\"logout\",\"data\":{\"sessionID\":\"" + sessionId + "\"}}";
return api.postRequest(config.ipAddress, contentString);
public @Nullable String logout() {
if (!sessionId.isEmpty()) { // we have a running session
String contentString = "{\"command\":\"logout\",\"data\":{\"sessionID\":\"" + sessionId + "\"}}";
logger.trace("logout() - session ID: {}", sessionId);
sessionId = ""; // not really necessary as it is called after dispose(), so sessionID is not used anympre,
// but it is a cleaner way
return api.postRequest(config.ipAddress, contentString);
}
return null;
}

public void populateProperties() {
Expand Down