mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +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)
|
product.pop("cached_data", None)
|
||||||
vin = product["vin"]
|
vin = product["vin"]
|
||||||
api = VehicleSpecific(teslemetry.vehicle, vin)
|
api = VehicleSpecific(teslemetry.vehicle, vin)
|
||||||
coordinator = TeslemetryVehicleDataCoordinator(hass, api, product)
|
coordinator = TeslemetryVehicleDataCoordinator(hass, entry, api, product)
|
||||||
device = DeviceInfo(
|
device = DeviceInfo(
|
||||||
identifiers={(DOMAIN, vin)},
|
identifiers={(DOMAIN, vin)},
|
||||||
manufacturer="Tesla",
|
manufacturer="Tesla",
|
||||||
@ -177,15 +177,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
|||||||
TeslemetryEnergyData(
|
TeslemetryEnergyData(
|
||||||
api=api,
|
api=api,
|
||||||
live_coordinator=(
|
live_coordinator=(
|
||||||
TeslemetryEnergySiteLiveCoordinator(hass, api, live_status)
|
TeslemetryEnergySiteLiveCoordinator(
|
||||||
|
hass, entry, api, live_status
|
||||||
|
)
|
||||||
if isinstance(live_status, dict)
|
if isinstance(live_status, dict)
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
info_coordinator=TeslemetryEnergySiteInfoCoordinator(
|
info_coordinator=TeslemetryEnergySiteInfoCoordinator(
|
||||||
hass, api, product
|
hass, entry, api, product
|
||||||
),
|
),
|
||||||
history_coordinator=(
|
history_coordinator=(
|
||||||
TeslemetryEnergyHistoryCoordinator(hass, api)
|
TeslemetryEnergyHistoryCoordinator(hass, entry, api)
|
||||||
if powerwall
|
if powerwall
|
||||||
else None
|
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)
|
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."""
|
"""Migrate config entry."""
|
||||||
if config_entry.version > 1:
|
if config_entry.version > 1:
|
||||||
return False
|
return False
|
||||||
@ -282,7 +286,7 @@ def create_handle_vehicle_stream(vin: str, coordinator) -> Callable[[dict], None
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_stream(
|
async def async_setup_stream(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, vehicle: TeslemetryVehicleData
|
hass: HomeAssistant, entry: TeslemetryConfigEntry, vehicle: TeslemetryVehicleData
|
||||||
):
|
):
|
||||||
"""Set up the stream for a vehicle."""
|
"""Set up the stream for a vehicle."""
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
"""Teslemetry Data Coordinator."""
|
"""Teslemetry Data Coordinator."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
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 import EnergySpecific, VehicleSpecific
|
||||||
from tesla_fleet_api.const import TeslaEnergyPeriod, VehicleDataEndpoint
|
from tesla_fleet_api.const import TeslaEnergyPeriod, VehicleDataEndpoint
|
||||||
@ -15,6 +17,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 TeslemetryConfigEntry
|
||||||
|
|
||||||
from .const import ENERGY_HISTORY_FIELDS, LOGGER
|
from .const import ENERGY_HISTORY_FIELDS, LOGGER
|
||||||
from .helpers import flatten
|
from .helpers import flatten
|
||||||
|
|
||||||
@ -37,15 +42,21 @@ ENDPOINTS = [
|
|||||||
class TeslemetryVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslemetryVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching data from the Teslemetry API."""
|
"""Class to manage fetching data from the Teslemetry API."""
|
||||||
|
|
||||||
|
config_entry: TeslemetryConfigEntry
|
||||||
last_active: datetime
|
last_active: datetime
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, api: VehicleSpecific, product: dict
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: TeslemetryConfigEntry,
|
||||||
|
api: VehicleSpecific,
|
||||||
|
product: dict,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize Teslemetry Vehicle Update Coordinator."""
|
"""Initialize Teslemetry Vehicle Update Coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Teslemetry Vehicle",
|
name="Teslemetry Vehicle",
|
||||||
update_interval=VEHICLE_INTERVAL,
|
update_interval=VEHICLE_INTERVAL,
|
||||||
)
|
)
|
||||||
@ -69,9 +80,16 @@ class TeslemetryVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
class TeslemetryEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslemetryEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching energy site live status from the Teslemetry API."""
|
"""Class to manage fetching energy site live status from the Teslemetry API."""
|
||||||
|
|
||||||
|
config_entry: TeslemetryConfigEntry
|
||||||
updated_once: bool
|
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."""
|
"""Initialize Teslemetry Energy Site Live coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
@ -108,7 +126,15 @@ class TeslemetryEnergySiteLiveCoordinator(DataUpdateCoordinator[dict[str, Any]])
|
|||||||
class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching energy site info from the Teslemetry API."""
|
"""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."""
|
"""Initialize Teslemetry Energy Info coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
@ -135,7 +161,14 @@ class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]])
|
|||||||
class TeslemetryEnergyHistoryCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class TeslemetryEnergyHistoryCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching energy site info from the Teslemetry API."""
|
"""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."""
|
"""Initialize Teslemetry Energy Info coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user