[miio] support sending openclose commands (#11581)

* [miio] support sending openclose commands

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>

* [miio] fix contact sending

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>

* [miio] switch

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2021-11-14 13:40:05 +01:00 committed by GitHub
parent edafc1970b
commit 4d8c6b304b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -28,8 +28,9 @@ public enum CommandParameterType {
ONOFFBOOL("onoffbool"),
ONOFFBOOLSTRING("onoffboolstring"),
ONOFFNUMBER("onoffnumber"),
OPENCLOSENUMBER("openclosenumber"),
OPENCLOSE("openclose"),
OPENCLOSENUMBER("openclosenumber"),
OPENCLOSESWITCH("opencloseswitch"),
STRING("string"),
CUSTOMSTRING("customstring"),
NUMBER("number"),

View File

@ -175,6 +175,30 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
command = new DecimalType(((QuantityType<?>) command).toBigDecimal());
}
}
if (paramType == CommandParameterType.OPENCLOSE) {
if (command instanceof OpenClosedType) {
value = new JsonPrimitive(command == OpenClosedType.OPEN ? "open" : "close");
} else {
value = new JsonPrimitive(("ON".contentEquals(command.toString().toUpperCase())
|| "1".contentEquals(command.toString())) ? "open" : "close");
}
}
if (paramType == CommandParameterType.OPENCLOSENUMBER) {
if (command instanceof OpenClosedType) {
value = new JsonPrimitive(command == OpenClosedType.OPEN ? 1 : 0);
} else {
value = new JsonPrimitive(("ON".contentEquals(command.toString().toUpperCase())
|| "1".contentEquals(command.toString())) ? 1 : 0);
}
}
if (paramType == CommandParameterType.OPENCLOSESWITCH) {
if (command instanceof OpenClosedType) {
value = new JsonPrimitive(command == OpenClosedType.OPEN ? "on" : "off");
} else {
value = new JsonPrimitive(("ON".contentEquals(command.toString().toUpperCase())
|| "1".contentEquals(command.toString())) ? "on" : "off");
}
}
if (paramType == CommandParameterType.COLOR) {
if (command instanceof HSBType) {
HSBType hsb = (HSBType) command;
@ -630,8 +654,8 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
} else {
String strVal = val.getAsString().toLowerCase();
updateState(basicChannel.getChannel(),
"on".equals(strVal) || "true".equals(strVal) || "1".equals(strVal) ? OpenClosedType.OPEN
: OpenClosedType.CLOSED);
"open".equals(strVal) || "on".equals(strVal) || "true".equals(strVal)
|| "1".equals(strVal) ? OpenClosedType.OPEN : OpenClosedType.CLOSED);
}
break;
case "color":
@ -706,6 +730,7 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
switch (response.getCommand()) {
case MIIO_INFO:
break;
case GET_DEVICE_PROPERTY_EXP:
case GET_VALUE:
case GET_PROPERTIES:
case GET_PROPERTY: