mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Explicitly pass in the config_entry in teslemetry coordinator (#137907)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
8a7d96919d
commit
133fdb0ed2
@ -112,7 +112,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
||||
product.pop("cached_data", None)
|
||||
vin = product["vin"]
|
||||
api = VehicleSpecific(teslemetry.vehicle, vin)
|
||||
coordinator = TeslemetryVehicleDataCoordinator(hass, api, product)
|
||||
coordinator = TeslemetryVehicleDataCoordinator(hass, entry, api, product)
|
||||
device = DeviceInfo(
|
||||
identifiers={(DOMAIN, vin)},
|
||||
manufacturer="Tesla",
|
||||
@ -177,15 +177,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
||||
TeslemetryEnergyData(
|
||||
api=api,
|
||||
live_coordinator=(
|
||||
TeslemetryEnergySiteLiveCoordinator(hass, api, live_status)
|
||||
TeslemetryEnergySiteLiveCoordinator(
|
||||
hass, entry, api, live_status
|
||||
)
|
||||
if isinstance(live_status, dict)
|
||||
else None
|
||||
),
|
||||
info_coordinator=TeslemetryEnergySiteInfoCoordinator(
|
||||
hass, api, product
|
||||
hass, entry, api, product
|
||||
),
|
||||
history_coordinator=(
|
||||
TeslemetryEnergyHistoryCoordinator(hass, api)
|
||||
TeslemetryEnergyHistoryCoordinator(hass, entry, api)
|
||||
if powerwall
|
||||
else None
|
||||
),
|
||||
@ -242,7 +244,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry)
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_migrate_entry(
|
||||
hass: HomeAssistant, config_entry: TeslemetryConfigEntry
|
||||
) -> bool:
|
||||
"""Migrate config entry."""
|
||||
if config_entry.version > 1:
|
||||
return False
|
||||
@ -282,7 +286,7 @@ def create_handle_vehicle_stream(vin: str, coordinator) -> Callable[[dict], None
|
||||
|
||||
|
||||
async def async_setup_stream(
|
||||
hass: HomeAssistant, entry: ConfigEntry, vehicle: TeslemetryVehicleData
|
||||
hass: HomeAssistant, entry: TeslemetryConfigEntry, vehicle: TeslemetryVehicleData
|
||||
):
|
||||
"""Set up the stream for a vehicle."""
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
"""Teslemetry Data Coordinator."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from tesla_fleet_api import EnergySpecific, VehicleSpecific
|
||||
from tesla_fleet_api.const import TeslaEnergyPeriod, VehicleDataEndpoint
|
||||
@ -15,6 +17,9 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import TeslemetryConfigEntry
|
||||
|
||||
from .const import ENERGY_HISTORY_FIELDS, LOGGER
|
||||
from .helpers import flatten
|
||||
|
||||
@ -37,15 +42,21 @@ ENDPOINTS = [
|
||||
class TeslemetryVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
"""Class to manage fetching data from the Teslemetry API."""
|
||||
|
||||
config_entry: TeslemetryConfigEntry
|
||||
last_active: datetime
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, api: VehicleSpecific, product: dict
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: TeslemetryConfigEntry,
|
||||
api: VehicleSpecific,
|
||||
product: dict,
|
||||
) -> None:
|
||||
"""Initialize Teslemetry Vehicle Update Coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
LOGGER,
|
||||
config_entry=config_entry,
|
||||
name="Teslemetry Vehicle",
|
||||
update_interval=VEHICLE_INTERVAL,
|
||||
)
|
||||
@ -69,9 +80,16 @@ class TeslemetryVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
class TeslemetryEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
"""Class to manage fetching energy site live status from the Teslemetry API."""
|
||||
|
||||
config_entry: TeslemetryConfigEntry
|
||||
updated_once: bool
|
||||
|
||||
def __init__(self, hass: HomeAssistant, api: EnergySpecific, data: dict) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: TeslemetryConfigEntry,
|
||||
api: EnergySpecific,
|
||||
data: dict,
|
||||
) -> None:
|
||||
"""Initialize Teslemetry Energy Site Live coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
@ -108,7 +126,15 @@ class TeslemetryEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]])
|
||||
class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
"""Class to manage fetching energy site info from the Teslemetry API."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, api: EnergySpecific, product: dict) -> None:
|
||||
config_entry: TeslemetryConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: TeslemetryConfigEntry,
|
||||
api: EnergySpecific,
|
||||
product: dict,
|
||||
) -> None:
|
||||
"""Initialize Teslemetry Energy Info coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
@ -135,7 +161,14 @@ class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]])
|
||||
class TeslemetryEnergyHistoryCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
"""Class to manage fetching energy site info from the Teslemetry API."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, api: EnergySpecific) -> None:
|
||||
config_entry: TeslemetryConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: TeslemetryConfigEntry,
|
||||
api: EnergySpecific,
|
||||
) -> None:
|
||||
"""Initialize Teslemetry Energy Info coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
|
Loading…
x
Reference in New Issue
Block a user