]> git.basschouten.com Git - openhab-addons.git/commitdiff
[somfytahoma] Faster feedback for commands initiated by the binding (#10409)
authorlolodomo <lg.hc@free.fr>
Fri, 2 Apr 2021 20:31:35 +0000 (22:31 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Apr 2021 20:31:35 +0000 (22:31 +0200)
Also fix references to OH2

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBridgeHandler.java

index 8895d8288c9d4d947ed2a2decb18212349896290..2fa94bfe91bf4a6670b271a19dfb0d8465f5ed48 100644 (file)
@@ -166,9 +166,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
      */
     private void initPolling() {
         stopPolling();
-        pollFuture = scheduler.scheduleWithFixedDelay(() -> {
-            getTahomaUpdates();
-        }, 10, thingConfig.getRefresh(), TimeUnit.SECONDS);
+        scheduleGetUpdates(10);
 
         statusFuture = scheduler.scheduleWithFixedDelay(() -> {
             refreshTahomaStates();
@@ -179,6 +177,21 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
         }, RECONCILIATION_TIME, RECONCILIATION_TIME, TimeUnit.SECONDS);
     }
 
+    private void scheduleGetUpdates(long delay) {
+        pollFuture = scheduler.schedule(() -> {
+            getTahomaUpdates();
+            scheduleNextGetUpdates();
+        }, delay, TimeUnit.SECONDS);
+    }
+
+    private void scheduleNextGetUpdates() {
+        ScheduledFuture<?> localPollFuture = pollFuture;
+        if (localPollFuture != null) {
+            localPollFuture.cancel(false);
+        }
+        scheduleGetUpdates(executions.isEmpty() ? thingConfig.getRefresh() : 2);
+    }
+
     public synchronized void login() {
         String url;
 
@@ -638,9 +651,9 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
     }
 
     private boolean sendCommandInternal(String io, String command, String params, String url) {
-        String value = params.equals("[]") ? command : params.replace("\"", "");
+        String value = params.equals("[]") ? command : command + " " + params.replace("\"", "");
         String urlParameters = "{\"label\":\"" + getThingLabelByURL(io) + " - " + value
-                + " - OH2\",\"actions\":[{\"deviceURL\":\"" + io + "\",\"commands\":[{\"name\":\"" + command
+                + " - openHAB\",\"actions\":[{\"deviceURL\":\"" + io + "\",\"commands\":[{\"name\":\"" + command
                 + "\",\"parameters\":" + params + "}]}]}";
         SomfyTahomaApplyResponse response = invokeCallToURL(url, urlParameters, HttpMethod.POST,
                 SomfyTahomaApplyResponse.class);
@@ -648,6 +661,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
             if (!response.getExecId().isEmpty()) {
                 logger.debug("Exec id: {}", response.getExecId());
                 registerExecution(io, response.getExecId());
+                scheduleNextGetUpdates();
             } else {
                 logger.debug("ExecId is empty!");
                 return false;
@@ -689,7 +703,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
                 // Return label from Tahoma
                 return th.getProperties().get(NAME_STATE).replace("\"", "");
             }
-            // Return label from OH2
+            // Return label from the thing
             String label = th.getLabel();
             return label != null ? label.replace("\"", "") : "";
         }
@@ -717,6 +731,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
         }
         if (execId != null) {
             registerExecution(id, execId);
+            scheduleNextGetUpdates();
         }
     }