diff --git a/custom_components/ohme/__init__.py b/custom_components/ohme/__init__.py index fe82310..cbea312 100644 --- a/custom_components/ohme/__init__.py +++ b/custom_components/ohme/__init__.py @@ -1,8 +1,11 @@ +import logging from homeassistant import core from .const import * from .api_client import OhmeApiClient from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAccountInfoCoordinator, OhmeAdvancedSettingsCoordinator, OhmeChargeSchedulesCoordinator +from homeassistant.exceptions import ConfigEntryNotReady +_LOGGER = logging.getLogger(__name__) async def async_setup(hass: core.HomeAssistant, config: dict) -> bool: """Set up the Ohme EV Charger component.""" @@ -39,8 +42,25 @@ async def async_setup_entry(hass, entry): OhmeChargeSchedulesCoordinator(hass=hass) # COORDINATOR_SCHEDULES ] + # We can function without these so setup can continue + coordinators_optional = [ + OhmeStatisticsCoordinator, + OhmeAdvancedSettingsCoordinator + ] + for coordinator in coordinators: - await coordinator.async_config_entry_first_refresh() + # Catch failures if this is an 'optional' coordinator + try: + await coordinator.async_config_entry_first_refresh() + except ConfigEntryNotReady as ex: + allow_failure = False + for optional in coordinators_optional: + allow_failure = True if isinstance(coordinator, optional) else allow_failure + + if allow_failure: + _LOGGER.error(f"{coordinator.__class__.__name__} failed to setup. This coordinator is optional so the integration will still function, but please raise an issue if this persists.") + else: + raise ex hass.data[DOMAIN][DATA_COORDINATORS] = coordinators