Skip to content

Commit

Permalink
[feed] Added Channel for link to feed item; Updated rome library to v…
Browse files Browse the repository at this point in the history
…ersion 1.15 (#8893)

* Added Channel for link to latest feed; update rome deoendency to version 1.15
* Removed unsed interface
* Run spotless

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp authored Oct 30, 2020
1 parent 9a5832a commit 1e89b79
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 41 deletions.
8 changes: 5 additions & 3 deletions bundles/org.openhab.binding.feed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ 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 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. |
Expand All @@ -48,8 +49,8 @@ The binding supports following channels
Things:

```java
feed:feed:bbc [ URL="http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml?edition=uk"]
feed:feed:techCrunch [ URL="http://feeds.feedburner.com/TechCrunch/", refresh=60]
feed:feed:bbc [URL="http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml?edition=uk"]
feed:feed:techCrunch [URL="http://feeds.feedburner.com/TechCrunch/", refresh=60]
```

Items:
Expand All @@ -58,6 +59,7 @@ Items:
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"}
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
6 changes: 4 additions & 2 deletions bundles/org.openhab.binding.feed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

<properties>
<bnd.importpackage>org.jaxen.*;resolution:=optional</bnd.importpackage>

<rome.version>1.15.0</rome.version>
</properties>

<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>1.12.0</version>
<version>${rome.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand All @@ -34,7 +36,7 @@
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-utils</artifactId>
<version>1.12.0</version>
<version>${rome.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ public class FeedBindingConstants {
public static final String CHANNEL_LATEST_TITLE = "latest-title";

/**
* Contains the description of last feed entry.
* Contains the description of the last feed entry.
*/
public static final String CHANNEL_LATEST_DESCRIPTION = "latest-description";

/**
* Contains the link to the last feed entry.
*/
public static final String CHANNEL_LATEST_LINK = "latest-link";

/**
* Description of the feed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ private void publishChannelIfLinked(ChannelUID channelUID) {
state = new StringType(getValueSafely(description));
}
break;
case CHANNEL_LATEST_LINK:
if (latestEntry == null || latestEntry.getLink() == null) {
state = UnDefType.UNDEF;
} else {
state = new StringType(getValueSafely(latestEntry.getLink()));
}
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 @@ -19,6 +19,7 @@
<channel id="latest-title" typeId="latest-title"/>
<channel id="latest-description" typeId="latest-description"/>
<channel id="latest-date" typeId="latest-date"/>
<channel id="latest-link" typeId="latest-link"/>
<channel id="author" typeId="author"/>
<channel id="description" typeId="description"/>
<channel id="title" typeId="title"/>
Expand Down Expand Up @@ -52,7 +53,7 @@
<channel-type id="latest-description">
<item-type>String</item-type>
<label>Latest Description</label>
<description>Contains the description of last feed entry.</description>
<description>Contains the description of the last feed entry.</description>
<state readOnly="true" pattern="%s"/>
</channel-type>

Expand All @@ -63,6 +64,13 @@
<state readOnly="true" pattern="%tc %n"/>
</channel-type>

<channel-type id="latest-link">
<item-type>String</item-type>
<label>Latest Link</label>
<description>Contains the 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
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.feed.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

<properties>
<org.osgi.service.http.port>9090</org.osgi.service.http.port>

<rome.version>1.15.0</rome.version>
</properties>

<dependencies>
Expand All @@ -27,7 +29,7 @@
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>1.12.0</version>
<version>${rome.version}</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static java.lang.Thread.sleep;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.openhab.core.thing.ThingStatus.*;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -46,6 +45,7 @@
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingProvider;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
Expand Down Expand Up @@ -232,7 +232,7 @@ private void initializeFeedHandler(String url, BigDecimal refreshTime) {

// This will ensure that the configuration is read before the channelLinked() method in FeedHandler is called !
waitForAssert(() -> {
assertThat(feedThing.getStatus(), anyOf(is(ONLINE), is(OFFLINE)));
assertThat(feedThing.getStatus(), anyOf(is(ThingStatus.ONLINE), is(ThingStatus.OFFLINE)));
}, 60000, DFL_SLEEP_TIME);
initializeItem(channelUID);
}
Expand Down Expand Up @@ -270,7 +270,7 @@ private void testIfItemStateIsUpdated(boolean commandReceived, boolean contentCh
initializeDefaultFeedHandler();

waitForAssert(() -> {
assertThat("Feed Thing can not be initialized", feedThing.getStatus(), is(equalTo(ONLINE)));
assertThat("Feed Thing can not be initialized", feedThing.getStatus(), is(equalTo(ThingStatus.ONLINE)));
assertThat("Item's state is not updated on initialize", currentItemState, is(notNullValue()));
});

Expand All @@ -294,7 +294,7 @@ private void testIfItemStateIsUpdated(boolean commandReceived, boolean contentCh

waitForAssert(() -> {
assertThat("Error occurred while trying to connect to server. Content is not downloaded!",
feedThing.getStatus(), is(equalTo(ONLINE)));
feedThing.getStatus(), is(equalTo(ThingStatus.ONLINE)));
});

waitForAssert(() -> {
Expand Down Expand Up @@ -361,7 +361,7 @@ private void testIfThingStatusIsUpdated(Integer serverStatus) throws Interrupted
feedHandler.handleCommand(channelUID, RefreshType.REFRESH);

waitForAssert(() -> {
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE)));
});

servlet.httpStatus = HttpStatus.OK_200;
Expand All @@ -372,7 +372,7 @@ private void testIfThingStatusIsUpdated(Integer serverStatus) throws Interrupted
feedHandler.handleCommand(channelUID, RefreshType.REFRESH);

waitForAssert(() -> {
assertThat(feedThing.getStatus(), is(equalTo(ONLINE)));
assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.ONLINE)));
});
}

Expand All @@ -384,7 +384,7 @@ public void createThingWithInvalidUrlProtocol() {

initializeFeedHandler(invalidURL);
waitForAssert(() -> {
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE)));
assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.CONFIGURATION_ERROR)));
});
}
Expand All @@ -397,7 +397,7 @@ public void createThingWithInvalidUrlHostname() {

initializeFeedHandler(invalidURL);
waitForAssert(() -> {
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE)));
assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.COMMUNICATION_ERROR)));
}, 30000, DFL_SLEEP_TIME);
}
Expand All @@ -410,7 +410,7 @@ public void createThingWithInvalidUrlPath() {

initializeFeedHandler(invalidURL);
waitForAssert(() -> {
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE)));
assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.COMMUNICATION_ERROR)));
});
}
Expand Down

This file was deleted.

0 comments on commit 1e89b79

Please sign in to comment.