]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tivo] refresh connection every 12 hours (#10824)
authormlobstein <michael.lobstein@gmail.com>
Sat, 12 Jun 2021 11:11:15 +0000 (06:11 -0500)
committerGitHub <noreply@github.com>
Sat, 12 Jun 2021 11:11:15 +0000 (13:11 +0200)
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoBindingConstants.java
bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java
bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java

index 04019ccb71c394bd478e4a7d043190c5b3d60b15..ff11cfc5e246fd83933b4e50b9ed02bd02b6385c 100644 (file)
@@ -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");
index ea207afc7a9e4c2d2b6fc1016cf8368b5f3d400c..4546be62fa01040574ab6b2695dd1a3d648e6947 100644 (file)
@@ -212,8 +212,9 @@ public class TiVoHandler extends BaseThingHandler {
         };
 
         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()) {
index 7057e5f46358e9484921ef3684ae1719d1d58f29..b831649333bf29b0340ec00c52ca941d3aa2b6ad 100644 (file)
@@ -84,6 +84,13 @@ public class TivoStatusProvider {
             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()) {