[miio] Support contact type in basic channel json (#11477)

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2021-10-31 12:42:32 +01:00 committed by GitHub
parent 8b1eabe166
commit b73bf672ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -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]+$"))) {