Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions custom_components/feedparser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ def _process_image(self: FeedParserSensor, feed_entry: FeedParserDict) -> str:
if images:
# pick the first image found
return images[0]["href"]
if feed_entry.get("media_content"):
images = [
enc for enc in feed_entry["media_content"] if enc['type'].startswith("image/")
]
Comment on lines +264 to +266
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filtering media_content items with enc['type'].startswith("image/") can raise KeyError (missing type) or AttributeError (type is None). Using a safe accessor (e.g., enc.get("type", "")) and matching the enclosures style (enc.type) would make this more robust for varying feedparser outputs.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this a minor comment.

if images:
# pick the first image found
return images[0]["url"]
Comment on lines +263 to +269
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces a new image source (media_content) but the test suite doesn't include any fixture/feed data that exercises media_content image parsing. Adding a representative feed sample (e.g., Mastodon) and asserting the selected image URL would prevent regressions and validate the new behavior.

Copilot uses AI. Check for mistakes.
elif "summary" in feed_entry:
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summary fallback is skipped when media_content exists but contains no image items because this uses elif "summary" in feed_entry after the media_content block. This can cause DEFAULT_THUMBNAIL to be returned even when an <img> exists in the summary. Consider making the summary check an independent if (or otherwise falling through) so it runs when media_content has no usable images.

Suggested change
enc for enc in feed_entry["media_content"] if enc['type'].startswith("image/")
]
if images:
# pick the first image found
return images[0]["url"]
elif "summary" in feed_entry:
enc for enc in feed_entry["media_content"] if enc["type"].startswith("image/")
]
if images:
# pick the first image found
return images[0]["url"]
if "summary" in feed_entry:

Copilot uses AI. Check for mistakes.
images = re.findall(
IMAGE_REGEX,
Expand Down
Loading