From 7aa030f94d376d3f11d72e0c4205ec4cc4d24fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Gajdu=C5=A1ek?= Date: Fri, 28 Jul 2023 09:47:09 +0200 Subject: [PATCH] Show images based on the envelopes feed parameter --- custom_components/feedparser/sensor.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/custom_components/feedparser/sensor.py b/custom_components/feedparser/sensor.py index 055ebc6..c5f2cbf 100644 --- a/custom_components/feedparser/sensor.py +++ b/custom_components/feedparser/sensor.py @@ -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( { @@ -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"", 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)