mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Explicitly pass in the config_entry in Feedreader coordinator init (#136777)
This commit is contained in:
parent
fa2aeae30f
commit
177bb29f69
@ -2,15 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_URL, Platform
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import CONF_MAX_ENTRIES, DOMAIN
|
||||
from .coordinator import FeedReaderCoordinator, StoredData
|
||||
|
||||
type FeedReaderConfigEntry = ConfigEntry[FeedReaderCoordinator]
|
||||
from .const import DOMAIN
|
||||
from .coordinator import FeedReaderConfigEntry, FeedReaderCoordinator, StoredData
|
||||
|
||||
CONF_URLS = "urls"
|
||||
|
||||
@ -23,12 +20,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: FeedReaderConfigEntry) -
|
||||
if not storage.is_initialized:
|
||||
await storage.async_setup()
|
||||
|
||||
coordinator = FeedReaderCoordinator(
|
||||
hass,
|
||||
entry.data[CONF_URL],
|
||||
entry.options[CONF_MAX_ENTRIES],
|
||||
storage,
|
||||
)
|
||||
coordinator = FeedReaderCoordinator(hass, entry, storage)
|
||||
|
||||
await coordinator.async_setup()
|
||||
|
||||
|
@ -13,13 +13,14 @@ from urllib.error import URLError
|
||||
import feedparser
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_URL
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, EVENT_FEEDREADER
|
||||
from .const import CONF_MAX_ENTRIES, DEFAULT_SCAN_INTERVAL, DOMAIN, EVENT_FEEDREADER
|
||||
|
||||
DELAY_SAVE = 30
|
||||
STORAGE_VERSION = 1
|
||||
@ -27,37 +28,39 @@ STORAGE_VERSION = 1
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
type FeedReaderConfigEntry = ConfigEntry[FeedReaderCoordinator]
|
||||
|
||||
|
||||
class FeedReaderCoordinator(
|
||||
DataUpdateCoordinator[list[feedparser.FeedParserDict] | None]
|
||||
):
|
||||
"""Abstraction over Feedparser module."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: FeedReaderConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
url: str,
|
||||
max_entries: int,
|
||||
config_entry: FeedReaderConfigEntry,
|
||||
storage: StoredData,
|
||||
) -> None:
|
||||
"""Initialize the FeedManager object, poll as per scan interval."""
|
||||
super().__init__(
|
||||
hass=hass,
|
||||
logger=_LOGGER,
|
||||
name=f"{DOMAIN} {url}",
|
||||
update_interval=DEFAULT_SCAN_INTERVAL,
|
||||
)
|
||||
self.url = url
|
||||
self.url = config_entry.data[CONF_URL]
|
||||
self.feed_author: str | None = None
|
||||
self.feed_version: str | None = None
|
||||
self._max_entries = max_entries
|
||||
self._max_entries = config_entry.options[CONF_MAX_ENTRIES]
|
||||
self._storage = storage
|
||||
self._last_entry_timestamp: struct_time | None = None
|
||||
self._event_type = EVENT_FEEDREADER
|
||||
self._feed: feedparser.FeedParserDict | None = None
|
||||
self._feed_id = url
|
||||
self._feed_id = self.url
|
||||
super().__init__(
|
||||
hass=hass,
|
||||
logger=_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=f"{DOMAIN} {self.url}",
|
||||
update_interval=DEFAULT_SCAN_INTERVAL,
|
||||
)
|
||||
|
||||
@callback
|
||||
def _log_no_entries(self) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user