Explicitly pass in the config_entry in opower coordinator (#138048)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 16:33:51 +01:00 committed by GitHub
parent 8241429c5e
commit 020e8fe939
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,7 @@ PLATFORMS: list[Platform] = [Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: OpowerConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: OpowerConfigEntry) -> bool:
"""Set up Opower from a config entry.""" """Set up Opower from a config entry."""
coordinator = OpowerCoordinator(hass, entry.data) coordinator = OpowerCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator entry.runtime_data = coordinator

View File

@ -2,8 +2,7 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
from types import MappingProxyType from typing import cast
from typing import Any, cast
from opower import ( from opower import (
Account, Account,
@ -46,12 +45,13 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]):
def __init__( def __init__(
self, self,
hass: HomeAssistant, hass: HomeAssistant,
entry_data: MappingProxyType[str, Any], config_entry: OpowerConfigEntry,
) -> None: ) -> None:
"""Initialize the data handler.""" """Initialize the data handler."""
super().__init__( super().__init__(
hass, hass,
_LOGGER, _LOGGER,
config_entry=config_entry,
name="Opower", name="Opower",
# Data is updated daily on Opower. # Data is updated daily on Opower.
# Refresh every 12h to be at most 12h behind. # Refresh every 12h to be at most 12h behind.
@ -59,10 +59,10 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]):
) )
self.api = Opower( self.api = Opower(
aiohttp_client.async_get_clientsession(hass), aiohttp_client.async_get_clientsession(hass),
entry_data[CONF_UTILITY], config_entry.data[CONF_UTILITY],
entry_data[CONF_USERNAME], config_entry.data[CONF_USERNAME],
entry_data[CONF_PASSWORD], config_entry.data[CONF_PASSWORD],
entry_data.get(CONF_TOTP_SECRET), config_entry.data.get(CONF_TOTP_SECRET),
) )
self._statistic_ids: set[str] = set() self._statistic_ids: set[str] = set()