mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Explicitly pass in the config_entry in tesla_fleet coordinator (#137909)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
017af4fcf8
commit
e4ec217cfa
@ -139,7 +139,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslaFleetConfigEntry) -
|
|||||||
api = VehicleSigned(tesla.vehicle, vin)
|
api = VehicleSigned(tesla.vehicle, vin)
|
||||||
else:
|
else:
|
||||||
api = VehicleSpecific(tesla.vehicle, vin)
|
api = VehicleSpecific(tesla.vehicle, vin)
|
||||||
coordinator = TeslaFleetVehicleDataCoordinator(hass, api, product)
|
coordinator = TeslaFleetVehicleDataCoordinator(hass, entry, api, product)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
@ -175,9 +175,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslaFleetConfigEntry) -
|
|||||||
|
|
||||||
api = EnergySpecific(tesla.energy, site_id)
|
api = EnergySpecific(tesla.energy, site_id)
|
||||||
|
|
||||||
live_coordinator = TeslaFleetEnergySiteLiveCoordinator(hass, api)
|
live_coordinator = TeslaFleetEnergySiteLiveCoordinator(hass, entry, api)
|
||||||
history_coordinator = TeslaFleetEnergySiteHistoryCoordinator(hass, api)
|
history_coordinator = TeslaFleetEnergySiteHistoryCoordinator(
|
||||||
info_coordinator = TeslaFleetEnergySiteInfoCoordinator(hass, api, product)
|
hass, entry, api
|
||||||
|
)
|
||||||
|
info_coordinator = TeslaFleetEnergySiteInfoCoordinator(
|
||||||
|
hass, entry, api, product
|
||||||
|
)
|
||||||
|
|
||||||
await live_coordinator.async_config_entry_first_refresh()
|
await live_coordinator.async_config_entry_first_refresh()
|
||||||
await history_coordinator.async_config_entry_first_refresh()
|
await history_coordinator.async_config_entry_first_refresh()
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
"""Tesla Fleet Data Coordinator."""
|
"""Tesla Fleet Data Coordinator."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from random import randint
|
from random import randint
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from tesla_fleet_api import EnergySpecific, VehicleSpecific
|
from tesla_fleet_api import EnergySpecific, VehicleSpecific
|
||||||
from tesla_fleet_api.const import TeslaEnergyPeriod, VehicleDataEndpoint
|
from tesla_fleet_api.const import TeslaEnergyPeriod, VehicleDataEndpoint
|
||||||
@ -21,6 +23,9 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import TeslaFleetConfigEntry
|
||||||
|
|
||||||
from .const import ENERGY_HISTORY_FIELDS, LOGGER, TeslaFleetState
|
from .const import ENERGY_HISTORY_FIELDS, LOGGER, TeslaFleetState
|
||||||
|
|
||||||
VEHICLE_INTERVAL_SECONDS = 300
|
VEHICLE_INTERVAL_SECONDS = 300
|
||||||
@ -57,18 +62,24 @@ def flatten(data: dict[str, Any], parent: str | None = None) -> dict[str, Any]:
|
|||||||
class TeslaFleetVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslaFleetVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching data from the TeslaFleet API."""
|
"""Class to manage fetching data from the TeslaFleet API."""
|
||||||
|
|
||||||
|
config_entry: TeslaFleetConfigEntry
|
||||||
updated_once: bool
|
updated_once: bool
|
||||||
pre2021: bool
|
pre2021: bool
|
||||||
last_active: datetime
|
last_active: datetime
|
||||||
rate: RateCalculator
|
rate: RateCalculator
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, api: VehicleSpecific, product: dict
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: TeslaFleetConfigEntry,
|
||||||
|
api: VehicleSpecific,
|
||||||
|
product: dict,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize TeslaFleet Vehicle Update Coordinator."""
|
"""Initialize TeslaFleet Vehicle Update Coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Tesla Fleet Vehicle",
|
name="Tesla Fleet Vehicle",
|
||||||
update_interval=VEHICLE_INTERVAL,
|
update_interval=VEHICLE_INTERVAL,
|
||||||
)
|
)
|
||||||
@ -141,13 +152,20 @@ class TeslaFleetVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
class TeslaFleetEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslaFleetEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching energy site live status from the TeslaFleet API."""
|
"""Class to manage fetching energy site live status from the TeslaFleet API."""
|
||||||
|
|
||||||
|
config_entry: TeslaFleetConfigEntry
|
||||||
updated_once: bool
|
updated_once: bool
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: EnergySpecific) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: TeslaFleetConfigEntry,
|
||||||
|
api: EnergySpecific,
|
||||||
|
) -> None:
|
||||||
"""Initialize TeslaFleet Energy Site Live coordinator."""
|
"""Initialize TeslaFleet Energy Site Live coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Tesla Fleet Energy Site Live",
|
name="Tesla Fleet Energy Site Live",
|
||||||
update_interval=timedelta(seconds=10),
|
update_interval=timedelta(seconds=10),
|
||||||
)
|
)
|
||||||
@ -188,11 +206,19 @@ class TeslaFleetEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]])
|
|||||||
class TeslaFleetEnergySiteHistoryCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslaFleetEnergySiteHistoryCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching energy site history import and export from the Tesla Fleet API."""
|
"""Class to manage fetching energy site history import and export from the Tesla Fleet API."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: EnergySpecific) -> None:
|
config_entry: TeslaFleetConfigEntry
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: TeslaFleetConfigEntry,
|
||||||
|
api: EnergySpecific,
|
||||||
|
) -> None:
|
||||||
"""Initialize Tesla Fleet Energy Site History coordinator."""
|
"""Initialize Tesla Fleet Energy Site History coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=f"Tesla Fleet Energy History {api.energy_site_id}",
|
name=f"Tesla Fleet Energy History {api.energy_site_id}",
|
||||||
update_interval=timedelta(seconds=300),
|
update_interval=timedelta(seconds=300),
|
||||||
)
|
)
|
||||||
@ -243,13 +269,21 @@ class TeslaFleetEnergySiteHistoryCoordinator(DataUpdateCoordinator[dict[str, Any
|
|||||||
class TeslaFleetEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslaFleetEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching energy site info from the TeslaFleet API."""
|
"""Class to manage fetching energy site info from the TeslaFleet API."""
|
||||||
|
|
||||||
|
config_entry: TeslaFleetConfigEntry
|
||||||
updated_once: bool
|
updated_once: bool
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: EnergySpecific, product: dict) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: TeslaFleetConfigEntry,
|
||||||
|
api: EnergySpecific,
|
||||||
|
product: dict,
|
||||||
|
) -> None:
|
||||||
"""Initialize TeslaFleet Energy Info coordinator."""
|
"""Initialize TeslaFleet Energy Info coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Tesla Fleet Energy Site Info",
|
name="Tesla Fleet Energy Site Info",
|
||||||
update_interval=timedelta(seconds=15),
|
update_interval=timedelta(seconds=15),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user