This commit is contained in:
Gaël L'hopital 2025-01-09 10:15:10 +01:00 committed by GitHub
commit 1c0964eb08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayDeque;
@ -161,6 +162,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
}
logger.debug("Connected to Netatmo API.");
freeConnectJob();
ApiHandlerConfiguration configuration = getConfiguration();
if (!configuration.webHookUrl.isBlank()
@ -293,11 +295,14 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
public synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> clazz, @Nullable String payload,
@Nullable String contentType, int retryCount) throws NetatmoException {
try {
logger.debug("executeUri {} {} ", method.toString(), uri);
if (connectJob.isPresent()) {
throw new NetatmoException("Connection pending, request will not be accepted in the meantime.");
}
logger.debug("executeUri {} {} ", method.toString(), uri);
Request request = httpClient.newRequest(uri).method(method).timeout(TIMEOUT_S, TimeUnit.SECONDS);
try {
if (!authenticate(null, null)) {
prepareReconnection(getConfiguration().reconnectInterval, "@text/status-bridge-offline", null, null);
throw new NetatmoException("Not authenticated");
@ -452,4 +457,8 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
public Optional<WebhookServlet> getWebHookServlet() {
return webHookServlet;
}
public @Nullable Duration getTimeBeforeReconnect() {
return connectJob.map(job -> Duration.ofSeconds(job.getDelay(TimeUnit.SECONDS))).orElse(null);
}
}

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
import org.openhab.binding.netatmo.internal.handler.CommonInterface;
import org.openhab.core.thing.ThingStatus;
import org.slf4j.Logger;
@ -85,9 +86,14 @@ public class RefreshCapability extends Capability {
private void proceedWithUpdate() {
Duration delay;
handler.proceedWithUpdate();
if (!ThingStatus.ONLINE.equals(handler.getThing().getStatus())) {
if (handler.getAccountHandler() instanceof ApiBridgeHandler accountHandler
&& !ThingStatus.ONLINE.equals(accountHandler.getThing().getStatus())) {
delay = accountHandler.getTimeBeforeReconnect();
delay = delay != null ? delay.plus(ASAP) : OFFLINE_DELAY;
logger.debug("Bridge is not ONLINE, will wait for him to come-back {}", delay);
} else if (!ThingStatus.ONLINE.equals(handler.getThing().getStatus())) {
delay = OFFLINE_DELAY;
logger.debug("Thing '{}' is not ONLINE, using special refresh interval", thingUID);
logger.debug("Thing '{}' is not ONLINE, special refresh interval {} used", thingUID, delay);
} else {
delay = calcDelay();
}