mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Compare commits
5 Commits
1c0964eb08
...
ede063ae7f
Author | SHA1 | Date | |
---|---|---|---|
|
ede063ae7f | ||
|
e868d3264a | ||
|
eded3ca791 | ||
|
f0ce2fc9fe | ||
|
0ffc18a7f6 |
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@ -161,6 +162,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Connected to Netatmo API.");
|
logger.debug("Connected to Netatmo API.");
|
||||||
|
freeConnectJob();
|
||||||
|
|
||||||
ApiHandlerConfiguration configuration = getConfiguration();
|
ApiHandlerConfiguration configuration = getConfiguration();
|
||||||
if (!configuration.webHookUrl.isBlank()
|
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,
|
public synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> clazz, @Nullable String payload,
|
||||||
@Nullable String contentType, int retryCount) throws NetatmoException {
|
@Nullable String contentType, int retryCount) throws NetatmoException {
|
||||||
try {
|
if (connectJob.isPresent()) {
|
||||||
logger.debug("executeUri {} {} ", method.toString(), uri);
|
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);
|
Request request = httpClient.newRequest(uri).method(method).timeout(TIMEOUT_S, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
try {
|
||||||
if (!authenticate(null, null)) {
|
if (!authenticate(null, null)) {
|
||||||
prepareReconnection(getConfiguration().reconnectInterval, "@text/status-bridge-offline", null, null);
|
prepareReconnection(getConfiguration().reconnectInterval, "@text/status-bridge-offline", null, null);
|
||||||
throw new NetatmoException("Not authenticated");
|
throw new NetatmoException("Not authenticated");
|
||||||
@ -452,4 +457,8 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
|
|||||||
public Optional<WebhookServlet> getWebHookServlet() {
|
public Optional<WebhookServlet> getWebHookServlet() {
|
||||||
return webHookServlet;
|
return webHookServlet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable Duration getTimeBeforeReconnect() {
|
||||||
|
return connectJob.map(job -> Duration.ofSeconds(job.getDelay(TimeUnit.SECONDS))).orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
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.binding.netatmo.internal.handler.CommonInterface;
|
||||||
import org.openhab.core.thing.ThingStatus;
|
import org.openhab.core.thing.ThingStatus;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -85,9 +86,14 @@ public class RefreshCapability extends Capability {
|
|||||||
private void proceedWithUpdate() {
|
private void proceedWithUpdate() {
|
||||||
Duration delay;
|
Duration delay;
|
||||||
handler.proceedWithUpdate();
|
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;
|
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 {
|
} else {
|
||||||
delay = calcDelay();
|
delay = calcDelay();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user