From: Cody Cutrer Date: Sun, 4 Feb 2024 10:48:20 +0000 (-0700) Subject: [plex] add ratingKey channels (#16343) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=8d8e1693f55fd3223dd526f1d1f7820aec0ec22a;p=openhab-addons.git [plex] add ratingKey channels (#16343) * [plex] add ratingKey channels useful for automations related to exactly what's playing, to avoid having to lookup based on title (which may not be unique) --------- Signed-off-by: Cody Cutrer Co-authored-by: mlobstein --- diff --git a/bundles/org.openhab.binding.plex/README.md b/bundles/org.openhab.binding.plex/README.md index 8a48f8f1c1..7fc0d81d9a 100644 --- a/bundles/org.openhab.binding.plex/README.md +++ b/bundles/org.openhab.binding.plex/README.md @@ -95,21 +95,29 @@ Find the `Device` block of the player you want to add and fill in the `clientIde ## Channels +The PLEX Server supports the following channels: + +| Channel | Type | Read/Write | Description | +|----------------------|----------|------------|------------------------------------------------------------------------------------------------------------------| +| currentPlayers | Number | RO | The number of players currently configured to watch on PLEX | +| currentPlayersActive | Number | RO | The number of players currently being used on PLEX | + The PLEX Player supports the following channels: -| Channel | Type | Read/Write | Description | -|----------------------|----------|------------|-----------------------------------------------------------------------| -| currentPlayers | Number | RO | The number of players currently configured to watch on PLEX | -| currentPlayersActive | Number | RO | The number of players currently being used on PLEX | -| state | String | RO | The current state of the Player (BUFFERING, PLAYING, PAUSED, STOPPED) | -| power | Switch | RO | The power status of the player | -| title | String | RO | The title of media that is playing | -| type | String | RO | The current type of playing media | -| endtime | DateTime | RO | Time at which the media that is playing will end | -| progress | Dimmer | RO | The current progress of playing media | -| art | String | RO | The URL of the background art for currently playing media | -| thumb | String | RO | The URL of the cover art for currently playing media | -| player | Player | RW | The control channel for the player `PLAY/PAUSE/NEXT/PREVIOUS` | +| Channel | Type | Read/Write | Description | +|----------------------|----------|------------|------------------------------------------------------------------------------------------------------------------| +| state | String | RO | The current state of the Player (BUFFERING, PLAYING, PAUSED, STOPPED) | +| power | Switch | RO | The power status of the player | +| title | String | RO | The title of media that is playing | +| type | String | RO | The current type of playing media | +| endtime | DateTime | RO | Time at which the media that is playing will end | +| progress | Dimmer | RO | The current progress of playing media | +| art | String | RO | The URL of the background art for currently playing media | +| thumb | String | RO | The URL of the cover art for currently playing media | +| player | Player | RW | The control channel for the player `PLAY/PAUSE/NEXT/PREVIOUS` | +| ratingKey | String | RO | The unique key in the Plex library identifying the media that is playing | +| parentRatingKey | String | RO | The unique key in the Plex library identifying the parent (TV show season or album) of the media that is playing | +| grandparentRatingKey | String | RO | The unique key in the Plex library identifying the grandparent (TV show) of the media that is playing | ## Full Example @@ -135,7 +143,7 @@ String PlexTVType01 "Type [%s]" {channel="ple String PlexTVEndTime01 "End time" {channel="plex:player:MyViewerName01:endtime"} Dimmer PlexTVProgress01 "Progress [%.1f%%]" {channel="plex:player:MyViewerName01:progress"} String PlexTVCover1 "Cover" {channel="plex:player:MyViewerName01:thumb"} -String ShellArt01 "Background art" {channel="plex:player:MyViewerName01:art"} +String ShellArt01 "Background art" {channel="plex:player:MyViewerName01:art"} Switch PlexTVPower02 "Power" {channel="plex:player:MyViewerName02:power"} String PlexTVStatus02 "Status [%s]" {channel="plex:player:MyViewerName02:state"} String PlexTVTitle02 "Title [%s]" {channel="plex:player:MyViewerName02:title"} diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexBindingConstants.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexBindingConstants.java index 193c007382..35f1ff57af 100644 --- a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexBindingConstants.java +++ b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexBindingConstants.java @@ -66,6 +66,9 @@ public class PlexBindingConstants { // Player public static final String CHANNEL_PLAYER_STATE = "state"; public static final String CHANNEL_PLAYER_TITLE = "title"; + public static final String CHANNEL_PLAYER_RATING_KEY = "ratingKey"; + public static final String CHANNEL_PLAYER_PARENT_RATING_KEY = "parentRatingKey"; + public static final String CHANNEL_PLAYER_GRANDPARENT_RATING_KEY = "grandparentRatingKey"; public static final String CHANNEL_PLAYER_TYPE = "type"; public static final String CHANNEL_PLAYER_POWER = "power"; public static final String CHANNEL_PLAYER_ART = "art"; diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/MediaContainer.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/MediaContainer.java index 8bc023d44f..0fb93985f2 100644 --- a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/MediaContainer.java +++ b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/MediaContainer.java @@ -73,6 +73,8 @@ public class MediaContainer { @XStreamAsAttribute private String title; @XStreamAsAttribute + private String ratingKey; + @XStreamAsAttribute private String thumb; @XStreamAsAttribute private String art; @@ -81,10 +83,14 @@ public class MediaContainer { @XStreamAsAttribute private String grandparentTitle; @XStreamAsAttribute + private String grandparentRatingKey; + @XStreamAsAttribute private String parentThumb; @XStreamAsAttribute private String parentTitle; @XStreamAsAttribute + private String parentRatingKey; + @XStreamAsAttribute private long viewOffset; @XStreamAsAttribute private String type; @@ -113,6 +119,14 @@ public class MediaContainer { this.grandparentTitle = grandparentTitle; } + public String getGrandparentRatingKey() { + return grandparentRatingKey; + } + + public void setGrandparentRatingKey(String ratingKey) { + this.grandparentRatingKey = ratingKey; + } + public String getParentThumb() { return this.parentThumb; } @@ -129,6 +143,14 @@ public class MediaContainer { this.parentTitle = parentTitle; } + public String getParentRatingKey() { + return parentRatingKey; + } + + public void setParentRatingKey(String ratingKey) { + this.parentRatingKey = ratingKey; + } + public Media getMedia() { return this.media; } @@ -145,6 +167,14 @@ public class MediaContainer { this.title = title; } + public String getRatingKey() { + return ratingKey; + } + + public void setRatingKey(String ratingKey) { + this.ratingKey = ratingKey; + } + public long getViewOffset() { return this.viewOffset; } diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/PlexSession.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/PlexSession.java index 123cd9616c..bc351a9181 100644 --- a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/PlexSession.java +++ b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/PlexSession.java @@ -42,6 +42,9 @@ public class PlexSession { private String sessionKey = ""; private Integer userId; private String userTitle = ""; + private String ratingKey; + private String parentRatingKey; + private String grandparentRatingKey; private final Logger logger = LoggerFactory.getLogger(PlexSession.class); @@ -57,6 +60,18 @@ public class PlexSession { return title; } + public String getRatingKey() { + return ratingKey; + } + + public String getParentRatingKey() { + return parentRatingKey; + } + + public String getGrandparentRatingKey() { + return grandparentRatingKey; + } + public Date getEndTime() { return endTime; } @@ -69,6 +84,18 @@ public class PlexSession { this.title = title; } + public void setRatingKey(String ratingKey) { + this.ratingKey = ratingKey; + } + + public void setParentRatingKey(String ratingKey) { + this.parentRatingKey = ratingKey; + } + + public void setGrandparentRatingKey(String ratingKey) { + this.grandparentRatingKey = ratingKey; + } + public String getThumb() { return thumb; } diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/handler/PlexPlayerHandler.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/handler/PlexPlayerHandler.java index 45a66f9b76..2ddf03a01f 100644 --- a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/handler/PlexPlayerHandler.java +++ b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/handler/PlexPlayerHandler.java @@ -139,6 +139,9 @@ public class PlexPlayerHandler extends BaseThingHandler { currentSessionData.setSessionKey(sessionData.getSessionKey()); currentSessionData.setUserId(sessionData.getUser().getId()); currentSessionData.setUserTitle(sessionData.getUser().getTitle()); + currentSessionData.setRatingKey(sessionData.getRatingKey()); + currentSessionData.setParentRatingKey(sessionData.getParentRatingKey()); + currentSessionData.setGrandparentRatingKey(sessionData.getGrandparentRatingKey()); foundInSession = true; updateStatus(ThingStatus.ONLINE); @@ -179,6 +182,14 @@ public class PlexPlayerHandler extends BaseThingHandler { new StringType(String.valueOf(foundInSession ? currentSessionData.getEndTime() : ""))); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLAYER_USER), new StringType(String.valueOf(foundInSession ? currentSessionData.getUserTitle() : ""))); + final String parentRatingKey = currentSessionData.getParentRatingKey(); + final String grandparentRatingKey = currentSessionData.getGrandparentRatingKey(); + updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLAYER_RATING_KEY), + new StringType(String.valueOf(foundInSession ? currentSessionData.getRatingKey() : ""))); + updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLAYER_PARENT_RATING_KEY), + new StringType(String.valueOf(foundInSession && parentRatingKey != null ? parentRatingKey : ""))); + updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLAYER_GRANDPARENT_RATING_KEY), new StringType( + String.valueOf(foundInSession && grandparentRatingKey != null ? grandparentRatingKey : ""))); // Make sure player control is in sync with the play state if (currentSessionData.getState() == PlexPlayerState.PLAYING) { diff --git a/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/i18n/plex.properties b/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/i18n/plex.properties index c24dfebf95..abe407141d 100644 --- a/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/i18n/plex.properties +++ b/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/i18n/plex.properties @@ -39,12 +39,18 @@ channel-type.plex.currentPlayersActive.label = Current Players Active channel-type.plex.currentPlayersActive.description = The number of players currently being used on PLEX channel-type.plex.endtime.label = End Time channel-type.plex.endtime.description = Time at which the media that is playing will end +channel-type.plex.grandparentRatingKey.label = Grandparent Rating Key +channel-type.plex.grandparentRatingKey.description = The unique key in the Plex library identifying the grandparent (TV show) of the media that is playing +channel-type.plex.parentRatingKey.label = Parent Rating Key +channel-type.plex.parentRatingKey.description = The unique key in the Plex library identifying the parent (TV show season or album) of the media that is playing channel-type.plex.player.label = Player Control channel-type.plex.player.description = The control channel for the player `PLAY/PAUSE/NEXT/PREVIOUS` channel-type.plex.power.label = Player Power State channel-type.plex.power.description = The power status of the player channel-type.plex.progress.label = Media Progress channel-type.plex.progress.description = The current progress of playing media +channel-type.plex.ratingKey.label = Rating Key +channel-type.plex.ratingKey.description = The unique key in the Plex library identifying the media that is playing channel-type.plex.state.label = Player State channel-type.plex.state.description = The current state of the Player channel-type.plex.thumb.label = Cover Art diff --git a/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/thing/thing-types.xml index 17df0f646f..76a8719180 100644 --- a/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/thing/thing-types.xml @@ -31,7 +31,13 @@ + + + + + 1 + @@ -65,6 +71,25 @@ The title of media that is playing + + String + + The unique key in the Plex library identifying the media that is playing + + + + String + + The unique key in the Plex library identifying the parent (TV show season or album) of the media that is + playing + + + + String + + The unique key in the Plex library identifying the grandparent (TV show) of the media that is playing + + String diff --git a/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/update/instructions.xml new file mode 100644 index 0000000000..1807542024 --- /dev/null +++ b/bundles/org.openhab.binding.plex/src/main/resources/OH-INF/update/instructions.xml @@ -0,0 +1,20 @@ + + + + + + + plex:ratingKey + + + plex:parentRatingKey + + + plex:grandparentRatingKey + + + + +