]> git.basschouten.com Git - openhab-addons.git/commitdiff
[feed] added channel for enclosure link on latest entry (#11345)
authorJürgen Pabel <juergenpabel@users.noreply.github.com>
Sat, 9 Oct 2021 16:32:44 +0000 (18:32 +0200)
committerGitHub <noreply@github.com>
Sat, 9 Oct 2021 16:32:44 +0000 (18:32 +0200)
Signed-off-by: Juergen Pabel <juergen@pabel.net>
bundles/org.openhab.binding.feed/README.md
bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/FeedBindingConstants.java
bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/handler/FeedHandler.java
bundles/org.openhab.binding.feed/src/main/resources/OH-INF/thing/thing-types.xml

index 686d3e9f597f03420a10adb9e01b468e07482a8b..d1f5d0f7f339c45f774c8c3c81667ebb9f86ee8b 100644 (file)
@@ -32,17 +32,18 @@ Optional configuration:
 
 The binding supports following channels
 
-| Channel Type ID    | Item Type | Description                                         |
-|--------------------|-----------|-----------------------------------------------------|
-| latest-title       | String    | Contains the title of the last feed entry.          |
-| latest-description | String    | Contains the description of the last feed entry.    |
-| latest-date        | DateTime  | Contains the published date of the last feed entry. |
-| latest-link        | String    | Contains the link of the last feed entry.           |
-| author             | String    | The name of the feed author, if author is present.  |
-| title              | String    | The title of the feed.                              |
-| description        | String    | Description of the feed.                            |
-| last-update        | DateTime  | The last update date of the feed.                   |
-| number-of-entries  | Number    | Number of entries in the feed.                      |
+| Channel Type ID    | Item Type | Description                                                                                               |
+|--------------------|-----------|-----------------------------------------------------------------------------------------------------------|
+| latest-title       | String    | Contains the title of the last feed entry.                                                                |
+| latest-description | String    | Contains the description of the last feed entry.                                                          |
+| latest-date        | DateTime  | Contains the published date of the last feed entry.                                                       |
+| latest-link        | String    | Contains the link of the last feed entry.                                                                 |
+| latest-enclosure   | String    | Contains the enclosure link (podcast) of the last feed entry, if enclosure is present (used in podcasts). |
+| author             | String    | The name of the feed author, if author is present.                                                        |
+| title              | String    | The title of the feed.                                                                                    |
+| description        | String    | Description of the feed.                                                                                  |
+| last-update        | DateTime  | The last update date of the feed.                                                                         |
+| number-of-entries  | Number    | Number of entries in the feed.                                                                            |
 
 ## Example
 
@@ -60,6 +61,7 @@ String latest_title           {channel="feed:feed:bbc:latest-title"}
 String latest_description     {channel="feed:feed:bbc:latest-description"}
 DateTime latest_date          {channel="feed:feed:bbc:latest-date"}
 String latest_link            {channel="feed:feed:bbc:latest-link"}
+String latest_enclosure       {channel="feed:feed:bbc:latest-enclosure"}
 Number number_of_entries      {channel="feed:feed:bbc:number-of-entries"}
 String description            {channel="feed:feed:bbc:description"}
 String author                 {channel="feed:feed:bbc:author"}
index f909f687eabfc892eb837054794c7a6e0badefe1..177449e51e572da64a8e8b99cf4e0f7397515fdc 100644 (file)
@@ -20,6 +20,7 @@ import org.openhab.core.thing.ThingTypeUID;
  * used across the whole binding.
  *
  * @author Svilen Valkanov - Initial contribution
+ * @author Juergen Pabel - Added enclosure channel
  */
 @NonNullByDefault
 public class FeedBindingConstants {
@@ -50,6 +51,11 @@ public class FeedBindingConstants {
      */
     public static final String CHANNEL_LATEST_LINK = "latest-link";
 
+    /**
+     * Contains the enclosure link to the last feed entry.
+     */
+    public static final String CHANNEL_LATEST_ENCLOSURE = "latest-enclosure";
+
     /**
      * Description of the feed.
      */
index 7fd560f19282d9de42c529e06e197451b170a55c..3b8b2711c97617316a3b01dc6f79f6608a3993d6 100644 (file)
@@ -57,6 +57,7 @@ import com.rometools.rome.io.SyndFeedInput;
  * sent to one of the channels and for the regular updates of the feed data.
  *
  * @author Svilen Valkanov - Initial contribution
+ * @author Juergen Pabel - Added enclosure channel
  */
 @NonNullByDefault
 public class FeedHandler extends BaseThingHandler {
@@ -169,6 +170,13 @@ public class FeedHandler extends BaseThingHandler {
                     state = new StringType(getValueSafely(latestEntry.getLink()));
                 }
                 break;
+            case CHANNEL_LATEST_ENCLOSURE:
+                if (latestEntry == null || latestEntry.getEnclosures().isEmpty()) {
+                    state = UnDefType.UNDEF;
+                } else {
+                    state = new StringType(getValueSafely(latestEntry.getEnclosures().get(0).getUrl()));
+                }
+                break;
             case CHANNEL_LATEST_PUBLISHED_DATE:
             case CHANNEL_LAST_UPDATE:
                 if (latestEntry == null || latestEntry.getPublishedDate() == null) {
index f1c8259e340f9339ebda3ec0a51e39ebac854617..017295641e39eec8f89ec0db990fcbb6b67b9613 100644 (file)
@@ -20,6 +20,7 @@
                        <channel id="latest-description" typeId="latest-description"/>
                        <channel id="latest-date" typeId="latest-date"/>
                        <channel id="latest-link" typeId="latest-link"/>
+                       <channel id="latest-enclosure" typeId="latest-enclosure"/>
                        <channel id="author" typeId="author"/>
                        <channel id="description" typeId="description"/>
                        <channel id="title" typeId="title"/>
                <state readOnly="true" pattern="%s"/>
        </channel-type>
 
+       <channel-type id="latest-enclosure">
+               <item-type>String</item-type>
+               <label>Latest Enclosure</label>
+               <description>Contains the first (if any) enclosure link of the last feed entry.</description>
+               <state readOnly="true" pattern="%s"/>
+       </channel-type>
+
        <channel-type id="author" advanced="true">
                <item-type>String</item-type>
                <label>Author</label>