mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Update RSS feed template (#62966)
This commit is contained in:
parent
a58fd87964
commit
27038fda27
@ -81,11 +81,17 @@ class RssView(HomeAssistantView):
|
|||||||
"""Generate the RSS view XML."""
|
"""Generate the RSS view XML."""
|
||||||
response = '<?xml version="1.0" encoding="utf-8"?>\n\n'
|
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:
|
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)
|
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:
|
for item in self._items:
|
||||||
response += " <item>\n"
|
response += " <item>\n"
|
||||||
@ -99,6 +105,7 @@ class RssView(HomeAssistantView):
|
|||||||
response += "</description>\n"
|
response += "</description>\n"
|
||||||
response += " </item>\n"
|
response += " </item>\n"
|
||||||
|
|
||||||
|
response += " </channel>\n"
|
||||||
response += "</rss>\n"
|
response += "</rss>\n"
|
||||||
|
|
||||||
return web.Response(body=response, content_type=CONTENT_TYPE_XML)
|
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()
|
text = await resp.text()
|
||||||
|
|
||||||
xml = ElementTree.fromstring(text)
|
xml = ElementTree.fromstring(text)
|
||||||
assert xml[0].text == "feed title is a_state_1"
|
feed_title = xml.find("./channel/title").text
|
||||||
assert xml[1][0].text == "item title is a_state_2"
|
item_title = xml.find("./channel/item/title").text
|
||||||
assert xml[1][1].text == "desc a_state_3"
|
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…
x
Reference in New Issue
Block a user