]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hdpowerview] Update positions after triggering scene/scene group (#11768)
authorjlaur <jacob-github@vindvejr.dk>
Mon, 20 Dec 2021 19:32:48 +0000 (20:32 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Dec 2021 19:32:48 +0000 (20:32 +0100)
* Update positions after triggering scene/scene group.
* Compare enum values directly with ==
* Fix re-entrant calls.

Fixes #11697

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewWebTargets.java
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewHubHandler.java

index 8fee72166c96aaf6ae50d633f404cb846a1ea22e..16efb896a6a986775ea0836c5f57146c81fa25e8 100644 (file)
@@ -237,7 +237,6 @@ public class HDPowerViewWebTargets {
      * @param query the http query parameter
      * @param jsonCommand the request command content (as a json string)
      * @return the response content (as a json string)
-     * @throws HubProcessingException
      * @throws HubMaintenanceException
      * @throws HubProcessingException
      */
index 9a75c03f318d3d43f5dae66b5d05358884cd597b..10936ed60f2072e15ebe03a6e01e986cd1edf665 100644 (file)
@@ -72,11 +72,13 @@ import com.google.gson.JsonParseException;
  *
  * @author Andy Lintner - Initial contribution
  * @author Andrew Fiddian-Green - Added support for secondary rail positions
- * @author Jacob Laursen - Add support for scene groups and automations
+ * @author Jacob Laursen - Added support for scene groups and automations
  */
 @NonNullByDefault
 public class HDPowerViewHubHandler extends BaseBridgeHandler {
 
+    private static final long INITIAL_SOFT_POLL_DELAY_MS = 5_000;
+
     private final Logger logger = LoggerFactory.getLogger(HDPowerViewHubHandler.class);
     private final HttpClient httpClient;
     private final HDPowerViewTranslationProvider translationProvider;
@@ -113,7 +115,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
 
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
-        if (RefreshType.REFRESH.equals(command)) {
+        if (RefreshType.REFRESH == command) {
             requestRefreshShadePositions();
             return;
         }
@@ -129,12 +131,16 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
                 throw new ProcessingException("Web targets not initialized");
             }
             int id = Integer.parseInt(channelUID.getIdWithoutGroup());
-            if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON.equals(command)) {
+            if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) {
                 webTargets.activateScene(id);
-            } else if (sceneGroupChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON.equals(command)) {
+                // Reschedule soft poll for immediate shade position update.
+                scheduleSoftPoll(0);
+            } else if (sceneGroupChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) {
                 webTargets.activateSceneCollection(id);
+                // Reschedule soft poll for immediate shade position update.
+                scheduleSoftPoll(0);
             } else if (automationChannelTypeUID.equals(channel.getChannelTypeUID())) {
-                webTargets.enableScheduledEvent(id, OnOffType.ON.equals(command));
+                webTargets.enableScheduledEvent(id, OnOffType.ON == command);
             }
         } catch (HubMaintenanceException e) {
             // exceptions are logged in HDPowerViewWebTargets
@@ -189,14 +195,22 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
     }
 
     private void schedulePoll() {
+        scheduleSoftPoll(INITIAL_SOFT_POLL_DELAY_MS);
+        scheduleHardPoll();
+    }
+
+    private void scheduleSoftPoll(long initialDelay) {
         ScheduledFuture<?> future = this.pollFuture;
         if (future != null) {
             future.cancel(false);
         }
-        logger.debug("Scheduling poll for 5000ms out, then every {}ms", refreshInterval);
-        this.pollFuture = scheduler.scheduleWithFixedDelay(this::poll, 5000, refreshInterval, TimeUnit.MILLISECONDS);
+        logger.debug("Scheduling poll for {} ms out, then every {} ms", initialDelay, refreshInterval);
+        this.pollFuture = scheduler.scheduleWithFixedDelay(this::poll, initialDelay, refreshInterval,
+                TimeUnit.MILLISECONDS);
+    }
 
-        future = this.hardRefreshPositionFuture;
+    private void scheduleHardPoll() {
+        ScheduledFuture<?> future = this.hardRefreshPositionFuture;
         if (future != null) {
             future.cancel(false);
         }