]> git.basschouten.com Git - openhab-addons.git/commitdiff
[miio] fix reported brightness for yeelight (#15611)
authorMarcel <marcel@verpaalen.com>
Sat, 23 Sep 2023 16:38:58 +0000 (18:38 +0200)
committerGitHub <noreply@github.com>
Sat, 23 Sep 2023 16:38:58 +0000 (18:38 +0200)
Fix reported brightness for yeelight when powered off.
This will fix wrong power switch visualization in the OH UI.

related to issue:
https://community.openhab.org/t/miio-and-yeelight-rgb-bulbs-behavior/135788/9

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/Conversions.java
bundles/org.openhab.binding.miio/src/main/resources/database/yeelink.light.color1.json

index 567232ba3f39de8692a375b21cf8aeec420ac7c2..c4073e3dc4f3713543003fbc598369ed3ef0e051 100644 (file)
@@ -61,14 +61,22 @@ public class Conversions {
      *
      * @param RGB
      * @param map with device variables containing the brightness info
+     * @param report brightness 0 on power off
      * @return HSV
      */
-    private static JsonElement addBrightToHSV(JsonElement rgbValue, @Nullable Map<String, Object> deviceVariables)
-            throws ClassCastException, IllegalStateException {
+    private static JsonElement addBrightToHSV(JsonElement rgbValue, @Nullable Map<String, Object> deviceVariables,
+            boolean powerDependent) throws ClassCastException, IllegalStateException {
         int bright = 100;
         if (deviceVariables != null) {
             JsonElement lastBright = (JsonElement) deviceVariables.getOrDefault("bright", new JsonPrimitive(100));
             bright = lastBright.getAsInt();
+            if (powerDependent) {
+                String lastPower = ((JsonElement) deviceVariables.getOrDefault("power", new JsonPrimitive("on")))
+                        .getAsString();
+                if (lastPower.toLowerCase().contentEquals("off")) {
+                    bright = 0;
+                }
+            }
         }
         if (rgbValue.isJsonPrimitive()
                 && (rgbValue.getAsJsonPrimitive().isNumber() || rgbValue.getAsString().matches("^[0-9]+$"))) {
@@ -215,7 +223,9 @@ public class Conversions {
                 case "TANKLEVEL":
                     return tankLevel(value);
                 case "ADDBRIGHTTOHSV":
-                    return addBrightToHSV(value, deviceVariables);
+                    return addBrightToHSV(value, deviceVariables, false);
+                case "ADDBRIGHTTOHSVPOWER":
+                    return addBrightToHSV(value, deviceVariables, true);
                 case "BRGBTOHSV":
                     return bRGBtoHSV(value);
                 case "DEVICEDATATAB":
index 18305fa735de97882448d74dc451e96adddf7cd2..4cf86731c38d1950f9ceed7c8a5eb9d8b02c8598 100644 (file)
                                "channel": "rgbColor",
                                "type": "Color",
                                "refresh": true,
-                               "transformation": "addBrightToHSV",
+                               "transformation": "addBrightToHSVPower",
                                "ChannelGroup": "actions",
                                "actions": [
                                        {