Repository: custom-components/feedparser

Issue:
Add entity attribution
https://developers.home-assistant.io/docs/core/entity/?_highlight=attribution#generic-properties

https://github.com/home-assistant/core/blob/af5fc7e759d52c9357fc9d6d8cb7d578123011a9/homeassistant/helpers/entity.py#L638-L641

Discussion:

Patch:
diff --git a/custom_components/feedparser/sensor.py b/custom_components/feedparser/sensor.py
index a898875..a292ff6 100644
--- a/custom_components/feedparser/sensor.py
+++ b/custom_components/feedparser/sensor.py
@@ -104,6 +104,7 @@ class FeedParserSensor(SensorEntity):
         self._local_time = local_time
         self._entries: list[dict[str, str]] = []
         self._attr_extra_state_attributes = {"entries": self._entries}
+        _attr_attribution = "Data retrieved using RSS feedparser"
 
     def update(self: FeedParserSensor) -> None:
         """Parse the feed and update the state of the sensor."""
@@ -119,6 +120,7 @@ class FeedParserSensor(SensorEntity):
             if len(parsed_feed.entries) > self._show_topn
             else len(parsed_feed.entries)
         )
+        self._entries.clear()  # clear the entries to avoid duplicates
         self._entries.extend(self._generate_entries(parsed_feed))
 
     def _generate_entries(


Test patch:
diff --git a/tests/test_sensors.py b/tests/test_sensors.py
index 6b43dfd..f34e47e 100644
--- a/tests/test_sensors.py
+++ b/tests/test_sensors.py
@@ -137,3 +137,13 @@ def test_update_sensor_entries_time(
     # assert that the time of the first entry in the sensor is equal to
     # the time of the first entry in the feed
     assert first_entry_time == first_sensor_entry_time
+
+
+def test_check_duplicates(feed_sensor: FeedParserSensor) -> None:
+    """Test that the sensor stores only unique entries."""
+    feed_sensor.update()
+    assert feed_sensor.extra_state_attributes["entries"]
+    after_first_update = len(feed_sensor.feed_entries)
+    feed_sensor.update()
+    after_second_update = len(feed_sensor.feed_entries)
+    assert after_first_update == after_second_update