From b6c073d088032f0834aaac2e8768dc448acb720a Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 31 Oct 2022 19:57:46 +0100 Subject: [PATCH] [lgwebos] Actions: sendButton updated, sendRCButton removed, sendKeyboard added (#13618) * README: make the list of remote control buttons less specific to a model Fix #13600 Signed-off-by: Laurent Garnier --- bundles/org.openhab.binding.lgwebos/README.md | 31 +++++++-- .../internal/action/LGWebOSActions.java | 65 ++++++------------- .../handler/LGWebOSTVMouseSocket.java | 8 +++ .../resources/OH-INF/i18n/lgwebos.properties | 10 +-- 4 files changed, 58 insertions(+), 56 deletions(-) diff --git a/bundles/org.openhab.binding.lgwebos/README.md b/bundles/org.openhab.binding.lgwebos/README.md index 82e8ea929d..ae1ef859ba 100644 --- a/bundles/org.openhab.binding.lgwebos/README.md +++ b/bundles/org.openhab.binding.lgwebos/README.md @@ -70,8 +70,8 @@ Here are examples of values that could be available for your TV: airplay, amazon ### Remote Control Buttons -The rcButton channel has only been tested on an LGUJ657A TV. and this is a list of button codes that are known to work with this device. -This list has been compiled mostly through trial and error. Your mileage may vary. +This is a list of button codes that are known to work with several LG WebOS TV models. +This list has been compiled mostly through trial and error, but the codes applicable to your model may vary. | Code String | Description | |-------------|----------------------------------------------------------| @@ -314,14 +314,33 @@ Sends a button press event to a WebOS device. Parameters: -| Name | Description | -|---------|------------------------------------------------------------------------| -| button | Can be one of UP, DOWN, LEFT, RIGHT, BACK, DELETE, ENTER, HOME, or OK | +| Name | Description | +|---------|------------------------------------------------------------------------------------------------| +| button | Can be one of UP, DOWN, LEFT, RIGHT, BACK, EXIT, ENTER, HOME, OK or any other supported value. | Example: ``` -actions.sendButton("OK") +actions.sendButton("HOME") +``` + +### sendKeyboard(key) + +Sends a keyboard input to the WebOS on-screen keyboard. + +Parameters: + +| Name | Description | +|---------|--------------------------------| +| key | Can be either DELETE or ENTER. | + +DELETE will delete the last character when on-screen keyboard is displayed with focus in the text field. +ENTER will remove the keyboard when on-screen keyboard is displayed with focus in the text field. + +Example: + +``` +actions.sendKeyboard("ENTER") ``` ### increaseChannel() diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java index 33addc7b51..d9af4fe8d5 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java @@ -30,7 +30,6 @@ import javax.imageio.ImageIO; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.lgwebos.internal.handler.LGWebOSHandler; -import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVMouseSocket.ButtonType; import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket; import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket.State; import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription; @@ -82,16 +81,9 @@ public class LGWebOSActions implements ThingActions { return lgWebOSHandler; } - private enum Button { - UP, - DOWN, - LEFT, - RIGHT, - BACK, + private enum Key { DELETE, - ENTER, - HOME, - OK + ENTER } @RuleAction(label = "@text/actionShowToastLabel", description = "@text/actionShowToastDesc") @@ -182,40 +174,29 @@ public class LGWebOSActions implements ThingActions { @RuleAction(label = "@text/actionSendButtonLabel", description = "@text/actionSendButtonDesc") public void sendButton( - @ActionInput(name = "text", label = "@text/actionSendButtonInputButtonLabel", description = "@text/actionSendButtonInputButtonDesc") String button) { + @ActionInput(name = "button", label = "@text/actionSendButtonInputButtonLabel", description = "@text/actionSendButtonInputButtonDesc") String button) { + if ("OK".equals(button)) { + getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.click())); + } else { + getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(button))); + } + } + + @RuleAction(label = "@text/actionSendKeyboardLabel", description = "@text/actionSendKeyboardDesc") + public void sendKeyboard( + @ActionInput(name = "key", label = "@text/actionSendKeyboardInputKeyLabel", description = "@text/actionSendKeyboardInputKeyDesc") String key) { try { - switch (Button.valueOf(button)) { - case UP: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(ButtonType.UP))); - break; - case DOWN: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(ButtonType.DOWN))); - break; - case LEFT: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(ButtonType.LEFT))); - break; - case RIGHT: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(ButtonType.RIGHT))); - break; - case BACK: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(ButtonType.BACK))); - break; + switch (Key.valueOf(key)) { case DELETE: getConnectedSocket().ifPresent(control -> control.sendDelete()); break; case ENTER: getConnectedSocket().ifPresent(control -> control.sendEnter()); break; - case HOME: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button("HOME"))); - break; - case OK: - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.click())); - break; } } catch (IllegalArgumentException ex) { - logger.warn("{} is not a valid value for button - available are: {}", button, - Stream.of(Button.values()).map(b -> b.name()).collect(Collectors.joining(", "))); + logger.warn("{} is not a valid value for key - available are: {}", key, + Stream.of(Key.values()).map(b -> b.name()).collect(Collectors.joining(", "))); } } @@ -229,12 +210,6 @@ public class LGWebOSActions implements ThingActions { getConnectedSocket().ifPresent(control -> control.channelDown(createResponseListener())); } - @RuleAction(label = "@text/actionSendRCButtonLabel", description = "@text/actionSendRCButtonDesc") - public void sendRCButton( - @ActionInput(name = "text", label = "@text/actionSendRCButtonInputTextLabel", description = "@text/actionSendRCButtonInputTextDesc") String rcButton) { - getConnectedSocket().ifPresent(control -> control.executeMouse(s -> s.button(rcButton))); - } - private Optional getConnectedSocket() { LGWebOSHandler lgWebOSHandler = getLGWebOSHandler(); final LGWebOSTVSocket socket = lgWebOSHandler.getSocket(); @@ -307,6 +282,10 @@ public class LGWebOSActions implements ThingActions { ((LGWebOSActions) actions).sendButton(button); } + public static void sendKeyboard(ThingActions actions, String key) { + ((LGWebOSActions) actions).sendKeyboard(key); + } + public static void increaseChannel(ThingActions actions) { ((LGWebOSActions) actions).increaseChannel(); } @@ -314,8 +293,4 @@ public class LGWebOSActions implements ThingActions { public static void decreaseChannel(ThingActions actions) { ((LGWebOSActions) actions).decreaseChannel(); } - - public static void sendRCButton(ThingActions actions, String rcButton) { - ((LGWebOSActions) actions).sendRCButton(rcButton); - } } diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVMouseSocket.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVMouseSocket.java index bc8462f77f..356164cdb1 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVMouseSocket.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVMouseSocket.java @@ -48,7 +48,9 @@ public class LGWebOSTVMouseSocket { public enum ButtonType { HOME, + ENTER, BACK, + EXIT, UP, DOWN, LEFT, @@ -164,9 +166,15 @@ public class LGWebOSTVMouseSocket { case HOME: keyName = "HOME"; break; + case ENTER: + keyName = "ENTER"; + break; case BACK: keyName = "BACK"; break; + case EXIT: + keyName = "EXIT"; + break; case UP: keyName = "UP"; break; diff --git a/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties b/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties index dca1a52701..361f4d17ce 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties +++ b/bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties @@ -51,11 +51,11 @@ actionLaunchBrowserInputUrlDesc = The URL to open actionSendButtonLabel = send a button press actionSendButtonDesc = Sends a button press event to a WebOS device. actionSendButtonInputButtonLabel = Button -actionSendButtonInputButtonDesc = Can be one of UP, DOWN, LEFT, RIGHT, BACK, DELETE, ENTER, HOME, or OK -actionSendRCButtonLabel = simulate remote control button press -actionSendRCButtonDesc = Simulates pressing of a Remote Control Button. -actionSendRCButtonInputTextLabel = Remote Control button name -actionSendRCButtonInputTextDesc = The Remote Control button name to send to the WebOS device. +actionSendButtonInputButtonDesc = Can be one of UP, DOWN, LEFT, RIGHT, BACK, EXIT, ENTER, HOME, OK or any other supported value. +actionSendKeyboardLabel = send a keyboard input +actionSendKeyboardDesc = Sends a keyboard input to the WebOS on-screen keyboard. +actionSendKeyboardInputKeyLabel = Key +actionSendKeyboardInputKeyDesc = Can be either DELETE or ENTER. actionSendTextLabel = send a text input actionSendTextDesc = Sends a text input to a WebOS device. actionSendTextInputTextLabel = Text -- 2.47.3