1 """Event entities for RSS/Atom feeds."""
3 from __future__
import annotations
8 from feedparser
import FeedParserDict
16 from .
import FeedReaderConfigEntry
17 from .const
import DOMAIN, EVENT_FEEDREADER
18 from .coordinator
import FeedReaderCoordinator
20 LOGGER = logging.getLogger(__name__)
22 ATTR_CONTENT =
"content"
23 ATTR_DESCRIPTION =
"description"
30 entry: FeedReaderConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up event entities for feedreader."""
34 coordinator = entry.runtime_data
40 """Representation of a feedreader event."""
42 _attr_event_types = [EVENT_FEEDREADER]
44 _attr_has_entity_name =
True
45 _unrecorded_attributes = frozenset(
46 {ATTR_CONTENT, ATTR_DESCRIPTION, ATTR_TITLE, ATTR_LINK}
48 coordinator: FeedReaderCoordinator
50 def __init__(self, coordinator: FeedReaderCoordinator) ->
None:
51 """Initialize the feedreader event."""
53 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.config_entry.entry_id}_latest_feed"
56 identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
57 name=coordinator.config_entry.title,
58 configuration_url=coordinator.url,
59 manufacturer=coordinator.feed_author,
60 sw_version=coordinator.feed_version,
61 entry_type=DeviceEntryType.SERVICE,
65 """Entity added to hass."""
73 if (data := self.coordinator.data)
is None or not data:
78 feed_data: FeedParserDict = data[0]
80 if description := feed_data.get(
"description"):
81 description = html.unescape(description)
83 if title := feed_data.get(
"title"):
84 title = html.unescape(title)
86 if content := feed_data.get(
"content"):
87 if isinstance(content, list)
and isinstance(content[0], dict):
88 content = content[0].
get(
"value")
89 content = html.unescape(content)
94 ATTR_DESCRIPTION: description,
96 ATTR_LINK: feed_data.get(
"link"),
97 ATTR_CONTENT: content,
None _trigger_event(self, str event_type, dict[str, Any]|None event_attributes=None)
None _async_handle_update(self)
None __init__(self, FeedReaderCoordinator coordinator)
None async_added_to_hass(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
Callable[[], None] async_add_listener(self, CALLBACK_TYPE update_callback, Any context=None)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, FeedReaderConfigEntry entry, AddEntitiesCallback async_add_entities)