[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
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()

View 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);
}
}

View 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;

View 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