3535CONF_INCLUSIONS = "inclusions"
3636CONF_EXCLUSIONS = "exclusions"
3737CONF_SHOW_TOPN = "show_topn"
38+ CONF_REMOVE_SUMMARY_IMG = "remove_summary_image"
3839
3940DEFAULT_DATE_FORMAT = "%a, %b %d %I:%M %p"
4041DEFAULT_SCAN_INTERVAL = timedelta (hours = 1 )
4142DEFAULT_THUMBNAIL = "https://www.home-assistant.io/images/favicon-192x192-full.png"
4243DEFAULT_TOPN = 9999
4344USER_AGENT = f"Home Assistant Feed-parser Integration { __version__ } "
45+ IMAGE_REGEX = r"<img.+?src=\"(.+?)\".+?>"
4446
4547PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend (
4648 {
4951 vol .Required (CONF_DATE_FORMAT , default = DEFAULT_DATE_FORMAT ): cv .string ,
5052 vol .Optional (CONF_LOCAL_TIME , default = False ): cv .boolean ,
5153 vol .Optional (CONF_SHOW_TOPN , default = DEFAULT_TOPN ): cv .positive_int ,
54+ vol .Optional (CONF_REMOVE_SUMMARY_IMG , default = False ): cv .boolean ,
5255 vol .Optional (CONF_INCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
5356 vol .Optional (CONF_EXCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
5457 vol .Optional (CONF_SCAN_INTERVAL , default = DEFAULT_SCAN_INTERVAL ): cv .time_period ,
@@ -72,6 +75,7 @@ async def async_setup_platform(
7275 name = config [CONF_NAME ],
7376 date_format = config [CONF_DATE_FORMAT ],
7477 show_topn = config [CONF_SHOW_TOPN ],
78+ remove_summary_image = config [CONF_REMOVE_SUMMARY_IMG ],
7579 inclusions = config [CONF_INCLUSIONS ],
7680 exclusions = config [CONF_EXCLUSIONS ],
7781 scan_interval = config [CONF_SCAN_INTERVAL ],
@@ -95,6 +99,7 @@ def __init__(
9599 name : str ,
96100 date_format : str ,
97101 show_topn : int ,
102+ remove_summary_image : bool ,
98103 exclusions : list [str | None ],
99104 inclusions : list [str | None ],
100105 scan_interval : timedelta ,
@@ -106,6 +111,7 @@ def __init__(
106111 self ._attr_icon = "mdi:rss"
107112 self ._date_format = date_format
108113 self ._show_topn : int = show_topn
114+ self ._remove_summary_image = remove_summary_image
109115 self ._inclusions = inclusions
110116 self ._exclusions = exclusions
111117 self ._scan_interval = scan_interval
@@ -119,7 +125,9 @@ def __repr__(self: FeedParserSensor) -> str:
119125 """Return the representation."""
120126 return (
121127 f'FeedParserSensor(name="{ self .name } ", feed="{ self ._feed } ", '
122- f"show_topn={ self ._show_topn } , inclusions={ self ._inclusions } , "
128+ f"show_topn={ self ._show_topn } , "
129+ f"remove_summary_image={ self ._remove_summary_image } , "
130+ f"inclusions={ self ._inclusions } , "
123131 f"exclusions={ self ._exclusions } , scan_interval={ self ._scan_interval } , "
124132 f'local_time={ self ._local_time } , date_format="{ self ._date_format } ")'
125133 )
@@ -199,6 +207,12 @@ def _generate_sensor_entry(
199207 and (processed_link := self ._process_link (feed_entry ))
200208 ):
201209 sensor_entry ["link" ] = processed_link
210+ if self ._remove_summary_image and "summary" in sensor_entry :
211+ sensor_entry ["summary" ] = re .sub (
212+ IMAGE_REGEX ,
213+ "" ,
214+ sensor_entry ["summary" ],
215+ )
202216 _LOGGER .debug ("Feed %s: Generated sensor entry: %s" , self .name , sensor_entry )
203217 return sensor_entry
204218
@@ -248,7 +262,7 @@ def _process_image(self: FeedParserSensor, feed_entry: FeedParserDict) -> str:
248262 return images [0 ]["href" ]
249263 elif "summary" in feed_entry :
250264 images = re .findall (
251- r"<img.+?src=\"(.+?)\".+?>" ,
265+ IMAGE_REGEX ,
252266 feed_entry ["summary" ],
253267 )
254268 if images :
0 commit comments