mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Explicitly pass in the config_entry in v2c coordinator (#137882)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
907826e909
commit
8fcc1f7e10
@ -4,12 +4,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from pytrydan import Trydan
|
from pytrydan import Trydan
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_HOST, Platform
|
from homeassistant.const import CONF_HOST, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
|
|
||||||
from .coordinator import V2CUpdateCoordinator
|
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -19,15 +18,11 @@ PLATFORMS: list[Platform] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
type V2CConfigEntry = ConfigEntry[V2CUpdateCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
|
||||||
"""Set up V2C from a config entry."""
|
"""Set up V2C from a config entry."""
|
||||||
|
|
||||||
host = entry.data[CONF_HOST]
|
trydan = Trydan(entry.data[CONF_HOST], get_async_client(hass, verify_ssl=False))
|
||||||
trydan = Trydan(host, get_async_client(hass, verify_ssl=False))
|
coordinator = V2CUpdateCoordinator(hass, entry, trydan)
|
||||||
coordinator = V2CUpdateCoordinator(hass, trydan, host)
|
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
@ -41,6 +36,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: V2CConfigEntry) -> bool:
|
|||||||
return True
|
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."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -15,8 +15,7 @@ from homeassistant.components.binary_sensor import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import V2CConfigEntry
|
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
|
||||||
from .coordinator import V2CUpdateCoordinator
|
|
||||||
from .entity import V2CBaseEntity
|
from .entity import V2CBaseEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from pytrydan import Trydan, TrydanData
|
|||||||
from pytrydan.exceptions import TrydanError
|
from pytrydan.exceptions import TrydanError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -16,19 +17,24 @@ SCAN_INTERVAL = timedelta(seconds=5)
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type V2CConfigEntry = ConfigEntry[V2CUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class V2CUpdateCoordinator(DataUpdateCoordinator[TrydanData]):
|
class V2CUpdateCoordinator(DataUpdateCoordinator[TrydanData]):
|
||||||
"""DataUpdateCoordinator to gather data from any v2c."""
|
"""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."""
|
"""Initialize DataUpdateCoordinator for a v2c evse."""
|
||||||
self.evse = evse
|
self.evse = evse
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name=f"EVSE {host}",
|
config_entry=config_entry,
|
||||||
|
name=f"EVSE {config_entry.data[CONF_HOST]}",
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.components.diagnostics import async_redact_data
|
|||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import V2CConfigEntry
|
from .coordinator import V2CConfigEntry
|
||||||
|
|
||||||
TO_REDACT = {CONF_HOST, "title"}
|
TO_REDACT = {CONF_HOST, "title"}
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ from homeassistant.const import EntityCategory, UnitOfElectricCurrent
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import V2CConfigEntry
|
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
|
||||||
from .coordinator import V2CUpdateCoordinator
|
|
||||||
from .entity import V2CBaseEntity
|
from .entity import V2CBaseEntity
|
||||||
|
|
||||||
MIN_INTENSITY = 6
|
MIN_INTENSITY = 6
|
||||||
|
@ -26,8 +26,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import V2CConfigEntry
|
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
|
||||||
from .coordinator import V2CUpdateCoordinator
|
|
||||||
from .entity import V2CBaseEntity
|
from .entity import V2CBaseEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -20,8 +20,7 @@ from homeassistant.components.switch import SwitchEntity, SwitchEntityDescriptio
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import V2CConfigEntry
|
from .coordinator import V2CConfigEntry, V2CUpdateCoordinator
|
||||||
from .coordinator import V2CUpdateCoordinator
|
|
||||||
from .entity import V2CBaseEntity
|
from .entity import V2CBaseEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user