mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Explicitly pass in the config_entry in fyta coordinator (#137828)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
e8e4fb296b
commit
04c20b9534
@ -7,7 +7,6 @@ import logging
|
||||
|
||||
from fyta_cli.fyta_connector import FytaConnector
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_PASSWORD,
|
||||
@ -19,7 +18,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.util.dt import async_get_time_zone
|
||||
|
||||
from .const import CONF_EXPIRATION
|
||||
from .coordinator import FytaCoordinator
|
||||
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -28,7 +27,6 @@ PLATFORMS = [
|
||||
Platform.IMAGE,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
type FytaConfigEntry = ConfigEntry[FytaCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: FytaConfigEntry) -> bool:
|
||||
@ -46,7 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: FytaConfigEntry) -> bool
|
||||
username, password, access_token, expiration, tz, async_get_clientsession(hass)
|
||||
)
|
||||
|
||||
coordinator = FytaCoordinator(hass, fyta)
|
||||
coordinator = FytaCoordinator(hass, entry, fyta)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
|
@ -17,7 +17,7 @@ from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import FytaConfigEntry
|
||||
from .coordinator import FytaConfigEntry
|
||||
from .entity import FytaPlantEntity
|
||||
|
||||
|
||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from fyta_cli.fyta_connector import FytaConnector
|
||||
from fyta_cli.fyta_exceptions import (
|
||||
@ -16,6 +15,7 @@ from fyta_cli.fyta_exceptions import (
|
||||
)
|
||||
from fyta_cli.fyta_models import Plant
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
@ -24,22 +24,24 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
||||
|
||||
from .const import CONF_EXPIRATION, DOMAIN
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import FytaConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type FytaConfigEntry = ConfigEntry[FytaCoordinator]
|
||||
|
||||
|
||||
class FytaCoordinator(DataUpdateCoordinator[dict[int, Plant]]):
|
||||
"""Fyta custom coordinator."""
|
||||
|
||||
config_entry: FytaConfigEntry
|
||||
|
||||
def __init__(self, hass: HomeAssistant, fyta: FytaConnector) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: FytaConfigEntry, fyta: FytaConnector
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name="FYTA Coordinator",
|
||||
update_interval=timedelta(minutes=4),
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import FytaConfigEntry
|
||||
from .coordinator import FytaConfigEntry
|
||||
|
||||
TO_REDACT = [
|
||||
CONF_PASSWORD,
|
||||
|
@ -6,9 +6,8 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import FytaConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import FytaCoordinator
|
||||
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||
|
||||
|
||||
class FytaPlantEntity(CoordinatorEntity[FytaCoordinator]):
|
||||
|
@ -9,8 +9,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import FytaConfigEntry
|
||||
from .coordinator import FytaCoordinator
|
||||
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||
from .entity import FytaPlantEntity
|
||||
|
||||
|
||||
|
@ -25,8 +25,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import FytaConfigEntry
|
||||
from .coordinator import FytaCoordinator
|
||||
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||
from .entity import FytaPlantEntity
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user