Skip to content

Commit

Permalink
Tolerate certain coordinator setup failures
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jan 4, 2024
1 parent ef838ba commit 41c36c6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion custom_components/ohme/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 41c36c6

Please sign in to comment.