Skip to content

Commit

Permalink
[kodi] Add channel for KODI JSON-RPC call Input.ButtonEvent (#11181)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Schumm <[email protected]>
  • Loading branch information
thumm authored Sep 19, 2021
1 parent 8a7f15e commit b0cbefd
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.kodi/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class KodiBindingConstants {
public static final String CHANNEL_INPUT = "input";
public static final String CHANNEL_INPUTTEXT = "inputtext";
public static final String CHANNEL_INPUTACTION = "inputaction";
public static final String CHANNEL_INPUTBUTTONEVENT = "inputbuttonevent";

public static final String CHANNEL_SYSTEMCOMMAND = "systemcommand";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
updateState(CHANNEL_INPUTACTION, UnDefType.UNDEF);
}
break;
case CHANNEL_INPUTBUTTONEVENT:
logger.debug("handleCommand CHANNEL_INPUTBUTTONEVENT {}.", command);
if (command instanceof StringType) {
connection.inputButtonEvent(command.toString());
updateState(CHANNEL_INPUTBUTTONEVENT, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_INPUTBUTTONEVENT, UnDefType.UNDEF);
}
break;
case CHANNEL_SYSTEMCOMMAND:
if (command instanceof StringType) {
handleSystemCommand(command.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,46 @@ public void inputAction(String action) {
socket.callMethod("Input.ExecuteAction", params);
}

public void inputButtonEvent(String buttonEvent) {
logger.debug("inputButtonEvent {}.", buttonEvent);

String button = buttonEvent;
String keymap = "KB";
Integer holdtime = null;

if (buttonEvent.contains(";")) {
String[] params = buttonEvent.split(";");
switch (params.length) {
case 2:
button = params[0];
keymap = params[1];
break;
case 3:
button = params[0];
keymap = params[1];
try {
holdtime = Integer.parseInt(params[2]);
} catch (NumberFormatException nfe) {
holdtime = null;
}
break;
}
}

this.inputButtonEvent(button, keymap, holdtime);
}

private void inputButtonEvent(String button, String keymap, Integer holdtime) {
JsonObject params = new JsonObject();
params.addProperty("button", button);
params.addProperty("keymap", keymap);
if (holdtime != null) {
params.addProperty("holdtime", holdtime.intValue());
}
JsonElement result = socket.callMethod("Input.ButtonEvent", params);
logger.debug("inputButtonEvent result {}.", result);
}

public void getSystemProperties() {
KodiSystemProperties systemProperties = null;
if (socket.isConnected()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ channel-type.kodi.inputtext.label = Texteingabe
channel-type.kodi.inputtext.description = Ermöglicht das Senden eines Eingabetextes (Unicode) an das Kodi Media Center.
channel-type.kodi.inputaction.label = Aktion
channel-type.kodi.inputaction.description = Ermöglicht das Senden einer vordefinierten Aktion an das Kodi Media Center.
channel-type.kodi.inputbuttonevent.label = Button
channel-type.kodi.inputbuttonevent.description = Ermöglicht das Senden einer Buttonevents an das Kodi Media Center.
channel-type.kodi.systemcommand.label = Systembefehl
channel-type.kodi.systemcommand.description = Ermöglicht das Senden eines Systembefehls um das Kodi Media Center neu zu starten, in den Ruhezustand oder Stromsparmodus zu versetzen oder herunterzufahren.
channel-type.kodi.systemcommand.command.option.Shutdown = Herunterfahren
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<channel id="input" typeId="input"/>
<channel id="inputtext" typeId="inputtext"/>
<channel id="inputaction" typeId="inputaction"/>
<channel id="inputbuttonevent" typeId="inputbuttonevent"/>
<channel id="systemcommand" typeId="systemcommand"/>
<channel id="title" typeId="system.media-title"/>
<channel id="originaltitle" typeId="system.media-title"/>
Expand Down Expand Up @@ -395,6 +396,11 @@
</options>
</state>
</channel-type>
<channel-type id="inputbuttonevent" advanced="true">
<item-type>String</item-type>
<label>Sends a button press event as Input</label>
<description>Sends a generic button press event to Kodi</description>
</channel-type>
<channel-type id="systemcommand" advanced="true">
<item-type>String</item-type>
<label>Send System Command</label>
Expand Down

0 comments on commit b0cbefd

Please sign in to comment.