Skip to content

Commit

Permalink
Handle invalid creds during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgospodinow authored Dec 8, 2024
1 parent 54c1ae0 commit b88396e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions custom_components/eldom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
import logging

from eldom.client import Client as EldomClient
import requests

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client

from .const import API_BASE_URL, DOMAIN
from .coordinator import EldomCoordinator
from .models import EldomData

_LOGGER = logging.getLogger(__name__)

PLATFORMS: list[Platform] = [
Platform.SENSOR,
Platform.SWITCH,
Platform.WATER_HEATER,
]

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Eldom from a config entry."""
Expand All @@ -37,10 +37,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

try:
await api_client.login(email, password)
_LOGGER.info("Successfully logged in to Eldom API")
except requests.exceptions.HTTPError as e:
_LOGGER.error("Failed to login to Eldom API: %s", e)
return False
await api_client.get_devices() # NOTE: This is needed since currently the login API does not throw an error if the credentials are invalid: https://github.com/qbaware/homeassistant-eldom/issues/27
_LOGGER.info("Successfully authenticated with Eldom API")
except Exception as e:
_LOGGER.error("Unexpected exception while authenticating with Eldom API: %s", e)
raise ConfigEntryNotReady(
f"Unexpected exception while authenticating with Eldom API: {e}"
) from e

coordinator = EldomCoordinator(hass, api_client)

Expand Down

0 comments on commit b88396e

Please sign in to comment.