]> git.basschouten.com Git - openhab-addons.git/commitdiff
[remoteopenhab] New settings to setup the remote server accessibility check (#9311)
authorlolodomo <lg.hc@free.fr>
Wed, 9 Dec 2020 22:52:41 +0000 (23:52 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Dec 2020 22:52:41 +0000 (14:52 -0800)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.remoteopenhab/README.md
bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java
bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java
bundles/org.openhab.binding.remoteopenhab/src/main/resources/OH-INF/thing/thing-types.xml

index 977f2daf02c6e7702195093bb5bea87e40d80c05..07bef25df914c0cef508608c3ebeafcca082daee 100644 (file)
@@ -36,14 +36,16 @@ The binding has no configuration options, all configuration is done at Thing lev
 
 The `server` thing has the following configuration parameters:
 
-| Parameter          | Required | Description                                                                                               |
-|--------------------|----------|-----------------------------------------------------------------------------------------------------------|
-| host               | yes      | The host name or IP address of the remote openHAB server.                                                 |
-| useHttps           | no       | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false.     |
-| port               | yes      | The HTTP port to use to communicate with the remote openHAB server. Default is 8080.                      |
-| trustedCertificate | no       | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. |
-| restPath           | yes      | The subpath of the REST API on the remote openHAB server. Default is /rest                                |
-| token              | no       | The token to use when the remote openHAB server is setup to require authorization to run its REST API.    |
+| Parameter             | Required | Description                                                                                               |
+|-----------------------|----------|-----------------------------------------------------------------------------------------------------------|
+| host                  | yes      | The host name or IP address of the remote openHAB server.                                                 |
+| useHttps              | no       | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false.     |
+| port                  | yes      | The HTTP port to use to communicate with the remote openHAB server. Default is 8080.                      |
+| trustedCertificate    | no       | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. |
+| restPath              | yes      | The subpath of the REST API on the remote openHAB server. Default is /rest                                |
+| token                 | no       | The token to use when the remote openHAB server is setup to require authorization to run its REST API.    |
+| accessibilityInterval | no       | Minutes between checking the remote server accessibility. 0 to disable the check. Default is 3.           |
+| aliveInterval         | no       | Number of last minutes to take into account to determine whether the remote server is alive. 0 to disable this feature. Default is 5. |
 
 The `thing` thing has the following configuration parameters:
 
index cbb0c8242ee3791b0ecf377a01ddfd5009855805..edfefdd7ad96a0f0437c61a5417e4e51e6f02b22 100644 (file)
@@ -33,4 +33,6 @@ public class RemoteopenhabServerConfiguration {
     public boolean trustedCertificate = false;
     public String restPath = "/rest";
     public String token = "";
+    public int accessibilityInterval = 3;
+    public int aliveInterval = 5;
 }
index bc3a199dfbfa9d5c9a3ab540d87306b96d7d6133..06040dfaf0bf3c015704fc134b50a849c149c68a 100644 (file)
@@ -98,7 +98,6 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
     private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
     private static final DateTimeFormatter FORMATTER_DATE = DateTimeFormatter.ofPattern(DATE_FORMAT_PATTERN);
 
-    private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES);
     private static final int MAX_STATE_SIZE_FOR_LOGGING = 50;
 
     private final Logger logger = LoggerFactory.getLogger(RemoteopenhabBridgeHandler.class);
@@ -177,7 +176,10 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
 
         updateStatus(ThingStatus.UNKNOWN);
 
-        startCheckConnectionJob();
+        scheduler.submit(this::checkConnection);
+        if (config.accessibilityInterval > 0) {
+            startCheckConnectionJob(config.accessibilityInterval, config.aliveInterval);
+        }
     }
 
     @Override
@@ -354,19 +356,25 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
         }
     }
 
-    private void startCheckConnectionJob() {
+    private void startCheckConnectionJob(int accessibilityInterval, int aliveInterval) {
         ScheduledFuture<?> localCheckConnectionJob = checkConnectionJob;
         if (localCheckConnectionJob == null || localCheckConnectionJob.isCancelled()) {
             checkConnectionJob = scheduler.scheduleWithFixedDelay(() -> {
                 long millisSinceLastEvent = System.currentTimeMillis() - restClient.getLastEventTimestamp();
-                if (millisSinceLastEvent > CONNECTION_TIMEOUT_MILLIS) {
-                    logger.debug("Check: Maybe disconnected from streaming events, millisSinceLastEvent={}",
+                if (aliveInterval == 0 || restClient.getLastEventTimestamp() == 0) {
+                    logger.debug("Time to check server accessibility");
+                    checkConnection();
+                } else if (millisSinceLastEvent > (aliveInterval * 60000)) {
+                    logger.debug(
+                            "Time to check server accessibility (maybe disconnected from streaming events, millisSinceLastEvent={})",
                             millisSinceLastEvent);
                     checkConnection();
                 } else {
-                    logger.debug("Check: Receiving streaming events, millisSinceLastEvent={}", millisSinceLastEvent);
+                    logger.debug(
+                            "Bypass server accessibility check (receiving streaming events, millisSinceLastEvent={})",
+                            millisSinceLastEvent);
                 }
-            }, 0, CONNECTION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+            }, accessibilityInterval, accessibilityInterval, TimeUnit.MINUTES);
         }
     }
 
index 762bba8de9ca61947bd0b2be19867ddb9ce6111c..f992004b880f3ffc00deb1fd355d235562a18713 100644 (file)
                                <description>The token to use when the remote openHAB server is setup to require authorization to run its REST API.</description>
                                <advanced>true</advanced>
                        </parameter>
+
+                       <parameter name="accessibilityInterval" type="integer" min="0" step="1" unit="min">
+                               <label>Accessibility Interval</label>
+                               <description>Minutes between checking the remote server accessibility. 0 to disable the check. Default is 3.</description>
+                               <default>3</default>
+                               <advanced>true</advanced>
+                       </parameter>
+
+                       <parameter name="aliveInterval" type="integer" min="0" step="1" unit="min">
+                               <label>Alive Interval</label>
+                               <description>Number of last minutes to take into account to determine whether the remote server is alive. 0 to
+                                       disable this feature. Default is 5.</description>
+                               <default>5</default>
+                               <advanced>true</advanced>
+                       </parameter>
                </config-description>
        </bridge-type>