Add channels for screensaver state and virtual keyboard state (#11984)

Include OnAVStart for playing state detection

Fixes: #7542

Signed-off-by: Flole <flole@flole.de>
This commit is contained in:
Flole998 2022-01-22 22:34:48 +01:00 committed by GitHub
parent dd08a2a1e3
commit 158f8341d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 5 deletions

View File

@ -84,6 +84,8 @@ The Kodi thing supports the following channels:
| 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 |
| inputrequested | Switch | Indicates whether Kodi is currently asking the user for input |
| screensaver | Switch | Current state of the Screensaver |
| 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 |

View File

@ -45,6 +45,8 @@ public class KodiBindingConstants {
public static final String REFRESH_PARAMETER = "refreshInterval";
// List of all Channel ids
public static final String CHANNEL_SCREENSAVER = "screensaver";
public static final String CHANNEL_INPUTREQUESTED = "inputrequested";
public static final String CHANNEL_MUTE = "mute";
public static final String CHANNEL_VOLUME = "volume";
public static final String CHANNEL_STOP = "stop";

View File

@ -51,7 +51,9 @@ public interface KodiEventListener extends EventListener {
void updateConnectionState(boolean connected);
void updateScreenSaverState(boolean screenSaveActive);
void updateScreenSaverState(boolean screenSaverActive);
void updateInputRequestedState(boolean inputRequested);
void updatePlaylistState(KodiPlaylistState playlistState);

View File

@ -91,6 +91,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
private final KodiDynamicCommandDescriptionProvider commandDescriptionProvider;
private final KodiDynamicStateDescriptionProvider stateDescriptionProvider;
private final ChannelUID screenSaverChannelUID;
private final ChannelUID inputRequestedChannelUID;
private final ChannelUID volumeChannelUID;
private final ChannelUID mutedChannelUID;
private final ChannelUID favoriteChannelUID;
@ -108,6 +110,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
this.commandDescriptionProvider = commandDescriptionProvider;
this.stateDescriptionProvider = stateDescriptionProvider;
screenSaverChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_SCREENSAVER);
inputRequestedChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_INPUTREQUESTED);
volumeChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_VOLUME);
mutedChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_MUTE);
favoriteChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_PLAYFAVORITE);
@ -141,6 +145,11 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_SCREENSAVER:
if (RefreshType.REFRESH == command) {
connection.updateScreenSaverState();
}
break;
case CHANNEL_MUTE:
if (command.equals(OnOffType.ON)) {
connection.setMute(true);
@ -741,7 +750,13 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
}
@Override
public void updateScreenSaverState(boolean screenSaveActive) {
public void updateScreenSaverState(boolean screenSaverActive) {
updateState(screenSaverChannelUID, OnOffType.from(screenSaverActive));
}
@Override
public void updateInputRequestedState(boolean inputRequested) {
updateState(inputRequestedChannelUID, OnOffType.from(inputRequested));
}
@Override

View File

@ -67,6 +67,7 @@ public class KodiConnection implements KodiClientSocketEventListener {
private static final String PROPERTY_FANART = "fanart";
private static final String PROPERTY_THUMBNAIL = "thumbnail";
private static final String PROPERTY_VERSION = "version";
private static final String PROPERTY_SCREENSAVER = "System.ScreensaverActive";
private static final String PROPERTY_VOLUME = "volume";
private static final String PROPERTY_MUTED = "muted";
private static final String PROPERTY_TOTALTIME = "totaltime";
@ -978,7 +979,9 @@ public class KodiConnection implements KodiClientSocketEventListener {
} else if (method.startsWith("System.On")) {
processSystemStateChanged(method, params);
} else if (method.startsWith("GUI.OnScreensaver")) {
processScreensaverStateChanged(method, params);
processScreenSaverStateChanged(method, params);
} else if (method.startsWith("Input.OnInput")) {
processInputRequestedStateChanged(method, params);
} else if (method.startsWith("Playlist.On")) {
processPlaylistStateChanged(method, params);
} else {
@ -988,7 +991,7 @@ public class KodiConnection implements KodiClientSocketEventListener {
}
private void processPlayerStateChanged(String method, JsonObject json) {
if ("Player.OnPlay".equals(method)) {
if ("Player.OnPlay".equals(method) || "Player.OnAVStart".equals(method)) {
// get the player id and make a new request for the media details
JsonObject data = json.get("data").getAsJsonObject();
@ -1059,7 +1062,7 @@ public class KodiConnection implements KodiClientSocketEventListener {
}
}
private void processScreensaverStateChanged(String method, JsonObject json) {
private void processScreenSaverStateChanged(String method, JsonObject json) {
if ("GUI.OnScreensaverDeactivated".equals(method)) {
listener.updateScreenSaverState(false);
} else if ("GUI.OnScreensaverActivated".equals(method)) {
@ -1070,6 +1073,17 @@ public class KodiConnection implements KodiClientSocketEventListener {
listener.updateConnectionState(true);
}
private void processInputRequestedStateChanged(String method, JsonObject json) {
if ("Input.OnInputFinished".equals(method)) {
listener.updateInputRequestedState(false);
} else if ("Input.OnInputRequested".equals(method)) {
listener.updateInputRequestedState(true);
} else {
logger.debug("Unknown event from Kodi {}: {}", method, json);
}
listener.updateConnectionState(true);
}
private void processPlaylistStateChanged(String method, JsonObject json) {
if ("Playlist.OnAdd".equals(method)) {
currentPlaylistState = KodiPlaylistState.ADDED;
@ -1091,6 +1105,25 @@ public class KodiConnection implements KodiClientSocketEventListener {
}
}
public void updateScreenSaverState() {
if (socket.isConnected()) {
String[] props = { PROPERTY_SCREENSAVER };
JsonObject params = new JsonObject();
params.add("booleans", getJsonArray(props));
JsonElement response = socket.callMethod("XBMC.GetInfoBooleans", params);
if (response instanceof JsonObject) {
JsonObject data = response.getAsJsonObject();
if (data.has(PROPERTY_SCREENSAVER)) {
listener.updateScreenSaverState(data.get(PROPERTY_SCREENSAVER).getAsBoolean());
}
}
} else {
listener.updateScreenSaverState(false);
}
}
public void updateVolume() {
if (socket.isConnected()) {
String[] props = { PROPERTY_VOLUME, PROPERTY_MUTED };

View File

@ -311,6 +311,8 @@ channel-type.kodi.inputaction.state.option.error = error
channel-type.kodi.inputaction.state.option.noop = noop
channel-type.kodi.inputbuttonevent.label = Sends a button press event as Input
channel-type.kodi.inputbuttonevent.description = Sends a generic button press event to Kodi
channel-type.kodi.inputrequested.label = Input requested
channel-type.kodi.inputrequested.description = Status that shows if Kodi is asking for user input.
channel-type.kodi.inputtext.label = Sends Text as Input
channel-type.kodi.inputtext.description = Sends a generic input (unicode) text to Kodi
channel-type.kodi.language.label = Language
@ -337,6 +339,8 @@ channel-type.kodi.pvr-open-tv.label = Play PVR TV
channel-type.kodi.pvr-open-tv.description = Play the given PVR TV channel by sending a command with the channel's name
channel-type.kodi.rating.label = Rating
channel-type.kodi.rating.description = Rating
channel-type.kodi.screensaver.label = Screensaver
channel-type.kodi.screensaver.description = Status of the screensaver
channel-type.kodi.shownotification.label = Show Notification
channel-type.kodi.shownotification.description = Shows a notification on the UI
channel-type.kodi.showtitle.label = Show Title

View File

@ -110,6 +110,8 @@
<channel id="userrating" typeId="rating">
<label>User Rating</label>
</channel>
<channel id="screensaver" typeId="screensaver"/>
<channel id="inputrequested" typeId="inputrequested"/>
</channels>
<properties>
@ -560,4 +562,16 @@
<description>Profile of Kodi</description>
<state pattern="%s"/>
</channel-type>
<channel-type id="screensaver">
<item-type>Switch</item-type>
<label>Screensaver</label>
<description>Status of the screensaver</description>
<state readOnly="true"/>
</channel-type>
<channel-type id="inputrequested">
<item-type>Switch</item-type>
<label>Input requested</label>
<description>Status that shows if Kodi is asking for user input.</description>
<state readOnly="true"/>
</channel-type>
</thing:thing-descriptions>