[velux] softer initialization if bridge unreachable (#14817)

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
Andrew Fiddian-Green 2023-05-11 15:26:25 +01:00 committed by GitHub
parent 2f7bdbe966
commit 6cd10a771e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 1 deletions

View File

@ -12,6 +12,8 @@
*/
package org.openhab.binding.velux.internal.handler;
import java.io.IOException;
import java.net.InetAddress;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
@ -163,6 +165,7 @@ public class VeluxBridgeHandler extends ExtendedBaseBridgeHandler implements Vel
private VeluxBridgeConfiguration veluxBridgeConfiguration = new VeluxBridgeConfiguration();
private Duration offlineDelay = Duration.ofMinutes(5);
private int initializeRetriesDone = 0;
/*
* ************************
@ -298,6 +301,8 @@ public class VeluxBridgeHandler extends ExtendedBaseBridgeHandler implements Vel
offlineDelay = Duration.ofMillis(
((long) Math.pow(2, veluxBridgeConfiguration.retries + 1) - 1) * veluxBridgeConfiguration.refreshMSecs);
initializeRetriesDone = 0;
scheduler.execute(() -> {
disposing = false;
initializeSchedulerJob();
@ -316,6 +321,17 @@ public class VeluxBridgeHandler extends ExtendedBaseBridgeHandler implements Vel
logger.trace("initializeSchedulerJob(): adopt new bridge configuration parameters.");
bridgeParamsUpdated();
if ((thing.getStatus() == ThingStatus.OFFLINE)
&& (thing.getStatusInfo().getStatusDetail() == ThingStatusDetail.COMMUNICATION_ERROR)) {
if (initializeRetriesDone <= veluxBridgeConfiguration.retries) {
initializeRetriesDone++;
scheduler.schedule(() -> initializeSchedulerJob(),
((long) Math.pow(2, initializeRetriesDone) * veluxBridgeConfiguration.timeoutMsecs),
TimeUnit.MILLISECONDS);
}
return;
}
long mSecs = veluxBridgeConfiguration.refreshMSecs;
logger.trace("initializeSchedulerJob(): scheduling refresh at {} milliseconds.", mSecs);
refreshSchedulerJob = scheduler.scheduleWithFixedDelay(() -> {
@ -448,7 +464,16 @@ public class VeluxBridgeHandler extends ExtendedBaseBridgeHandler implements Vel
logger.trace("bridgeParamsUpdated() done.");
return;
}
try {
InetAddress bridgeAddress = InetAddress.getByName(veluxBridgeConfiguration.ipAddress);
if (!bridgeAddress.isReachable(veluxBridgeConfiguration.timeoutMsecs)) {
throw new IOException();
}
} catch (IOException e) {
logger.debug("bridgeParamsUpdated(): Bridge ip address not reachable.");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
return;
}
logger.trace("bridgeParamsUpdated(): Trying to authenticate towards bridge.");
if (!thisBridge.bridgeLogin()) {