Explicitly pass in the config_entry in nzbget coordinator (#138061)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 16:33:38 +01:00 committed by GitHub
parent 7097faa950
commit 8241429c5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 15 deletions

View File

@ -31,10 +31,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up NZBGet from a config entry.""" """Set up NZBGet from a config entry."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
coordinator = NZBGetDataUpdateCoordinator( coordinator = NZBGetDataUpdateCoordinator(hass, entry)
hass,
config=entry.data,
)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()

View File

@ -1,13 +1,12 @@
"""Provides the NZBGet DataUpdateCoordinator.""" """Provides the NZBGet DataUpdateCoordinator."""
import asyncio import asyncio
from collections.abc import Mapping
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any
from pynzbgetapi import NZBGetAPI, NZBGetAPIException from pynzbgetapi import NZBGetAPI, NZBGetAPIException
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_PASSWORD, CONF_PASSWORD,
@ -27,27 +26,32 @@ _LOGGER = logging.getLogger(__name__)
class NZBGetDataUpdateCoordinator(DataUpdateCoordinator): class NZBGetDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching NZBGet data.""" """Class to manage fetching NZBGet data."""
config_entry: ConfigEntry
def __init__( def __init__(
self, self,
hass: HomeAssistant, hass: HomeAssistant,
*, config_entry: ConfigEntry,
config: Mapping[str, Any],
) -> None: ) -> None:
"""Initialize global NZBGet data updater.""" """Initialize global NZBGet data updater."""
self.nzbget = NZBGetAPI( self.nzbget = NZBGetAPI(
config[CONF_HOST], config_entry.data[CONF_HOST],
config.get(CONF_USERNAME), config_entry.data.get(CONF_USERNAME),
config.get(CONF_PASSWORD), config_entry.data.get(CONF_PASSWORD),
config[CONF_SSL], config_entry.data[CONF_SSL],
config[CONF_VERIFY_SSL], config_entry.data[CONF_VERIFY_SSL],
config[CONF_PORT], config_entry.data[CONF_PORT],
) )
self._completed_downloads_init = False self._completed_downloads_init = False
self._completed_downloads = set[tuple]() self._completed_downloads = set[tuple]()
super().__init__( super().__init__(
hass, _LOGGER, name=DOMAIN, update_interval=timedelta(seconds=5) hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=timedelta(seconds=5),
) )
def _check_completed_downloads(self, history): def _check_completed_downloads(self, history):