Explicitly pass in the config_entry in husqvarna_automower coordinator (#138149)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 21:05:42 +01:00 committed by GitHub
parent b65403f332
commit ec3e888372
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 10 deletions

View File

@ -5,7 +5,6 @@ import logging
from aioautomower.session import AutomowerSession from aioautomower.session import AutomowerSession
from aiohttp import ClientResponseError from aiohttp import ClientResponseError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
@ -13,7 +12,7 @@ from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from . import api from . import api
from .coordinator import AutomowerDataUpdateCoordinator from .coordinator import AutomowerConfigEntry, AutomowerDataUpdateCoordinator
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -29,8 +28,6 @@ PLATFORMS: list[Platform] = [
Platform.SWITCH, Platform.SWITCH,
] ]
type AutomowerConfigEntry = ConfigEntry[AutomowerDataUpdateCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: AutomowerConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: AutomowerConfigEntry) -> bool:
"""Set up this integration using UI.""" """Set up this integration using UI."""
@ -61,7 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: AutomowerConfigEntry) ->
# without the scope. So only polling would be possible. # without the scope. So only polling would be possible.
raise ConfigEntryAuthFailed raise ConfigEntryAuthFailed
coordinator = AutomowerDataUpdateCoordinator(hass, automower_api) coordinator = AutomowerDataUpdateCoordinator(hass, entry, automower_api)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator entry.runtime_data = coordinator

View File

@ -6,7 +6,6 @@ import asyncio
from collections.abc import Callable from collections.abc import Callable
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import TYPE_CHECKING
from aioautomower.exceptions import ( from aioautomower.exceptions import (
ApiError, ApiError,
@ -17,6 +16,7 @@ from aioautomower.exceptions import (
from aioautomower.model import MowerAttributes from aioautomower.model import MowerAttributes
from aioautomower.session import AutomowerSession from aioautomower.session import AutomowerSession
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers import device_registry as dr, entity_registry as er
@ -24,25 +24,30 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import DOMAIN from .const import DOMAIN
if TYPE_CHECKING:
from . import AutomowerConfigEntry
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
MAX_WS_RECONNECT_TIME = 600 MAX_WS_RECONNECT_TIME = 600
SCAN_INTERVAL = timedelta(minutes=8) SCAN_INTERVAL = timedelta(minutes=8)
DEFAULT_RECONNECT_TIME = 2 # Define a default reconnect time DEFAULT_RECONNECT_TIME = 2 # Define a default reconnect time
type AutomowerConfigEntry = ConfigEntry[AutomowerDataUpdateCoordinator]
class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[dict[str, MowerAttributes]]): class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[dict[str, MowerAttributes]]):
"""Class to manage fetching Husqvarna data.""" """Class to manage fetching Husqvarna data."""
config_entry: AutomowerConfigEntry config_entry: AutomowerConfigEntry
def __init__(self, hass: HomeAssistant, api: AutomowerSession) -> None: def __init__(
self,
hass: HomeAssistant,
config_entry: AutomowerConfigEntry,
api: AutomowerSession,
) -> None:
"""Initialize data updater.""" """Initialize data updater."""
super().__init__( super().__init__(
hass, hass,
_LOGGER, _LOGGER,
config_entry=config_entry,
name=DOMAIN, name=DOMAIN,
update_interval=SCAN_INTERVAL, update_interval=SCAN_INTERVAL,
) )