mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +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 fyta_cli.fyta_connector import FytaConnector
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ACCESS_TOKEN,
|
CONF_ACCESS_TOKEN,
|
||||||
CONF_PASSWORD,
|
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 homeassistant.util.dt import async_get_time_zone
|
||||||
|
|
||||||
from .const import CONF_EXPIRATION
|
from .const import CONF_EXPIRATION
|
||||||
from .coordinator import FytaCoordinator
|
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -28,7 +27,6 @@ PLATFORMS = [
|
|||||||
Platform.IMAGE,
|
Platform.IMAGE,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
]
|
]
|
||||||
type FytaConfigEntry = ConfigEntry[FytaCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: FytaConfigEntry) -> bool:
|
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)
|
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()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from homeassistant.const import EntityCategory
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import FytaConfigEntry
|
from .coordinator import FytaConfigEntry
|
||||||
from .entity import FytaPlantEntity
|
from .entity import FytaPlantEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from fyta_cli.fyta_connector import FytaConnector
|
from fyta_cli.fyta_connector import FytaConnector
|
||||||
from fyta_cli.fyta_exceptions import (
|
from fyta_cli.fyta_exceptions import (
|
||||||
@ -16,6 +15,7 @@ from fyta_cli.fyta_exceptions import (
|
|||||||
)
|
)
|
||||||
from fyta_cli.fyta_models import Plant
|
from fyta_cli.fyta_models import Plant
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
@ -24,22 +24,24 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||||||
|
|
||||||
from .const import CONF_EXPIRATION, DOMAIN
|
from .const import CONF_EXPIRATION, DOMAIN
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from . import FytaConfigEntry
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type FytaConfigEntry = ConfigEntry[FytaCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class FytaCoordinator(DataUpdateCoordinator[dict[int, Plant]]):
|
class FytaCoordinator(DataUpdateCoordinator[dict[int, Plant]]):
|
||||||
"""Fyta custom coordinator."""
|
"""Fyta custom coordinator."""
|
||||||
|
|
||||||
config_entry: FytaConfigEntry
|
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."""
|
"""Initialize my coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="FYTA Coordinator",
|
name="FYTA Coordinator",
|
||||||
update_interval=timedelta(minutes=4),
|
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.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import FytaConfigEntry
|
from .coordinator import FytaConfigEntry
|
||||||
|
|
||||||
TO_REDACT = [
|
TO_REDACT = [
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
|
@ -6,9 +6,8 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import FytaConfigEntry
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import FytaCoordinator
|
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||||
|
|
||||||
|
|
||||||
class FytaPlantEntity(CoordinatorEntity[FytaCoordinator]):
|
class FytaPlantEntity(CoordinatorEntity[FytaCoordinator]):
|
||||||
|
@ -9,8 +9,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import FytaConfigEntry
|
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||||
from .coordinator import FytaCoordinator
|
|
||||||
from .entity import FytaPlantEntity
|
from .entity import FytaPlantEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +25,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import FytaConfigEntry
|
from .coordinator import FytaConfigEntry, FytaCoordinator
|
||||||
from .coordinator import FytaCoordinator
|
|
||||||
from .entity import FytaPlantEntity
|
from .entity import FytaPlantEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user