Skip to content
Open
Changes from all commits
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
9 changes: 8 additions & 1 deletion custom_components/feedparser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,14 @@ def _process_image(self: FeedParserSensor, feed_entry: FeedParserDict) -> str:
if images:
# pick the first image found
return images[0]["href"]
elif "summary" in feed_entry:
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.
if "summary" in feed_entry:
images = re.findall(
IMAGE_REGEX,
feed_entry["summary"],
Expand Down