Explicitly pass in the config_entry in wallbox coordinator (#137874)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 00:39:11 +01:00 committed by GitHub
parent 50c15f3056
commit 17569d8186
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View File

@ -9,7 +9,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from .const import CONF_STATION, DOMAIN, UPDATE_INTERVAL
from .const import DOMAIN, UPDATE_INTERVAL
from .coordinator import InvalidAuth, WallboxCoordinator, async_validate_input
PLATFORMS = [Platform.LOCK, Platform.NUMBER, Platform.SENSOR, Platform.SWITCH]
@ -27,11 +27,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except InvalidAuth as ex:
raise ConfigEntryAuthFailed from ex
wallbox_coordinator = WallboxCoordinator(
entry.data[CONF_STATION],
wallbox,
hass,
)
wallbox_coordinator = WallboxCoordinator(hass, entry, wallbox)
await wallbox_coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = wallbox_coordinator

View File

@ -11,6 +11,7 @@ from typing import Any, Concatenate
import requests
from wallbox import Wallbox
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
@ -28,6 +29,7 @@ from .const import (
CHARGER_STATUS_DESCRIPTION_KEY,
CHARGER_STATUS_ID_KEY,
CODE_KEY,
CONF_STATION,
DOMAIN,
UPDATE_INTERVAL,
ChargerStatus,
@ -107,14 +109,19 @@ async def async_validate_input(hass: HomeAssistant, wallbox: Wallbox) -> None:
class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Wallbox Coordinator class."""
def __init__(self, station: str, wallbox: Wallbox, hass: HomeAssistant) -> None:
config_entry: ConfigEntry
def __init__(
self, hass: HomeAssistant, config_entry: ConfigEntry, wallbox: Wallbox
) -> None:
"""Initialize."""
self._station = station
self._station = config_entry.data[CONF_STATION]
self._wallbox = wallbox
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=timedelta(seconds=UPDATE_INTERVAL),
)