Repository: home-assistant/core
File: homeassistant/components/point/coordinator.py (Python)

Code before:
from datetime import datetime
import logging
from typing import Any

from pypoint import PointSession

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util.dt import parse_datetime

from .const import DOMAIN, SCAN_INTERVAL

_LOGGER = logging.getLogger(__name__)


class PointDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict[str, Any]]]):
    """Class to manage fetching Point data from the API."""

    def __init__(
        self, hass: HomeAssistant, point: PointSession, config_entry: ConfigEntry
    ) -> None:
        """Initialize."""
        super().__init__(
            hass,
            _LOGGER,
            name=DOMAIN,
            update_interval=SCAN_INTERVAL,
            config_entry=config_entry,
        )
        self.point = point
        self.device_updates: dict[str, datetime] = {}
        self._known_devices: set[str] = set()
        self._known_homes: set[str] = set()
        self.new_home_callback: Callable[[str], None] | None = None
        self.new_device_callbacks: list[Callable[[str], None]] = []
        self.data: dict[str, dict[str, Any]] = {}

    async def _async_update_data(self) -> dict[str, dict[str, Any]]:
        if not await self.point.update():
            raise UpdateFailed("Failed to fetch data from Point")

        if new_homes := set(self.point.homes) - self._known_homes:
            _LOGGER.debug("Found new homes: %s", new_homes)
            for home_id in new_homes:
                if self.new_home_callback:
                    self.new_home_callback(home_id)
            self._known_homes.update(new_homes)

        device_ids = {device.device_id for device in self.point.devices}
        if new_devices := device_ids - self._known_devices:

Review comment (suggestion):
Please move `PointConfigEntry` definition from `__init__.py` to `coordinator.py`, and use that instead of the generic `ConfigEntry` definition.

```suggestion
    config_entry: PointConfigEntry
    
    def __init__(
        self, hass: HomeAssistant, point: PointSession, config_entry: ConfigEntry
    ) -> None:
```

Code after:
from datetime import datetime
import logging
from typing import TYPE_CHECKING, Any

from pypoint import PointSession

from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util.dt import parse_datetime

from .const import DOMAIN, SCAN_INTERVAL

if TYPE_CHECKING:
    from . import PointConfigEntry

_LOGGER = logging.getLogger(__name__)


class PointDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict[str, Any]]]):
    """Class to manage fetching Point data from the API."""

    config_entry: "PointConfigEntry"

    def __init__(
        self, hass: HomeAssistant, point: PointSession, config_entry: "PointConfigEntry"
    ) -> None:
        """Initialize."""
        super().__init__(
            hass,
            _LOGGER,
            name=DOMAIN,
            update_interval=SCAN_INTERVAL,
            config_entry=config_entry,
        )
        self.point = point
        self.device_updates: dict[str, datetime] = {}
        self._known_devices: set[str] = set()
        self._known_homes: set[str] = set()
        self.new_home_callback: Callable[[str], None] | None = None
        self.new_device_callbacks: list[Callable[[str], None]] = []
        self.data: dict[str, dict[str, Any]] = {}

    async def _async_update_data(self) -> dict[str, dict[str, Any]]:
        if not await self.point.update():
            raise UpdateFailed("Failed to fetch data from Point")

        if new_homes := set(self.point.homes) - self._known_homes:
            _LOGGER.debug("Found new homes: %s", new_homes)
            for home_id in new_homes:
                if self.new_home_callback:
                    self.new_home_callback(home_id)