Skip to content

Commit

Permalink
[miio] support sending openclose commands (#11581)
Browse files Browse the repository at this point in the history
* [miio] support sending openclose commands

Signed-off-by: Marcel Verpaalen <[email protected]>

* [miio] fix contact sending

Signed-off-by: Marcel Verpaalen <[email protected]>

* [miio] switch

Signed-off-by: Marcel Verpaalen <[email protected]>
  • Loading branch information
marcelrv authored Nov 14, 2021
1 parent edafc19 commit 4d8c6b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ public void handleCommand(ChannelUID channelUID, Command receivedCommand) {
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;
Expand Down Expand Up @@ -630,8 +654,8 @@ private void updateChannel(@Nullable MiIoBasicChannel basicChannel, String param
} 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":
Expand Down Expand Up @@ -706,6 +730,7 @@ public void onMessageReceived(MiIoSendCommand response) {
switch (response.getCommand()) {
case MIIO_INFO:
break;
case GET_DEVICE_PROPERTY_EXP:
case GET_VALUE:
case GET_PROPERTIES:
case GET_PROPERTY:
Expand Down

0 comments on commit 4d8c6b3

Please sign in to comment.