Skip to content

Commit

Permalink
Show images based on the envelopes feed parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ogajduse committed Jul 28, 2023
1 parent e1dd66d commit 7aa030f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions custom_components/feedparser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CONF_SHOW_TOPN = "show_topn"

DEFAULT_SCAN_INTERVAL = timedelta(hours=1)
DEFAULT_THUMBNAIL = "https://www.home-assistant.io/images/favicon-192x192-full.png"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand Down Expand Up @@ -127,17 +128,22 @@ def update(self):
entry_value[key] = value

if "image" in self._inclusions and "image" not in entry_value.keys():
images = []
if "summary" in entry.keys():
images = re.findall(
r"<img.+?src=\"(.+?)\".+?>", entry["summary"]
)
if "enclosures" in entry:
images = [
enc
for enc in entry["enclosures"]
if enc.type.startswith("image/")
]
else:
images = []
if images:
entry_value["image"] = images[0]
entry_value["image"] = images[0][
"href"
] # pick the first image found
else:
entry_value[
"image"
] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
] = DEFAULT_THUMBNAIL # use default image if no image found

self._entries.append(entry_value)

Expand Down

0 comments on commit 7aa030f

Please sign in to comment.