Explicitly pass in the config_entry in ohme coordinator (#138055)
explicitly pass in the config_entry in coordinatorpull/130406/merge
parent
d92e2194d0
commit
390af71c49
|
@ -1,10 +1,7 @@
|
|||
"""Set up ohme integration."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ohme import ApiException, AuthException, OhmeApiClient
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
|
@ -15,23 +12,14 @@ from .const import DOMAIN, PLATFORMS
|
|||
from .coordinator import (
|
||||
OhmeAdvancedSettingsCoordinator,
|
||||
OhmeChargeSessionCoordinator,
|
||||
OhmeConfigEntry,
|
||||
OhmeDeviceInfoCoordinator,
|
||||
OhmeRuntimeData,
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
type OhmeConfigEntry = ConfigEntry[OhmeRuntimeData]
|
||||
|
||||
|
||||
@dataclass()
|
||||
class OhmeRuntimeData:
|
||||
"""Dataclass to hold ohme coordinators."""
|
||||
|
||||
charge_session_coordinator: OhmeChargeSessionCoordinator
|
||||
advanced_settings_coordinator: OhmeAdvancedSettingsCoordinator
|
||||
device_info_coordinator: OhmeDeviceInfoCoordinator
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Ohme integration."""
|
||||
|
@ -62,9 +50,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: OhmeConfigEntry) -> bool
|
|||
) from e
|
||||
|
||||
coordinators = (
|
||||
OhmeChargeSessionCoordinator(hass, client),
|
||||
OhmeAdvancedSettingsCoordinator(hass, client),
|
||||
OhmeDeviceInfoCoordinator(hass, client),
|
||||
OhmeChargeSessionCoordinator(hass, entry, client),
|
||||
OhmeAdvancedSettingsCoordinator(hass, entry, client),
|
||||
OhmeDeviceInfoCoordinator(hass, entry, client),
|
||||
)
|
||||
|
||||
for coordinator in coordinators:
|
||||
|
|
|
@ -12,8 +12,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OhmeConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OhmeConfigEntry
|
||||
from .entity import OhmeEntity, OhmeEntityDescription
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
"""Ohme coordinators."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from ohme import ApiException, OhmeApiClient
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
|
@ -14,18 +18,34 @@ from .const import DOMAIN
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass()
|
||||
class OhmeRuntimeData:
|
||||
"""Dataclass to hold ohme coordinators."""
|
||||
|
||||
charge_session_coordinator: OhmeChargeSessionCoordinator
|
||||
advanced_settings_coordinator: OhmeAdvancedSettingsCoordinator
|
||||
device_info_coordinator: OhmeDeviceInfoCoordinator
|
||||
|
||||
|
||||
type OhmeConfigEntry = ConfigEntry[OhmeRuntimeData]
|
||||
|
||||
|
||||
class OhmeBaseCoordinator(DataUpdateCoordinator[None]):
|
||||
"""Base for all Ohme coordinators."""
|
||||
|
||||
config_entry: OhmeConfigEntry
|
||||
client: OhmeApiClient
|
||||
_default_update_interval: timedelta | None = timedelta(minutes=1)
|
||||
coordinator_name: str = ""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, client: OhmeApiClient) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: OhmeConfigEntry, client: OhmeApiClient
|
||||
) -> None:
|
||||
"""Initialise coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name="",
|
||||
update_interval=self._default_update_interval,
|
||||
)
|
||||
|
|
|
@ -11,8 +11,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OhmeConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OhmeConfigEntry
|
||||
from .entity import OhmeEntity, OhmeEntityDescription
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
|
|
@ -13,8 +13,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OhmeConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OhmeConfigEntry
|
||||
from .entity import OhmeEntity, OhmeEntityDescription
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OhmeConfigEntry
|
||||
from .coordinator import OhmeConfigEntry
|
||||
from .entity import OhmeEntity, OhmeEntityDescription
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
|
|
@ -11,8 +11,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OhmeConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OhmeConfigEntry
|
||||
from .entity import OhmeEntity, OhmeEntityDescription
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
|
|
@ -11,8 +11,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OhmeConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OhmeConfigEntry
|
||||
from .entity import OhmeEntity, OhmeEntityDescription
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
|
Loading…
Reference in New Issue