Update RSS feed template (#62966)
parent
a58fd87964
commit
27038fda27
|
@ -81,24 +81,31 @@ class RssView(HomeAssistantView):
|
|||
"""Generate the RSS view XML."""
|
||||
response = '<?xml version="1.0" encoding="utf-8"?>\n\n'
|
||||
|
||||
response += "<rss>\n"
|
||||
response += '<rss version="2.0">\n'
|
||||
response += " <channel>\n"
|
||||
if self._title is not None:
|
||||
response += " <title>%s</title>\n" % escape(
|
||||
response += " <title>%s</title>\n" % escape(
|
||||
self._title.async_render(parse_result=False)
|
||||
)
|
||||
else:
|
||||
response += " <title>Home Assistant</title>\n"
|
||||
|
||||
response += " <link>https://www.home-assistant.io/integrations/rss_feed_template/</link>\n"
|
||||
response += " <description>Home automation feed</description>\n"
|
||||
|
||||
for item in self._items:
|
||||
response += " <item>\n"
|
||||
response += " <item>\n"
|
||||
if "title" in item:
|
||||
response += " <title>"
|
||||
response += " <title>"
|
||||
response += escape(item["title"].async_render(parse_result=False))
|
||||
response += "</title>\n"
|
||||
if "description" in item:
|
||||
response += " <description>"
|
||||
response += " <description>"
|
||||
response += escape(item["description"].async_render(parse_result=False))
|
||||
response += "</description>\n"
|
||||
response += " </item>\n"
|
||||
response += " </item>\n"
|
||||
|
||||
response += " </channel>\n"
|
||||
response += "</rss>\n"
|
||||
|
||||
return web.Response(body=response, content_type=CONTENT_TYPE_XML)
|
||||
|
|
|
@ -46,6 +46,9 @@ async def test_get_rss_feed(mock_http_client, hass):
|
|||
text = await resp.text()
|
||||
|
||||
xml = ElementTree.fromstring(text)
|
||||
assert xml[0].text == "feed title is a_state_1"
|
||||
assert xml[1][0].text == "item title is a_state_2"
|
||||
assert xml[1][1].text == "desc a_state_3"
|
||||
feed_title = xml.find("./channel/title").text
|
||||
item_title = xml.find("./channel/item/title").text
|
||||
item_description = xml.find("./channel/item/description").text
|
||||
assert feed_title == "feed title is a_state_1"
|
||||
assert item_title == "item title is a_state_2"
|
||||
assert item_description == "desc a_state_3"
|
||||
|
|
Loading…
Reference in New Issue