Skip to content

Commit 5cf6ac7

Browse files
authored
Merge pull request #81 from ogajduse/fix/include-images-from-envelopes
2 parents e1dd66d + 7aa030f commit 5cf6ac7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

custom_components/feedparser/sensor.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
CONF_SHOW_TOPN = "show_topn"
3232

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

3536
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
3637
{
@@ -127,17 +128,22 @@ def update(self):
127128
entry_value[key] = value
128129

129130
if "image" in self._inclusions and "image" not in entry_value.keys():
130-
images = []
131-
if "summary" in entry.keys():
132-
images = re.findall(
133-
r"<img.+?src=\"(.+?)\".+?>", entry["summary"]
134-
)
131+
if "enclosures" in entry:
132+
images = [
133+
enc
134+
for enc in entry["enclosures"]
135+
if enc.type.startswith("image/")
136+
]
137+
else:
138+
images = []
135139
if images:
136-
entry_value["image"] = images[0]
140+
entry_value["image"] = images[0][
141+
"href"
142+
] # pick the first image found
137143
else:
138144
entry_value[
139145
"image"
140-
] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
146+
] = DEFAULT_THUMBNAIL # use default image if no image found
141147

142148
self._entries.append(entry_value)
143149

0 commit comments

Comments
 (0)