Skip to content

Commit

Permalink
fix: Fixed initialising of integration to automatically retry if acco…
Browse files Browse the repository at this point in the history
…unt information can't be retrieved
  • Loading branch information
BottlecapDave committed Jan 6, 2024
1 parent f379786 commit 320eb15
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions custom_components/octopus_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
TARGET_RATE_PLATFORMS = ["binary_sensor"]
COST_TRACKER_PLATFORMS = ["sensor"]

from .api_client import OctopusEnergyApiClient
from .api_client import ApiException, OctopusEnergyApiClient

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -151,8 +151,11 @@ async def async_setup_dependencies(hass, config):
client = OctopusEnergyApiClient(config[CONFIG_MAIN_API_KEY], electricity_price_cap, gas_price_cap)
hass.data[DOMAIN][account_id][DATA_CLIENT] = client

account_info = await client.async_get_account(config[CONFIG_ACCOUNT_ID])
if (account_info is None):
try:
account_info = await client.async_get_account(config[CONFIG_ACCOUNT_ID])
if (account_info is None):
raise ConfigEntryNotReady(f"Failed to retrieve account information")
except ApiException:
raise ConfigEntryNotReady(f"Failed to retrieve account information")

hass.data[DOMAIN][account_id][DATA_ACCOUNT] = AccountCoordinatorResult(utcnow(), 1, account_info)
Expand Down

0 comments on commit 320eb15

Please sign in to comment.