Explicitly pass in the config_entry in mastodon coordinator (#138094)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 17:34:20 +01:00 committed by GitHub
parent f8d4a63644
commit e3822ed277
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 8 deletions

View File

@ -47,7 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: MastodonConfigEntry) ->
assert entry.unique_id
coordinator = MastodonCoordinator(hass, client)
coordinator = MastodonCoordinator(hass, entry, client)
await coordinator.async_config_entry_first_refresh()

View File

@ -32,10 +32,18 @@ type MastodonConfigEntry = ConfigEntry[MastodonData]
class MastodonCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Class to manage fetching Mastodon data."""
def __init__(self, hass: HomeAssistant, client: Mastodon) -> None:
config_entry: MastodonConfigEntry
def __init__(
self, hass: HomeAssistant, config_entry: MastodonConfigEntry, client: Mastodon
) -> None:
"""Initialize coordinator."""
super().__init__(
hass, logger=LOGGER, name="Mastodon", update_interval=timedelta(hours=1)
hass,
logger=LOGGER,
config_entry=config_entry,
name="Mastodon",
update_interval=timedelta(hours=1),
)
self.client = client

View File

@ -6,7 +6,7 @@ from typing import Any
from homeassistant.core import HomeAssistant
from . import MastodonConfigEntry
from .coordinator import MastodonConfigEntry
async def async_get_config_entry_diagnostics(

View File

@ -4,9 +4,8 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import MastodonConfigEntry
from .const import DEFAULT_NAME, DOMAIN, INSTANCE_VERSION
from .coordinator import MastodonCoordinator
from .coordinator import MastodonConfigEntry, MastodonCoordinator
from .utils import construct_mastodon_username

View File

@ -15,12 +15,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import MastodonConfigEntry
from .const import (
ACCOUNT_FOLLOWERS_COUNT,
ACCOUNT_FOLLOWING_COUNT,
ACCOUNT_STATUSES_COUNT,
)
from .coordinator import MastodonConfigEntry
from .entity import MastodonEntity
# Coordinator is used to centralize the data updates

View File

@ -12,7 +12,6 @@ from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant, ServiceCall, ServiceResponse
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from . import MastodonConfigEntry
from .const import (
ATTR_CONFIG_ENTRY_ID,
ATTR_CONTENT_WARNING,
@ -22,6 +21,7 @@ from .const import (
ATTR_VISIBILITY,
DOMAIN,
)
from .coordinator import MastodonConfigEntry
from .utils import get_media_type