mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
Working on jlaur proposal
Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
parent
705feffd54
commit
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()
|
||||||
@ -452,4 +454,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;
|
||||||
@ -86,8 +87,15 @@ public class RefreshCapability extends Capability {
|
|||||||
Duration delay;
|
Duration delay;
|
||||||
handler.proceedWithUpdate();
|
handler.proceedWithUpdate();
|
||||||
if (!ThingStatus.ONLINE.equals(handler.getThing().getStatus())) {
|
if (!ThingStatus.ONLINE.equals(handler.getThing().getStatus())) {
|
||||||
delay = OFFLINE_DELAY;
|
if (handler.getAccountHandler() instanceof ApiBridgeHandler accountHandler
|
||||||
logger.debug("Thing '{}' is not ONLINE, using special refresh interval", thingUID);
|
&& !ThingStatus.ONLINE.equals(accountHandler.getThing().getStatus())) {
|
||||||
|
delay = accountHandler.getTimeBeforeReconnect();
|
||||||
|
delay = delay != null ? delay.plus(ASAP) : OFFLINE_DELAY;
|
||||||
|
} else {
|
||||||
|
delay = OFFLINE_DELAY;
|
||||||
|
logger.debug("Thing '{}' is not ONLINE, special refresh interval {} used", thingUID, OFFLINE_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
delay = calcDelay();
|
delay = calcDelay();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user