|
| 1 | +import logging |
1 | 2 | from homeassistant import core |
2 | 3 | from .const import * |
3 | 4 | from .api_client import OhmeApiClient |
4 | 5 | from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAccountInfoCoordinator, OhmeAdvancedSettingsCoordinator, OhmeChargeSchedulesCoordinator |
| 6 | +from homeassistant.exceptions import ConfigEntryNotReady |
5 | 7 |
|
| 8 | +_LOGGER = logging.getLogger(__name__) |
6 | 9 |
|
7 | 10 | async def async_setup(hass: core.HomeAssistant, config: dict) -> bool: |
8 | 11 | """Set up the Ohme EV Charger component.""" |
@@ -39,8 +42,25 @@ async def async_setup_entry(hass, entry): |
39 | 42 | OhmeChargeSchedulesCoordinator(hass=hass) # COORDINATOR_SCHEDULES |
40 | 43 | ] |
41 | 44 |
|
| 45 | + # We can function without these so setup can continue |
| 46 | + coordinators_optional = [ |
| 47 | + OhmeStatisticsCoordinator, |
| 48 | + OhmeAdvancedSettingsCoordinator |
| 49 | + ] |
| 50 | + |
42 | 51 | for coordinator in coordinators: |
43 | | - await coordinator.async_config_entry_first_refresh() |
| 52 | + # Catch failures if this is an 'optional' coordinator |
| 53 | + try: |
| 54 | + await coordinator.async_config_entry_first_refresh() |
| 55 | + except ConfigEntryNotReady as ex: |
| 56 | + allow_failure = False |
| 57 | + for optional in coordinators_optional: |
| 58 | + allow_failure = True if isinstance(coordinator, optional) else allow_failure |
| 59 | + |
| 60 | + if allow_failure: |
| 61 | + _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.") |
| 62 | + else: |
| 63 | + raise ex |
44 | 64 |
|
45 | 65 | hass.data[DOMAIN][DATA_COORDINATORS] = coordinators |
46 | 66 |
|
|
0 commit comments