mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Explicitly pass in the config_entry in renault coordinator (#137977)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
8afc3568fb
commit
4706beb6ef
@ -6,7 +6,7 @@ import asyncio
|
||||
from collections.abc import Awaitable, Callable
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TypeVar
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
|
||||
from renault_api.kamereon.exceptions import (
|
||||
AccessDeniedException,
|
||||
@ -18,6 +18,9 @@ from renault_api.kamereon.models import KamereonVehicleDataAttributes
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import RenaultConfigEntry
|
||||
|
||||
T = TypeVar("T", bound=KamereonVehicleDataAttributes)
|
||||
|
||||
# We have potentially 7 coordinators per vehicle
|
||||
@ -27,11 +30,13 @@ _PARALLEL_SEMAPHORE = asyncio.Semaphore(1)
|
||||
class RenaultDataUpdateCoordinator(DataUpdateCoordinator[T]):
|
||||
"""Handle vehicle communication with Renault servers."""
|
||||
|
||||
config_entry: RenaultConfigEntry
|
||||
update_method: Callable[[], Awaitable[T]]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: RenaultConfigEntry,
|
||||
logger: logging.Logger,
|
||||
*,
|
||||
name: str,
|
||||
@ -42,6 +47,7 @@ class RenaultDataUpdateCoordinator(DataUpdateCoordinator[T]):
|
||||
super().__init__(
|
||||
hass,
|
||||
logger,
|
||||
config_entry=config_entry,
|
||||
name=name,
|
||||
update_interval=update_interval,
|
||||
update_method=update_method,
|
||||
|
@ -5,13 +5,13 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from renault_api.gigya.exceptions import InvalidCredentialsException
|
||||
from renault_api.kamereon.models import KamereonVehiclesLink
|
||||
from renault_api.renault_account import RenaultAccount
|
||||
from renault_api.renault_client import RenaultClient
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
@ -24,6 +24,9 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import RenaultConfigEntry
|
||||
|
||||
from .const import CONF_KAMEREON_ACCOUNT_ID, DEFAULT_SCAN_INTERVAL
|
||||
from .renault_vehicle import RenaultVehicleProxy
|
||||
|
||||
@ -52,7 +55,7 @@ class RenaultHub:
|
||||
return True
|
||||
return False
|
||||
|
||||
async def async_initialise(self, config_entry: ConfigEntry) -> None:
|
||||
async def async_initialise(self, config_entry: RenaultConfigEntry) -> None:
|
||||
"""Set up proxy."""
|
||||
account_id: str = config_entry.data[CONF_KAMEREON_ACCOUNT_ID]
|
||||
scan_interval = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
|
||||
@ -86,7 +89,7 @@ class RenaultHub:
|
||||
vehicle_link: KamereonVehiclesLink,
|
||||
renault_account: RenaultAccount,
|
||||
scan_interval: timedelta,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: RenaultConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Set up proxy."""
|
||||
@ -95,6 +98,7 @@ class RenaultHub:
|
||||
# Generate vehicle proxy
|
||||
vehicle = RenaultVehicleProxy(
|
||||
hass=self._hass,
|
||||
config_entry=config_entry,
|
||||
vehicle=await renault_account.get_api_vehicle(vehicle_link.vin),
|
||||
details=vehicle_link.vehicleDetails,
|
||||
scan_interval=scan_interval,
|
||||
|
@ -8,7 +8,7 @@ from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from functools import wraps
|
||||
import logging
|
||||
from typing import Any, Concatenate, cast
|
||||
from typing import TYPE_CHECKING, Any, Concatenate, cast
|
||||
|
||||
from renault_api.exceptions import RenaultException
|
||||
from renault_api.kamereon import models
|
||||
@ -18,6 +18,9 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import RenaultConfigEntry
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import RenaultDataUpdateCoordinator
|
||||
|
||||
@ -64,12 +67,14 @@ class RenaultVehicleProxy:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: RenaultConfigEntry,
|
||||
vehicle: RenaultVehicle,
|
||||
details: models.KamereonVehicleDetails,
|
||||
scan_interval: timedelta,
|
||||
) -> None:
|
||||
"""Initialise vehicle proxy."""
|
||||
self.hass = hass
|
||||
self.config_entry = config_entry
|
||||
self._vehicle = vehicle
|
||||
self._details = details
|
||||
self._device_info = DeviceInfo(
|
||||
@ -98,11 +103,10 @@ class RenaultVehicleProxy:
|
||||
self.coordinators = {
|
||||
coord.key: RenaultDataUpdateCoordinator(
|
||||
self.hass,
|
||||
self.config_entry,
|
||||
LOGGER,
|
||||
# Name of the data. For logging purposes.
|
||||
name=f"{self.details.vin} {coord.key}",
|
||||
update_method=coord.update_method(self._vehicle),
|
||||
# Polling interval. Will only be polled if there are subscribers.
|
||||
update_interval=self._scan_interval,
|
||||
)
|
||||
for coord in COORDINATORS
|
||||
|
Loading…
x
Reference in New Issue
Block a user