Skip to content

Commit

Permalink
[feed] added channel for enclosure link on latest entry (openhab#11345)
Browse files Browse the repository at this point in the history
Signed-off-by: Juergen Pabel <juergen@pabel.net>
Signed-off-by: Dave J Schoepel <dave@theschoepels.com>
  • Loading branch information
juergenpabel authored and dschoepel committed Nov 9, 2021
1 parent d8a9b91 commit 6b4b0d1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
24 changes: 13 additions & 11 deletions bundles/org.openhab.binding.feed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* used across the whole binding.
*
* @author Svilen Valkanov - Initial contribution
* @author Juergen Pabel - Added enclosure channel
*/
@NonNullByDefault
public class FeedBindingConstants {
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* 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 {
Expand Down Expand Up @@ -169,6 +170,13 @@ private void publishChannelIfLinked(ChannelUID channelUID) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -71,6 +72,13 @@
<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>
Expand Down

0 comments on commit 6b4b0d1

Please sign in to comment.