]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lgwebos] Actions: sendButton updated, sendRCButton removed, sendKeyboard added ...
authorlolodomo <lg.hc@free.fr>
Mon, 31 Oct 2022 18:57:46 +0000 (19:57 +0100)
committerGitHub <noreply@github.com>
Mon, 31 Oct 2022 18:57:46 +0000 (19:57 +0100)
* README: make the list of remote control buttons less specific to a model

Fix #13600

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.lgwebos/README.md
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVMouseSocket.java
bundles/org.openhab.binding.lgwebos/src/main/resources/OH-INF/i18n/lgwebos.properties

index 82e8ea929ddf499227b20f01ec329f6a494e0ccb..ae1ef859ba3ed25e6a27b9bf1509ee13eed24b82 100644 (file)
@@ -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()
index 33addc7b519357bbb1c099c611f57b20e0f4140a..d9af4fe8d5e2a5081534f194c7902194502cfdcf 100644 (file)
@@ -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<LGWebOSTVSocket> 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);
-    }
 }
index bc8462f77f8532ebd8ae396bd120d09eec23da4a..356164cdb15f532bfd6e62ec6b08e4b273aa6d81 100644 (file)
@@ -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;
index dca1a52701dd66607b42c79afac14026c34435ae..361f4d17ce974985587ea5e87e376da08e12e367 100644 (file)
@@ -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