mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[freeboxos] Better fix for WEB socket registration (#17236)
* Checks if the server supports VM. Replace #17124 which was more a workaround. * Change default value The value is always set when calling openSession. Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
73a3f151c9
commit
858be48183
@ -52,6 +52,8 @@ public class FreeboxOsSession {
|
||||
private @Nullable Session session;
|
||||
private String appToken = "";
|
||||
private int wsReconnectInterval;
|
||||
@Nullable
|
||||
private Boolean vmSupported;
|
||||
|
||||
public enum BoxModel {
|
||||
FBXGW_R1_FULL, // Freebox Server (v6) revision 1
|
||||
@ -85,7 +87,9 @@ public class FreeboxOsSession {
|
||||
ApiVersion.class, null, null);
|
||||
this.uriBuilder = config.getUriBuilder(version.baseUrl());
|
||||
this.wsReconnectInterval = config.wsReconnectInterval;
|
||||
this.vmSupported = null;
|
||||
getManager(LoginManager.class);
|
||||
getManager(SystemManager.class);
|
||||
getManager(NetShareManager.class);
|
||||
getManager(LanManager.class);
|
||||
getManager(WifiManager.class);
|
||||
@ -95,9 +99,13 @@ public class FreeboxOsSession {
|
||||
|
||||
public void openSession(String appToken) throws FreeboxException {
|
||||
Session newSession = getManager(LoginManager.class).openSession(appToken);
|
||||
getManager(WebSocketManager.class).openSession(newSession.sessionToken(), wsReconnectInterval);
|
||||
session = newSession;
|
||||
this.appToken = appToken;
|
||||
if (vmSupported == null) {
|
||||
vmSupported = getManager(SystemManager.class).getConfig().modelInfo().hasVm();
|
||||
}
|
||||
getManager(WebSocketManager.class).openSession(newSession.sessionToken(), wsReconnectInterval,
|
||||
Boolean.TRUE.equals(vmSupported));
|
||||
}
|
||||
|
||||
public String grant() throws FreeboxException {
|
||||
|
@ -73,8 +73,7 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
|
||||
@Nullable
|
||||
private String sessionToken;
|
||||
private int reconnectInterval;
|
||||
private boolean vmSupported = true;
|
||||
private boolean retryConnectWithoutVm = false;
|
||||
private boolean vmSupported;
|
||||
|
||||
private record Register(String action, List<String> events) {
|
||||
Register(String... events) {
|
||||
@ -101,9 +100,10 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void openSession(@Nullable String sessionToken, int reconnectInterval) {
|
||||
public void openSession(@Nullable String sessionToken, int reconnectInterval, boolean vmSupported) {
|
||||
this.sessionToken = sessionToken;
|
||||
this.reconnectInterval = reconnectInterval;
|
||||
this.vmSupported = vmSupported;
|
||||
if (reconnectInterval > 0) {
|
||||
try {
|
||||
client.start();
|
||||
@ -190,12 +190,6 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
|
||||
default:
|
||||
logger.warn("Unhandled notification received: {}", result.action);
|
||||
}
|
||||
} else if (result.action == Action.REGISTER) {
|
||||
logger.debug("Event registration failed!");
|
||||
if (vmSupported && "unsupported event vm_state_changed".equals(result.msg)) {
|
||||
vmSupported = false;
|
||||
retryConnectWithoutVm = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,11 +227,6 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
|
||||
public void onWebSocketClose(int statusCode, @NonNullByDefault({}) String reason) {
|
||||
logger.debug("Socket Closed: [{}] - reason {}", statusCode, reason);
|
||||
this.wsSession = null;
|
||||
if (retryConnectWithoutVm) {
|
||||
logger.debug("Retry connecting websocket client without VM support");
|
||||
retryConnectWithoutVm = false;
|
||||
startReconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user