Set config_entry explicitly in history stats coordinator (#129417)

Set config_entry explicitely in history stats coordinator
This commit is contained in:
epenet 2024-10-29 15:32:56 +01:00 committed by GitHub
parent 5dc0bedbc4
commit 5d3af27928
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 2 deletions

View File

@ -41,7 +41,7 @@ async def async_setup_entry(
Template(end, hass) if end else None,
duration,
)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, entry.title)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, entry, entry.title)
await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator

View File

@ -6,6 +6,7 @@ from datetime import timedelta
import logging
from typing import Any
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import (
CALLBACK_TYPE,
Event,
@ -33,6 +34,7 @@ class HistoryStatsUpdateCoordinator(DataUpdateCoordinator[HistoryStatsState]):
self,
hass: HomeAssistant,
history_stats: HistoryStats,
config_entry: ConfigEntry | None,
name: str,
) -> None:
"""Initialize DataUpdateCoordinator."""
@ -43,6 +45,7 @@ class HistoryStatsUpdateCoordinator(DataUpdateCoordinator[HistoryStatsState]):
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=name,
update_interval=UPDATE_INTERVAL,
)

View File

@ -104,7 +104,7 @@ async def async_setup_platform(
unique_id: str | None = config.get(CONF_UNIQUE_ID)
history_stats = HistoryStats(hass, entity_id, entity_states, start, end, duration)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, name)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, None, name)
await coordinator.async_refresh()
if not coordinator.last_update_success:
raise PlatformNotReady from coordinator.last_exception