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, Template(end, hass) if end else None,
duration, duration,
) )
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, entry.title) coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, entry, entry.title)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator entry.runtime_data = coordinator

View File

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

View File

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