Explicitly pass in the config_entry in glances coordinator (#137835)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 13:17:06 +01:00 committed by GitHub
parent 9bdd8d04c5
commit 0efdceef27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 8 deletions

View File

@ -10,7 +10,6 @@ from glances_api.exceptions import (
GlancesApiNoDataAvailable, GlancesApiNoDataAvailable,
) )
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_PASSWORD, CONF_PASSWORD,
@ -29,15 +28,13 @@ from homeassistant.exceptions import (
) )
from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.httpx_client import get_async_client
from .coordinator import GlancesDataUpdateCoordinator from .coordinator import GlancesConfigEntry, GlancesDataUpdateCoordinator
PLATFORMS = [Platform.SENSOR] PLATFORMS = [Platform.SENSOR]
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
type GlancesConfigEntry = ConfigEntry[GlancesDataUpdateCoordinator]
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, config_entry: GlancesConfigEntry hass: HomeAssistant, config_entry: GlancesConfigEntry

View File

@ -17,21 +17,25 @@ from .const import DEFAULT_SCAN_INTERVAL, DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
type GlancesConfigEntry = ConfigEntry[GlancesDataUpdateCoordinator]
class GlancesDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]): class GlancesDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Get the latest data from Glances api.""" """Get the latest data from Glances api."""
config_entry: ConfigEntry config_entry: GlancesConfigEntry
def __init__(self, hass: HomeAssistant, entry: ConfigEntry, api: Glances) -> None: def __init__(
self, hass: HomeAssistant, entry: GlancesConfigEntry, api: Glances
) -> None:
"""Initialize the Glances data.""" """Initialize the Glances data."""
self.hass = hass self.hass = hass
self.config_entry = entry
self.host: str = entry.data[CONF_HOST] self.host: str = entry.data[CONF_HOST]
self.api = api self.api = api
super().__init__( super().__init__(
hass, hass,
_LOGGER, _LOGGER,
config_entry=entry,
name=f"{DOMAIN} - {self.host}", name=f"{DOMAIN} - {self.host}",
update_interval=DEFAULT_SCAN_INTERVAL, update_interval=DEFAULT_SCAN_INTERVAL,
) )

View File

@ -22,8 +22,8 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import GlancesConfigEntry, GlancesDataUpdateCoordinator
from .const import CPU_ICON, DOMAIN from .const import CPU_ICON, DOMAIN
from .coordinator import GlancesConfigEntry, GlancesDataUpdateCoordinator
@dataclass(frozen=True, kw_only=True) @dataclass(frozen=True, kw_only=True)