Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 41c36c6

Browse files
committed
Tolerate certain coordinator setup failures
1 parent ef838ba commit 41c36c6

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

custom_components/ohme/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import logging
12
from homeassistant import core
23
from .const import *
34
from .api_client import OhmeApiClient
45
from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAccountInfoCoordinator, OhmeAdvancedSettingsCoordinator, OhmeChargeSchedulesCoordinator
6+
from homeassistant.exceptions import ConfigEntryNotReady
57

8+
_LOGGER = logging.getLogger(__name__)
69

710
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
811
"""Set up the Ohme EV Charger component."""
@@ -39,8 +42,25 @@ async def async_setup_entry(hass, entry):
3942
OhmeChargeSchedulesCoordinator(hass=hass) # COORDINATOR_SCHEDULES
4043
]
4144

45+
# We can function without these so setup can continue
46+
coordinators_optional = [
47+
OhmeStatisticsCoordinator,
48+
OhmeAdvancedSettingsCoordinator
49+
]
50+
4251
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
4464

4565
hass.data[DOMAIN][DATA_COORDINATORS] = coordinators
4666

0 commit comments

Comments
 (0)