Add RSS description to Feedreader event (#126681)

This commit is contained in:
rubenbe 2024-09-27 13:46:48 +02:00 committed by GitHub
parent 2d16732972
commit b3b5d9602a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -19,6 +19,7 @@ from .coordinator import FeedReaderCoordinator
LOGGER = logging.getLogger(__name__)
ATTR_CONTENT = "content"
ATTR_DESCRIPTION = "description"
ATTR_LINK = "link"
ATTR_TITLE = "title"
@ -40,7 +41,9 @@ class FeedReaderEvent(CoordinatorEntity[FeedReaderCoordinator], EventEntity):
_attr_event_types = [EVENT_FEEDREADER]
_attr_name = None
_attr_has_entity_name = True
_unrecorded_attributes = frozenset({ATTR_CONTENT, ATTR_TITLE, ATTR_LINK})
_unrecorded_attributes = frozenset(
{ATTR_CONTENT, ATTR_DESCRIPTION, ATTR_TITLE, ATTR_LINK}
)
coordinator: FeedReaderCoordinator
def __init__(self, coordinator: FeedReaderCoordinator) -> None:
@ -80,6 +83,7 @@ class FeedReaderEvent(CoordinatorEntity[FeedReaderCoordinator], EventEntity):
self._trigger_event(
EVENT_FEEDREADER,
{
ATTR_DESCRIPTION: feed_data.get("description"),
ATTR_TITLE: feed_data.get("title"),
ATTR_LINK: feed_data.get("link"),
ATTR_CONTENT: content,

View File

@ -5,6 +5,7 @@ from unittest.mock import patch
from homeassistant.components.feedreader.event import (
ATTR_CONTENT,
ATTR_DESCRIPTION,
ATTR_LINK,
ATTR_TITLE,
)
@ -35,6 +36,7 @@ async def test_event_entity(
assert state.attributes[ATTR_TITLE] == "Title 1"
assert state.attributes[ATTR_LINK] == "http://www.example.com/link/1"
assert state.attributes[ATTR_CONTENT] == "Content 1"
assert state.attributes[ATTR_DESCRIPTION] == "Description 1"
future = dt_util.utcnow() + timedelta(hours=1, seconds=1)
async_fire_time_changed(hass, future)
@ -45,6 +47,7 @@ async def test_event_entity(
assert state.attributes[ATTR_TITLE] == "Title 2"
assert state.attributes[ATTR_LINK] == "http://www.example.com/link/2"
assert state.attributes[ATTR_CONTENT] == "Content 2"
assert state.attributes[ATTR_DESCRIPTION] == "Description 2"
future = dt_util.utcnow() + timedelta(hours=2, seconds=2)
async_fire_time_changed(hass, future)
@ -55,3 +58,4 @@ async def test_event_entity(
assert state.attributes[ATTR_TITLE] == "Title 1"
assert state.attributes[ATTR_LINK] == "http://www.example.com/link/1"
assert state.attributes[ATTR_CONTENT] == "This is a summary"
assert state.attributes[ATTR_DESCRIPTION] == "Description 1"