From ee6ffb1be4c0f1eb7b7b7181c33e5b56dcf6a7d9 Mon Sep 17 00:00:00 2001 From: likeablob <46628917+likeablob@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:43:50 +0900 Subject: [PATCH] Fix `feedreader` component to keep the last entry timestamp up to date (#77547) Fix feedreader to keep the last entry timestamp up to date - Use `updated` date in precedence over `published` date to update `last_entry_timestamp` in the case a feed entry has both updated date and published date. --- .../components/feedreader/__init__.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/feedreader/__init__.py b/homeassistant/components/feedreader/__init__.py index 0ee4d3c39f3..50404bb96dc 100644 --- a/homeassistant/components/feedreader/__init__.py +++ b/homeassistant/components/feedreader/__init__.py @@ -156,26 +156,27 @@ class FeedManager: def _update_and_fire_entry(self, entry: feedparser.FeedParserDict) -> None: """Update last_entry_timestamp and fire entry.""" - # Check if the entry has a published or updated date. - if "published_parsed" in entry and entry.published_parsed: - # We are lucky, `published_parsed` data available, let's make use of - # it to publish only new available entries since the last run - self._has_published_parsed = True - self._last_entry_timestamp = max( - entry.published_parsed, self._last_entry_timestamp - ) - elif "updated_parsed" in entry and entry.updated_parsed: + # Check if the entry has a updated or published date. + # Start from a updated date because generally `updated` > `published`. + if "updated_parsed" in entry and entry.updated_parsed: # We are lucky, `updated_parsed` data available, let's make use of # it to publish only new available entries since the last run self._has_updated_parsed = True self._last_entry_timestamp = max( entry.updated_parsed, self._last_entry_timestamp ) + elif "published_parsed" in entry and entry.published_parsed: + # We are lucky, `published_parsed` data available, let's make use of + # it to publish only new available entries since the last run + self._has_published_parsed = True + self._last_entry_timestamp = max( + entry.published_parsed, self._last_entry_timestamp + ) else: - self._has_published_parsed = False self._has_updated_parsed = False + self._has_published_parsed = False _LOGGER.debug( - "No published_parsed or updated_parsed info available for entry %s", + "No updated_parsed or published_parsed info available for entry %s", entry, ) entry.update({"feed_url": self._url})