mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[intesis] Session Handling improved (#16620)
Signed-off-by: Christoph <fd0cwp@gmx.de> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
3706757de3
commit
e6829288fd
@ -112,11 +112,10 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Password not set");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Password not set");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
logger.trace("trying to log in - current session ID: {}", sessionId);
|
|
||||||
login();
|
|
||||||
|
|
||||||
// start background initialization:
|
// start background initialization:
|
||||||
scheduler.submit(() -> {
|
scheduler.submit(() -> {
|
||||||
|
logger.trace("initialize() - trying to log in");
|
||||||
|
login();
|
||||||
populateProperties();
|
populateProperties();
|
||||||
// query available dataPoints and build dynamic channels
|
// query available dataPoints and build dynamic channels
|
||||||
postRequestInSession(sessionId -> "{\"command\":\"getavailabledatapoints\",\"data\":{\"sessionID\":\""
|
postRequestInSession(sessionId -> "{\"command\":\"getavailabledatapoints\",\"data\":{\"sessionID\":\""
|
||||||
@ -136,7 +135,10 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
this.refreshJob = null;
|
this.refreshJob = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
logout(sessionId);
|
// start background dispose:
|
||||||
|
scheduler.submit(() -> {
|
||||||
|
logout();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -230,7 +232,7 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
Data data = gson.fromJson(resp.data, Data.class);
|
Data data = gson.fromJson(resp.data, Data.class);
|
||||||
ResponseError error = gson.fromJson(resp.error, ResponseError.class);
|
ResponseError error = gson.fromJson(resp.error, ResponseError.class);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
logger.debug("Login - Error: {}", error);
|
logger.debug("login() - error: {}", error);
|
||||||
}
|
}
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
Id id = gson.fromJson(data.id, Id.class);
|
Id id = gson.fromJson(data.id, Id.class);
|
||||||
@ -239,7 +241,7 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
logger.trace("Login - received session ID: {}", sessionId);
|
logger.trace("login() - received session ID: {}", sessionId);
|
||||||
if (sessionId != null && !sessionId.isEmpty()) {
|
if (sessionId != null && !sessionId.isEmpty()) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
} else {
|
} else {
|
||||||
@ -249,10 +251,16 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable String logout(String sessionId) {
|
public @Nullable String logout() {
|
||||||
|
if (!sessionId.isEmpty()) { // we have a running session
|
||||||
String contentString = "{\"command\":\"logout\",\"data\":{\"sessionID\":\"" + sessionId + "\"}}";
|
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 api.postRequest(config.ipAddress, contentString);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void populateProperties() {
|
public void populateProperties() {
|
||||||
postRequest("{\"command\":\"getinfo\",\"data\":\"\"}", resp -> {
|
postRequest("{\"command\":\"getinfo\",\"data\":\"\"}", resp -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user