]> git.basschouten.com Git - openhab-addons.git/commitdiff
[plex] add ratingKey channels (#16343)
authorCody Cutrer <cody@cutrer.us>
Sun, 4 Feb 2024 10:48:20 +0000 (03:48 -0700)
committerGitHub <noreply@github.com>
Sun, 4 Feb 2024 10:48:20 +0000 (11:48 +0100)
* [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 <cody@cutrer.us>
Co-authored-by: mlobstein <github@lobstein.org>
bundles/org.openhab.binding.plex/README.md
bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexBindingConstants.java
bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/MediaContainer.java
bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/dto/PlexSession.java
bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/handler/PlexPlayerHandler.java
bundles/org.openhab.binding.plex/src/main/resources/OH-INF/i18n/plex.properties
bundles/org.openhab.binding.plex/src/main/resources/OH-INF/thing/thing-types.xml
bundles/org.openhab.binding.plex/src/main/resources/OH-INF/update/instructions.xml [new file with mode: 0644]

index 8a48f8f1c114f4d6654cfcc92ebb5259584be59a..7fc0d81d9ad8806fb29252fc3af46d7e3fea2dcf 100644 (file)
@@ -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"}
index 193c0073825312d2294ea5eb69371eea4292c70c..35f1ff57af280d7b015c6147ec092596917fcfa2 100644 (file)
@@ -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";
index 8bc023d44fc5c0035a0d6e557ca4b662f27efd60..0fb93985f284df9524871696d2a436dc08bf177a 100644 (file)
@@ -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;
         }
index 123cd9616ca1013658edd322c7ad94f396e55cc4..bc351a9181aa69ff1baeac29f8aca1638a580bc7 100644 (file)
@@ -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;
     }
index 45a66f9b76e9641710bf026cb6699d343f366ecb..2ddf03a01f39cfa4556d4382f0d55cac5502f3d6 100644 (file)
@@ -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) {
index c24dfebf958e07b3dcbb0730957be3bc4b3ecd68..abe407141d72368031312c8021159153829bd8f8 100644 (file)
@@ -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
index 17df0f646f0dd1ed1fa132fc5fab4ced2e5093ef..76a87191804d16413d002a11dcbb009f73416b52 100644 (file)
                        <channel id="thumb" typeId="thumb"/>
                        <channel id="player" typeId="player"/>
                        <channel id="user" typeId="user"/>
+                       <channel id="ratingKey" typeId="ratingKey"/>
+                       <channel id="parentRatingKey" typeId="parentRatingKey"/>
+                       <channel id="grandparentRatingKey" typeId="grandparentRatingKey"/>
                </channels>
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
                <config-description-ref uri="thing-type:plex:player"/>
        </thing-type>
 
                <description>The title of media that is playing</description>
                <state readOnly="true"/>
        </channel-type>
+       <channel-type id="ratingKey" advanced="true">
+               <item-type>String</item-type>
+               <label>Rating Key</label>
+               <description>The unique key in the Plex library identifying the media that is playing</description>
+               <state readOnly="true"/>
+       </channel-type>
+       <channel-type id="parentRatingKey" advanced="true">
+               <item-type>String</item-type>
+               <label>Parent Rating Key</label>
+               <description>The unique key in the Plex library identifying the parent (TV show season or album) of the media that is
+                       playing</description>
+               <state readOnly="true"/>
+       </channel-type>
+       <channel-type id="grandparentRatingKey" advanced="true">
+               <item-type>String</item-type>
+               <label>Grandparent Rating Key</label>
+               <description>The unique key in the Plex library identifying the grandparent (TV show) of the media that is playing</description>
+               <state readOnly="true"/>
+       </channel-type>
        <channel-type id="type">
                <item-type>String</item-type>
                <label>Media Type</label>
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 (file)
index 0000000..1807542
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
+
+       <thing-type uid="plex:player">
+               <instruction-set targetVersion="1">
+                       <add-channel id="ratingKey">
+                               <type>plex:ratingKey</type>
+                       </add-channel>
+                       <add-channel id="parentRatingKey">
+                               <type>plex:parentRatingKey</type>
+                       </add-channel>
+                       <add-channel id="grandparentRatingKey">
+                               <type>plex:grandparentRatingKey</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+
+</update:update-descriptions>