From b73bf672ab76f28b3842ffe3bc91c361cfd91d50 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 31 Oct 2021 12:42:32 +0100 Subject: [PATCH] [miio] Support contact type in basic channel json (#11477) Signed-off-by: Marcel Verpaalen --- .../miio/internal/handler/MiIoBasicHandler.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java index 4c7432b7f..c6c7c5905 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java @@ -52,6 +52,7 @@ import org.openhab.core.cache.ExpiringCache; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.StringType; @@ -622,6 +623,17 @@ public class MiIoBasicHandler extends MiIoAbstractHandler { : OnOffType.OFF); } break; + case "contact": + if (val.getAsJsonPrimitive().isNumber()) { + updateState(basicChannel.getChannel(), + val.getAsInt() > 0 ? OpenClosedType.OPEN : OpenClosedType.CLOSED); + } else { + String strVal = val.getAsString().toLowerCase(); + updateState(basicChannel.getChannel(), + "on".equals(strVal) || "true".equals(strVal) || "1".equals(strVal) ? OpenClosedType.OPEN + : OpenClosedType.CLOSED); + } + break; case "color": if (val.isJsonPrimitive() && (val.getAsJsonPrimitive().isNumber() || val.getAsString().matches("^[0-9]+$"))) {