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