[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 <lg.hc@free.fr>
This commit is contained in:
lolodomo
2022-10-31 19:57:46 +01:00
committed by GitHub
parent ec90a091c6
commit b6c073d088
4 changed files with 58 additions and 56 deletions

View File

@@ -70,8 +70,8 @@ Here are examples of values that could be available for your TV: airplay, amazon
### Remote Control Buttons ### 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 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. Your mileage may vary. This list has been compiled mostly through trial and error, but the codes applicable to your model may vary.
| Code String | Description | | Code String | Description |
|-------------|----------------------------------------------------------| |-------------|----------------------------------------------------------|
@@ -315,13 +315,32 @@ Sends a button press event to a WebOS device.
Parameters: Parameters:
| Name | Description | | Name | Description |
|---------|------------------------------------------------------------------------| |---------|------------------------------------------------------------------------------------------------|
| button | Can be one of UP, DOWN, LEFT, RIGHT, BACK, DELETE, ENTER, HOME, or OK | | button | Can be one of UP, DOWN, LEFT, RIGHT, BACK, EXIT, ENTER, HOME, OK or any other supported value. |
Example: 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() ### increaseChannel()

View File

@@ -30,7 +30,6 @@ import javax.imageio.ImageIO;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lgwebos.internal.handler.LGWebOSHandler; 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;
import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket.State; import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket.State;
import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription; import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription;
@@ -82,16 +81,9 @@ public class LGWebOSActions implements ThingActions {
return lgWebOSHandler; return lgWebOSHandler;
} }
private enum Button { private enum Key {
UP,
DOWN,
LEFT,
RIGHT,
BACK,
DELETE, DELETE,
ENTER, ENTER
HOME,
OK
} }
@RuleAction(label = "@text/actionShowToastLabel", description = "@text/actionShowToastDesc") @RuleAction(label = "@text/actionShowToastLabel", description = "@text/actionShowToastDesc")
@@ -182,40 +174,29 @@ public class LGWebOSActions implements ThingActions {
@RuleAction(label = "@text/actionSendButtonLabel", description = "@text/actionSendButtonDesc") @RuleAction(label = "@text/actionSendButtonLabel", description = "@text/actionSendButtonDesc")
public void sendButton( 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 { try {
switch (Button.valueOf(button)) { switch (Key.valueOf(key)) {
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;
case DELETE: case DELETE:
getConnectedSocket().ifPresent(control -> control.sendDelete()); getConnectedSocket().ifPresent(control -> control.sendDelete());
break; break;
case ENTER: case ENTER:
getConnectedSocket().ifPresent(control -> control.sendEnter()); getConnectedSocket().ifPresent(control -> control.sendEnter());
break; 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) { } catch (IllegalArgumentException ex) {
logger.warn("{} is not a valid value for button - available are: {}", button, logger.warn("{} is not a valid value for key - available are: {}", key,
Stream.of(Button.values()).map(b -> b.name()).collect(Collectors.joining(", "))); 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())); 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() { private Optional<LGWebOSTVSocket> getConnectedSocket() {
LGWebOSHandler lgWebOSHandler = getLGWebOSHandler(); LGWebOSHandler lgWebOSHandler = getLGWebOSHandler();
final LGWebOSTVSocket socket = lgWebOSHandler.getSocket(); final LGWebOSTVSocket socket = lgWebOSHandler.getSocket();
@@ -307,6 +282,10 @@ public class LGWebOSActions implements ThingActions {
((LGWebOSActions) actions).sendButton(button); ((LGWebOSActions) actions).sendButton(button);
} }
public static void sendKeyboard(ThingActions actions, String key) {
((LGWebOSActions) actions).sendKeyboard(key);
}
public static void increaseChannel(ThingActions actions) { public static void increaseChannel(ThingActions actions) {
((LGWebOSActions) actions).increaseChannel(); ((LGWebOSActions) actions).increaseChannel();
} }
@@ -314,8 +293,4 @@ public class LGWebOSActions implements ThingActions {
public static void decreaseChannel(ThingActions actions) { public static void decreaseChannel(ThingActions actions) {
((LGWebOSActions) actions).decreaseChannel(); ((LGWebOSActions) actions).decreaseChannel();
} }
public static void sendRCButton(ThingActions actions, String rcButton) {
((LGWebOSActions) actions).sendRCButton(rcButton);
}
} }

View File

@@ -48,7 +48,9 @@ public class LGWebOSTVMouseSocket {
public enum ButtonType { public enum ButtonType {
HOME, HOME,
ENTER,
BACK, BACK,
EXIT,
UP, UP,
DOWN, DOWN,
LEFT, LEFT,
@@ -164,9 +166,15 @@ public class LGWebOSTVMouseSocket {
case HOME: case HOME:
keyName = "HOME"; keyName = "HOME";
break; break;
case ENTER:
keyName = "ENTER";
break;
case BACK: case BACK:
keyName = "BACK"; keyName = "BACK";
break; break;
case EXIT:
keyName = "EXIT";
break;
case UP: case UP:
keyName = "UP"; keyName = "UP";
break; break;

View File

@@ -51,11 +51,11 @@ actionLaunchBrowserInputUrlDesc = The URL to open
actionSendButtonLabel = send a button press actionSendButtonLabel = send a button press
actionSendButtonDesc = Sends a button press event to a WebOS device. actionSendButtonDesc = Sends a button press event to a WebOS device.
actionSendButtonInputButtonLabel = Button actionSendButtonInputButtonLabel = Button
actionSendButtonInputButtonDesc = Can be one of UP, DOWN, LEFT, RIGHT, BACK, DELETE, ENTER, HOME, or OK actionSendButtonInputButtonDesc = Can be one of UP, DOWN, LEFT, RIGHT, BACK, EXIT, ENTER, HOME, OK or any other supported value.
actionSendRCButtonLabel = simulate remote control button press actionSendKeyboardLabel = send a keyboard input
actionSendRCButtonDesc = Simulates pressing of a Remote Control Button. actionSendKeyboardDesc = Sends a keyboard input to the WebOS on-screen keyboard.
actionSendRCButtonInputTextLabel = Remote Control button name actionSendKeyboardInputKeyLabel = Key
actionSendRCButtonInputTextDesc = The Remote Control button name to send to the WebOS device. actionSendKeyboardInputKeyDesc = Can be either DELETE or ENTER.
actionSendTextLabel = send a text input actionSendTextLabel = send a text input
actionSendTextDesc = Sends a text input to a WebOS device. actionSendTextDesc = Sends a text input to a WebOS device.
actionSendTextInputTextLabel = Text actionSendTextInputTextLabel = Text