From f13223c70dbb9efe3c0cff5d8f2261871c9c4818 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Sat, 12 Jun 2021 06:11:15 -0500 Subject: [PATCH] [tivo] refresh connection every 12 hours (#10824) Signed-off-by: Michael Lobstein Signed-off-by: Luca Calcaterra --- .../binding/tivo/internal/TiVoBindingConstants.java | 1 + .../openhab/binding/tivo/internal/handler/TiVoHandler.java | 5 +++-- .../binding/tivo/internal/service/TivoStatusProvider.java | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoBindingConstants.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoBindingConstants.java index 04019ccb71c39..ff11cfc5e246f 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoBindingConstants.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoBindingConstants.java @@ -29,6 +29,7 @@ public class TiVoBindingConstants { public static final String BINDING_ID = "tivo"; public static final int CONFIG_SOCKET_TIMEOUT_MS = 1000; public static final int INIT_POLLING_DELAY_S = 5; + public static final int POLLING_DELAY_12HR_S = 43200; // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_TIVO = new ThingTypeUID(BINDING_ID, "sckt"); diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java index ea207afc7a9e4..4546be62fa010 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java @@ -212,8 +212,9 @@ private void startPollStatus() { }; if (tivoConfigData.isKeepConnActive()) { - // Run once - refreshJob = scheduler.schedule(runnable, INIT_POLLING_DELAY_S, TimeUnit.SECONDS); + // Run once every 12 hours to keep the connection from going stale + refreshJob = scheduler.scheduleWithFixedDelay(runnable, INIT_POLLING_DELAY_S, POLLING_DELAY_12HR_S, + TimeUnit.SECONDS); logger.debug("Status collection '{}' will start in '{}' seconds.", getThing().getUID(), INIT_POLLING_DELAY_S); } else if (tivoConfigData.doPollChanges()) { diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java index 7057e5f46358e..b831649333bf2 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java @@ -84,6 +84,13 @@ public void statusRefresh() throws InterruptedException { logger.debug(" statusRefresh '{}' - EXISTING status data - '{}'", tivoConfigData.getCfgIdentifier(), tivoStatusData.toString()); } + + // this will close the connection and re-open every 12 hours + if (tivoConfigData.isKeepConnActive()) { + connTivoDisconnect(); + doNappTime(); + } + connTivoConnect(); doNappTime(); if (!tivoConfigData.isKeepConnActive()) {