mirror of
https://github.com/home-assistant/core.git
synced 2025-08-12 00:55:26 +02:00
Feedreader: Properly support Atom feeds that use only the updated
date format and resolve #73207.
This commit is contained in:
@@ -70,6 +70,7 @@ class FeedManager:
|
|||||||
self._last_entry_timestamp = None
|
self._last_entry_timestamp = None
|
||||||
self._last_update_successful = False
|
self._last_update_successful = False
|
||||||
self._has_published_parsed = False
|
self._has_published_parsed = False
|
||||||
|
self._has_updated_parsed = False
|
||||||
self._event_type = EVENT_FEEDREADER
|
self._event_type = EVENT_FEEDREADER
|
||||||
self._feed_id = url
|
self._feed_id = url
|
||||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, lambda _: self._update())
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, lambda _: self._update())
|
||||||
@@ -122,7 +123,7 @@ class FeedManager:
|
|||||||
)
|
)
|
||||||
self._filter_entries()
|
self._filter_entries()
|
||||||
self._publish_new_entries()
|
self._publish_new_entries()
|
||||||
if self._has_published_parsed:
|
if self._has_published_parsed or self._has_updated_parsed:
|
||||||
self._storage.put_timestamp(
|
self._storage.put_timestamp(
|
||||||
self._feed_id, self._last_entry_timestamp
|
self._feed_id, self._last_entry_timestamp
|
||||||
)
|
)
|
||||||
@@ -143,7 +144,7 @@ class FeedManager:
|
|||||||
|
|
||||||
def _update_and_fire_entry(self, entry):
|
def _update_and_fire_entry(self, entry):
|
||||||
"""Update last_entry_timestamp and fire entry."""
|
"""Update last_entry_timestamp and fire entry."""
|
||||||
# Check if the entry has a published date.
|
# Check if the entry has a published or updated date.
|
||||||
if "published_parsed" in entry and entry.published_parsed:
|
if "published_parsed" in entry and entry.published_parsed:
|
||||||
# We are lucky, `published_parsed` data available, let's make use of
|
# We are lucky, `published_parsed` data available, let's make use of
|
||||||
# it to publish only new available entries since the last run
|
# it to publish only new available entries since the last run
|
||||||
@@ -151,9 +152,17 @@ class FeedManager:
|
|||||||
self._last_entry_timestamp = max(
|
self._last_entry_timestamp = max(
|
||||||
entry.published_parsed, self._last_entry_timestamp
|
entry.published_parsed, self._last_entry_timestamp
|
||||||
)
|
)
|
||||||
|
elif "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
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self._has_published_parsed = False
|
self._has_published_parsed = False
|
||||||
_LOGGER.debug("No published_parsed info available for entry %s", entry)
|
self._has_updated_parsed = False
|
||||||
|
_LOGGER.debug("No published_parsed or updated_parsed info available for entry %s", entry)
|
||||||
entry.update({"feed_url": self._url})
|
entry.update({"feed_url": self._url})
|
||||||
self._hass.bus.fire(self._event_type, entry)
|
self._hass.bus.fire(self._event_type, entry)
|
||||||
|
|
||||||
@@ -170,6 +179,9 @@ class FeedManager:
|
|||||||
if self._firstrun or (
|
if self._firstrun or (
|
||||||
"published_parsed" in entry
|
"published_parsed" in entry
|
||||||
and entry.published_parsed > self._last_entry_timestamp
|
and entry.published_parsed > self._last_entry_timestamp
|
||||||
|
) or (
|
||||||
|
"updated_parsed" in entry
|
||||||
|
and entry.updated_parsed > self._last_entry_timestamp
|
||||||
):
|
):
|
||||||
self._update_and_fire_entry(entry)
|
self._update_and_fire_entry(entry)
|
||||||
new_entries = True
|
new_entries = True
|
||||||
|
Reference in New Issue
Block a user