Improve history coordinator in Teslemetry (#128235)
parent
c6cb2884f4
commit
96de4b3828
|
@ -135,11 +135,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
|||
|
||||
elif "energy_site_id" in product and Scope.ENERGY_DEVICE_DATA in scopes:
|
||||
site_id = product["energy_site_id"]
|
||||
if not (
|
||||
product["components"]["battery"]
|
||||
or product["components"]["solar"]
|
||||
or "wall_connectors" in product["components"]
|
||||
):
|
||||
powerwall = (
|
||||
product["components"]["battery"] or product["components"]["solar"]
|
||||
)
|
||||
wall_connector = "wall_connectors" in product["components"]
|
||||
if not powerwall and not wall_connector:
|
||||
LOGGER.debug(
|
||||
"Skipping Energy Site %s as it has no components",
|
||||
site_id,
|
||||
|
@ -162,7 +162,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
|||
info_coordinator=TeslemetryEnergySiteInfoCoordinator(
|
||||
hass, api, product
|
||||
),
|
||||
history_coordinator=TeslemetryEnergyHistoryCoordinator(hass, api),
|
||||
history_coordinator=(
|
||||
TeslemetryEnergyHistoryCoordinator(hass, api)
|
||||
if powerwall
|
||||
else None
|
||||
),
|
||||
id=site_id,
|
||||
device=device,
|
||||
)
|
||||
|
@ -185,6 +189,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
|||
*(
|
||||
energysite.history_coordinator.async_config_entry_first_refresh()
|
||||
for energysite in energysites
|
||||
if energysite.history_coordinator
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
@ -175,6 +175,8 @@ class TeslemetryEnergyHistoryEntity(TeslemetryEntity):
|
|||
) -> None:
|
||||
"""Initialize common aspects of a Teslemetry Energy Site Info entity."""
|
||||
|
||||
assert data.history_coordinator
|
||||
|
||||
self.api = data.api
|
||||
self._attr_unique_id = f"{data.id}-{key}"
|
||||
self._attr_device_info = data.device
|
||||
|
|
|
@ -49,6 +49,6 @@ class TeslemetryEnergyData:
|
|||
api: EnergySpecific
|
||||
live_coordinator: TeslemetryEnergySiteLiveCoordinator
|
||||
info_coordinator: TeslemetryEnergySiteInfoCoordinator
|
||||
history_coordinator: TeslemetryEnergyHistoryCoordinator
|
||||
history_coordinator: TeslemetryEnergyHistoryCoordinator | None
|
||||
id: int
|
||||
device: DeviceInfo
|
||||
|
|
|
@ -482,8 +482,7 @@ async def async_setup_entry(
|
|||
TeslemetryEnergyHistorySensorEntity(energysite, description)
|
||||
for energysite in entry.runtime_data.energysites
|
||||
for description in ENERGY_HISTORY_DESCRIPTIONS
|
||||
if energysite.info_coordinator.data.get("components_battery")
|
||||
or energysite.info_coordinator.data.get("components_solar")
|
||||
if energysite.history_coordinator
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue