]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] fix issue with some hue lights, e.g. xiaomi (#12931)
authoreugen <freiter@gmail.com>
Mon, 13 Jun 2022 17:16:13 +0000 (19:16 +0200)
committerGitHub <noreply@github.com>
Mon, 13 Jun 2022 17:16:13 +0000 (19:16 +0200)
* fix for hue

Signed-off-by: Eugen Freiter <freiter@gmx.de>
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitOHItemProxy.java

index e8a6c8b00cca83348fdd433cb715a8d67765beed..4dd6145d69aa0731ae78a6ec0b889c49d3cf8852 100644 (file)
@@ -103,30 +103,39 @@ public class HomekitOHItemProxy {
         // if hue or saturation present, send an HSBType state update. no filter applied for HUE & Saturation
         if ((hue != null) || (saturation != null)) {
             if (item instanceof ColorItem) {
-                // logic for ColorItem = combine hue, saturation and brightness update to one command
-                final HSBType currentState = item.getState() instanceof UnDefType ? HSBType.BLACK
-                        : (HSBType) item.getState();
-                ((ColorItem) item).send(new HSBType(hue != null ? hue : currentState.getHue(),
-                        saturation != null ? saturation : currentState.getSaturation(),
-                        brightness != null ? brightness : currentState.getBrightness()));
-                logger.trace("send HSB command for item {} with following values hue={} saturation={} brightness={}",
-                        item, hue, saturation, brightness);
+                sendHSBCommand((ColorItem) item, hue, saturation, brightness);
             }
         } else if ((brightness != null) && (item instanceof DimmerItem)) {
             // sends brightness:
-            // - DIMMER_MODE_NONE
+            // - DIMMER_MODE_NORMAL
             // - DIMMER_MODE_FILTER_ON
             // - other modes (DIMMER_MODE_FILTER_BRIGHTNESS_100 or DIMMER_MODE_FILTER_ON_EXCEPT_BRIGHTNESS_100) and
             // <100%.
             if ((dimmerMode == DIMMER_MODE_NORMAL) || (dimmerMode == DIMMER_MODE_FILTER_ON)
                     || (brightness.intValue() < 100) || (currentOnState == OnOffType.ON)) {
                 logger.trace("send Brightness command for item {} with value {}", item, brightness);
-                ((DimmerItem) item).send(brightness);
+                if (item instanceof ColorItem) {
+                    sendHSBCommand((ColorItem) item, hue, saturation, brightness);
+                } else {
+                    ((DimmerItem) item).send(brightness);
+                }
             }
         }
         commandCache.clear();
     }
 
+    private void sendHSBCommand(ColorItem item, @Nullable DecimalType hue, @Nullable PercentType saturation,
+            @Nullable PercentType brightness) {
+        final HSBType currentState = item.getState() instanceof UnDefType ? HSBType.BLACK : (HSBType) item.getState();
+        // logic for ColorItem = combine hue, saturation and brightness update to one command
+        final DecimalType targetHue = hue != null ? hue : currentState.getHue();
+        final PercentType targetSaturation = saturation != null ? saturation : currentState.getSaturation();
+        final PercentType targetBrightness = brightness != null ? brightness : currentState.getBrightness();
+        item.send(new HSBType(targetHue, targetSaturation, targetBrightness));
+        logger.trace("send HSB command for item {} with following values hue={} saturation={} brightness={}", item,
+                targetHue, targetSaturation, targetBrightness);
+    }
+
     public synchronized void sendCommandProxy(HomekitCommandType commandType, State state) {
         commandCache.put(commandType, state);
         logger.trace("add command to command cache: item {}, command type {}, command state {}. cache state after: {}",