mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 07:47:08 +00:00
Explicitly pass in the config_entry in google_photos coordinator (#137840)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
9e091f7a73
commit
11d5628da7
@ -12,9 +12,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import GooglePhotosUpdateCoordinator
|
from .coordinator import GooglePhotosConfigEntry, GooglePhotosUpdateCoordinator
|
||||||
from .services import async_register_services
|
from .services import async_register_services
|
||||||
from .types import GooglePhotosConfigEntry
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"DOMAIN",
|
"DOMAIN",
|
||||||
@ -43,7 +42,9 @@ async def async_setup_entry(
|
|||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
except ClientError as err:
|
except ClientError as err:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
coordinator = GooglePhotosUpdateCoordinator(hass, GooglePhotosLibraryApi(auth))
|
coordinator = GooglePhotosUpdateCoordinator(
|
||||||
|
hass, entry, GooglePhotosLibraryApi(auth)
|
||||||
|
)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from google_photos_library_api.api import GooglePhotosLibraryApi
|
|||||||
from google_photos_library_api.exceptions import GooglePhotosApiError
|
from google_photos_library_api.exceptions import GooglePhotosApiError
|
||||||
from google_photos_library_api.model import Album, NewAlbum
|
from google_photos_library_api.model import Album, NewAlbum
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -23,6 +24,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
UPDATE_INTERVAL: Final = datetime.timedelta(hours=24)
|
UPDATE_INTERVAL: Final = datetime.timedelta(hours=24)
|
||||||
ALBUM_PAGE_SIZE = 50
|
ALBUM_PAGE_SIZE = 50
|
||||||
|
|
||||||
|
type GooglePhotosConfigEntry = ConfigEntry[GooglePhotosUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class GooglePhotosUpdateCoordinator(DataUpdateCoordinator[dict[str, str]]):
|
class GooglePhotosUpdateCoordinator(DataUpdateCoordinator[dict[str, str]]):
|
||||||
"""Coordinator for fetching Google Photos albums.
|
"""Coordinator for fetching Google Photos albums.
|
||||||
@ -30,11 +33,19 @@ class GooglePhotosUpdateCoordinator(DataUpdateCoordinator[dict[str, str]]):
|
|||||||
The `data` object is a dict from Album ID to Album title.
|
The `data` object is a dict from Album ID to Album title.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, client: GooglePhotosLibraryApi) -> None:
|
config_entry: GooglePhotosConfigEntry
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: GooglePhotosConfigEntry,
|
||||||
|
client: GooglePhotosLibraryApi,
|
||||||
|
) -> None:
|
||||||
"""Initialize TaskUpdateCoordinator."""
|
"""Initialize TaskUpdateCoordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Google Photos",
|
name="Google Photos",
|
||||||
update_interval=UPDATE_INTERVAL,
|
update_interval=UPDATE_INTERVAL,
|
||||||
)
|
)
|
||||||
|
@ -20,8 +20,8 @@ from homeassistant.components.media_source import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import GooglePhotosConfigEntry
|
|
||||||
from .const import DOMAIN, READ_SCOPE
|
from .const import DOMAIN, READ_SCOPE
|
||||||
|
from .coordinator import GooglePhotosConfigEntry
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
|||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from .const import DOMAIN, UPLOAD_SCOPE
|
from .const import DOMAIN, UPLOAD_SCOPE
|
||||||
from .types import GooglePhotosConfigEntry
|
from .coordinator import GooglePhotosConfigEntry
|
||||||
|
|
||||||
CONF_CONFIG_ENTRY_ID = "config_entry_id"
|
CONF_CONFIG_ENTRY_ID = "config_entry_id"
|
||||||
CONF_ALBUM = "album"
|
CONF_ALBUM = "album"
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
"""Google Photos types."""
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
|
|
||||||
from .coordinator import GooglePhotosUpdateCoordinator
|
|
||||||
|
|
||||||
type GooglePhotosConfigEntry = ConfigEntry[GooglePhotosUpdateCoordinator]
|
|
Loading…
x
Reference in New Issue
Block a user