Explicitly pass in the config_entry in v2c coordinator (#137882)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 18:51:39 +01:00 committed by GitHub
parent 907826e909
commit 8fcc1f7e10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 18 additions and 21 deletions

View File

@ -4,12 +4,11 @@ from __future__ import annotations
from pytrydan import Trydan
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.httpx_client import get_async_client
from .coordinator import V2CUpdateCoordinator
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
PLATFORMS: list[Platform] = [
Platform.BINARY_SENSOR,
@ -19,15 +18,11 @@ PLATFORMS: list[Platform] = [
]
type V2CConfigEntry = ConfigEntry[V2CUpdateCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
"""Set up V2C from a config entry."""
host = entry.data[CONF_HOST]
trydan = Trydan(host, get_async_client(hass, verify_ssl=False))
coordinator = V2CUpdateCoordinator(hass, trydan, host)
trydan = Trydan(entry.data[CONF_HOST], get_async_client(hass, verify_ssl=False))
coordinator = V2CUpdateCoordinator(hass, entry, trydan)
await coordinator.async_config_entry_first_refresh()
@ -41,6 +36,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

View File

@ -15,8 +15,7 @@ from homeassistant.components.binary_sensor import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import V2CConfigEntry
from .coordinator import V2CUpdateCoordinator
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
from .entity import V2CBaseEntity

View File

@ -9,6 +9,7 @@ from pytrydan import Trydan, TrydanData
from pytrydan.exceptions import TrydanError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@ -16,19 +17,24 @@ SCAN_INTERVAL = timedelta(seconds=5)
_LOGGER = logging.getLogger(__name__)
type V2CConfigEntry = ConfigEntry[V2CUpdateCoordinator]
class V2CUpdateCoordinator(DataUpdateCoordinator[TrydanData]):
"""DataUpdateCoordinator to gather data from any v2c."""
config_entry: ConfigEntry
config_entry: V2CConfigEntry
def __init__(self, hass: HomeAssistant, evse: Trydan, host: str) -> None:
def __init__(
self, hass: HomeAssistant, config_entry: V2CConfigEntry, evse: Trydan
) -> None:
"""Initialize DataUpdateCoordinator for a v2c evse."""
self.evse = evse
super().__init__(
hass,
_LOGGER,
name=f"EVSE {host}",
config_entry=config_entry,
name=f"EVSE {config_entry.data[CONF_HOST]}",
update_interval=SCAN_INTERVAL,
)

View File

@ -8,7 +8,7 @@ from homeassistant.components.diagnostics import async_redact_data
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from . import V2CConfigEntry
from .coordinator import V2CConfigEntry
TO_REDACT = {CONF_HOST, "title"}

View File

@ -17,8 +17,7 @@ from homeassistant.const import EntityCategory, UnitOfElectricCurrent
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import V2CConfigEntry
from .coordinator import V2CUpdateCoordinator
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
from .entity import V2CBaseEntity
MIN_INTENSITY = 6

View File

@ -26,8 +26,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import V2CConfigEntry
from .coordinator import V2CUpdateCoordinator
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
from .entity import V2CBaseEntity
_LOGGER = logging.getLogger(__name__)

View File

@ -20,8 +20,7 @@ from homeassistant.components.switch import SwitchEntity, SwitchEntityDescriptio
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import V2CConfigEntry
from .coordinator import V2CUpdateCoordinator
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
from .entity import V2CBaseEntity
_LOGGER = logging.getLogger(__name__)