]> git.basschouten.com Git - openhab-addons.git/commitdiff
[kodi] Add channel for KODI JSON-RPC call Input.ButtonEvent (#11181)
authorThomas <thomas.schumm@yahoo.de>
Sun, 19 Sep 2021 19:59:19 +0000 (21:59 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Sep 2021 19:59:19 +0000 (21:59 +0200)
Signed-off-by: Thomas Schumm <thomas.schumm@yahoo.de>
bundles/org.openhab.binding.kodi/README.md
bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/KodiBindingConstants.java
bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/handler/KodiHandler.java
bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiConnection.java
bundles/org.openhab.binding.kodi/src/main/resources/OH-INF/i18n/kodi_de.properties
bundles/org.openhab.binding.kodi/src/main/resources/OH-INF/thing/thing-types.xml

index 5cf912208ef5feadde26c35ca62441607fec3f5c..35653967854ae61f61ce6f7eede6769154a8e2e9 100644 (file)
@@ -83,6 +83,7 @@ The Kodi thing supports the following channels:
 | input                 | String               | Sends a key stroke to Kodi to navigate in the UI. Valid commands are: `Back`, `ContextMenu`, `Down`, `Home`, `Info`, `Left`, `Right`, `Select`, `ShowCodec`, `ShowOSD`, `ShowPlayerProcessInfo` and `Up`. `ExecuteAction` and `SendText` should be used with the dedicated channels `inputaction` and `inputtext`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
 | inputtext             | String               | Sends a generic input (unicode) text to Kodi.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
 | inputaction           | String               | Sends a predefined action to Kodi to control the UI and/or perform other tasks. Valid commands are: `left`, `right`, `up`, `down`, `pageup`, `pagedown`, `select`, `highlight`, `parentdir`, `parentfolder`, `back`, `menu`, `previousmenu`, `info`, `pause`, `stop`, `skipnext`, `skipprevious`, `fullscreen`, `aspectratio`, `stepforward`, `stepback`, `bigstepforward`, `bigstepback`, `chapterorbigstepforward`, `chapterorbigstepback`, `osd`, `showsubtitles`, `nextsubtitle`, `cyclesubtitle`, `playerdebug`, `codecinfo`, `playerprocessinfo`, `nextpicture`, `previouspicture`, `zoomout`, `zoomin`, `playlist`, `queue`, `zoomnormal`, `zoomlevel1`, `zoomlevel2`, `zoomlevel3`, `zoomlevel4`, `zoomlevel5`, `zoomlevel6`, `zoomlevel7`, `zoomlevel8`, `zoomlevel9`, `nextcalibration`, `resetcalibration`, `analogmove`, `analogmovex`, `analogmovey`, `rotate`, `rotateccw`, `close`, `subtitledelayminus`, `subtitledelay`, `subtitledelayplus`, `audiodelayminus`, `audiodelay`, `audiodelayplus`, `subtitleshiftup`, `subtitleshiftdown`, `subtitlealign`, `audionextlanguage`, `verticalshiftup`, `verticalshiftdown`, `nextresolution`, `audiotoggledigital`, `number0`, `number1`, `number2`, `number3`, `number4`, `number5`, `number6`, `number7`, `number8`, `number9`, `smallstepback`, `fastforward`, `rewind`, `play`, `playpause`, `switchplayer`, `delete`, `copy`, `move`, `screenshot`, `rename`, `togglewatched`, `scanitem`, `reloadkeymaps`, `volumeup`, `volumedown`, `mute`, `backspace`, `scrollup`, `scrolldown`, `analogfastforward`, `analogrewind`, `moveitemup`, `moveitemdown`, `contextmenu`, `shift`, `symbols`, `cursorleft`, `cursorright`, `showtime`, `analogseekforward`, `analogseekback`, `showpreset`, `nextpreset`, `previouspreset`, `lockpreset`, `randompreset`, `increasevisrating`, `decreasevisrating`, `showvideomenu`, `enter`, `increaserating`, `decreaserating`, `setrating`, `togglefullscreen`, `nextscene`, `previousscene`, `nextletter`, `prevletter`, `jumpsms2`, `jumpsms3`, `jumpsms4`, `jumpsms5`, `jumpsms6`, `jumpsms7`, `jumpsms8`, `jumpsms9`, `filter`, `filterclear`, `filtersms2`, `filtersms3`, `filtersms4`, `filtersms5`, `filtersms6`, `filtersms7`, `filtersms8`, `filtersms9`, `firstpage`, `lastpage`, `guiprofile`, `red`, `green`, `yellow`, `blue`, `increasepar`, `decreasepar`, `volampup`, `volampdown`, `volumeamplification`, `createbookmark`, `createepisodebookmark`, `settingsreset`, `settingslevelchange`, `stereomode`, `nextstereomode`, `previousstereomode`, `togglestereomode`, `stereomodetomono`, `channelup`, `channeldown`, `previouschannelgroup`, `nextchannelgroup`, `playpvr`, `playpvrtv`, `playpvrradio`, `record`, `togglecommskip`, `showtimerrule`, `leftclick`, `rightclick`, `middleclick`, `doubleclick`, `longclick`, `wheelup`, `wheeldown`, `mousedrag`, `mousemove`, `tap`, `longpress`, `pangesture`, `zoomgesture`, `rotategesture`, `swipeleft`, `swiperight`, `swipeup`, `swipedown`, `error`, `noop`. |
+| inputbuttonevent      | String               | Send a button press event. The parameter can have the format "`<button>`", "`<button>;<keymap>`" or "`<button>;<keymap>;<holdtime>`". For details see https://kodi.wiki/view/JSON-RPC_API/v12#Input.ButtonEvent                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
 | systemcommand         | String               | This channel allows to send system commands to `Shutdown`, `Suspend`, `Hibernate`, `Reboot` or `Quit` Kodi (channel's state options contains available system commands)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
 | mediatype             | String               | The media type of the current file. Valid return values are: `unknown`, `channel`, `episode`, `movie`, `musicvideo`, `picture`, `radio`, `song`, `video`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
 | mediaid               | Number               | The media_id in database of Kodi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
index 835093340aa49e2d88e72ef0c07b4fdfedd29504..268e68c546bbc73d2c071e8445199d171c3a2bdb 100644 (file)
@@ -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";
 
index b31d5b3cccd4c7d674706dbaad981be7f0a91d50..152374b68718105d05e61d0f836c0a3e48b96fc6 100644 (file)
@@ -262,6 +262,15 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
                     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());
index 4469fadd0102d0f8cc63ce37269e90284a4e5636..ed9f53e48ab5794ec2f49347c3d8c65724ca052a 100644 (file)
@@ -1327,6 +1327,46 @@ public class KodiConnection implements KodiClientSocketEventListener {
         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()) {
index d21e288ff4f01c7076acb423841054bee3aeb3ea..7d9d3e3b2bc877f75b9fce24404ddff2692c71fd 100644 (file)
@@ -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
index 8f9db6734d3ebf51e19d6dbd2bfd4ee8db3498b7..ba204041dbbbd4de8b4cc4bcd01104b6a326f216 100644 (file)
@@ -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"/>
                        </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>