]> git.basschouten.com Git - openhab-addons.git/commitdiff
Reintroduce LK Wiser dimmer work-around for API v2 (#15316)
authorJacob Laursen <jacob-github@vindvejr.dk>
Mon, 31 Jul 2023 11:22:58 +0000 (13:22 +0200)
committerGitHub <noreply@github.com>
Mon, 31 Jul 2023 11:22:58 +0000 (13:22 +0200)
Fixes #15315

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

index 00975e55d2c1afbecdc637eccea05dbb09d24aa4..84586791b069d4a7c236da775505778a8560677c 100644 (file)
@@ -98,6 +98,8 @@ public class Clip2ThingHandler extends BaseThingHandler {
 
     private static final Duration DYNAMICS_ACTIVE_WINDOW = Duration.ofSeconds(10);
 
+    private static final String LK_WISER_DIMMER_MODEL_ID = "LK Dimmer";
+
     private final Logger logger = LoggerFactory.getLogger(Clip2ThingHandler.class);
 
     /**
@@ -163,6 +165,7 @@ public class Clip2ThingHandler extends BaseThingHandler {
     private boolean updateLightPropertiesDone;
     private boolean updatePropertiesDone;
     private boolean updateDependenciesDone;
+    private boolean applyOffTransitionWorkaround;
 
     private @Nullable Future<?> alertResetTask;
     private @Nullable Future<?> dynamicsResetTask;
@@ -402,6 +405,7 @@ public class Clip2ThingHandler extends BaseThingHandler {
             case CHANNEL_2_SWITCH:
                 putResource = Objects.nonNull(putResource) ? putResource : new Resource(lightResourceType);
                 putResource.setOnOff(command);
+                applyDeviceSpecificWorkArounds(command, putResource);
                 break;
 
             case CHANNEL_2_COLOR_XY_ONLY:
@@ -414,6 +418,7 @@ public class Clip2ThingHandler extends BaseThingHandler {
 
             case CHANNEL_2_ON_OFF_ONLY:
                 putResource = new Resource(lightResourceType).setOnOff(command);
+                applyDeviceSpecificWorkArounds(command, putResource);
                 break;
 
             case CHANNEL_2_TEMPERATURE_ENABLED:
@@ -514,6 +519,18 @@ public class Clip2ThingHandler extends BaseThingHandler {
         }
     }
 
+    /**
+     * Apply device specific work-arounds needed for given command.
+     *
+     * @param command the handled command.
+     * @param putResource the resource that will be adjusted if needed.
+     */
+    private void applyDeviceSpecificWorkArounds(Command command, Resource putResource) {
+        if (command == OnOffType.OFF && applyOffTransitionWorkaround) {
+            putResource.setDynamicsDuration(dynamicsDuration);
+        }
+    }
+
     /**
      * Handle a 'dynamics' command for the given channel ID for the given dynamics duration.
      *
@@ -1020,9 +1037,11 @@ public class Clip2ThingHandler extends BaseThingHandler {
             // product data
             ProductData productData = thisResource.getProductData();
             if (Objects.nonNull(productData)) {
+                String modelId = productData.getModelId();
+
                 // standard properties
                 properties.put(PROPERTY_RESOURCE_ID, resourceId);
-                properties.put(Thing.PROPERTY_MODEL_ID, productData.getModelId());
+                properties.put(Thing.PROPERTY_MODEL_ID, modelId);
                 properties.put(Thing.PROPERTY_VENDOR, productData.getManufacturerName());
                 properties.put(Thing.PROPERTY_FIRMWARE_VERSION, productData.getSoftwareVersion());
                 String hardwarePlatformType = productData.getHardwarePlatformType();
@@ -1034,6 +1053,14 @@ public class Clip2ThingHandler extends BaseThingHandler {
                 properties.put(PROPERTY_PRODUCT_NAME, productData.getProductName());
                 properties.put(PROPERTY_PRODUCT_ARCHETYPE, productData.getProductArchetype().toString());
                 properties.put(PROPERTY_PRODUCT_CERTIFIED, productData.getCertified().toString());
+
+                // Check device for needed work-arounds.
+                if (LK_WISER_DIMMER_MODEL_ID.equals(modelId)) {
+                    // Apply transition time as a workaround for LK Wiser Dimmer firmware bug.
+                    // Additional details here: https://techblog.vindvejr.dk/?p=455
+                    applyOffTransitionWorkaround = true;
+                    logger.debug("{} -> enabling work-around for turning off LK Wiser Dimmer", resourceId);
+                }
             }
 
             thing.setProperties(properties);