Raise ConfigEntryError on invalid login in ourgroceries (#185107)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
G Johansson
2026-10-11 21:47:47 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 9a3961ddc3
commit d748522707
3 changed files with 26 additions and 3 deletions
@@ -6,8 +6,9 @@ from ourgroceries.exceptions import InvalidLoginException
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
from .const import DOMAIN
from .coordinator import OurGroceriesConfigEntry, OurGroceriesDataUpdateCoordinator
PLATFORMS: list[Platform] = [Platform.TODO]
@@ -23,8 +24,11 @@ async def async_setup_entry(
await og.login()
except (TimeoutError, ClientError) as error:
raise ConfigEntryNotReady from error
except InvalidLoginException:
return False
except InvalidLoginException as error:
raise ConfigEntryError(
translation_domain=DOMAIN,
translation_key="invalid_login",
) from error
coordinator = OurGroceriesDataUpdateCoordinator(hass, entry, og)
await coordinator.async_config_entry_first_refresh()
@@ -13,5 +13,10 @@
}
}
}
},
"exceptions": {
"invalid_login": {
"message": "Login to OurGroceries failed because the username or password is incorrect"
}
}
}
@@ -50,3 +50,17 @@ async def test_init_failure(
) -> None:
"""Test an initialization error on integration load."""
assert ourgroceries_config_entry.state is status
@pytest.mark.parametrize("exception", [InvalidLoginException])
@pytest.mark.usefixtures("login_with_error", "setup_integration")
async def test_init_invalid_login(
hass: HomeAssistant,
ourgroceries_config_entry: MockConfigEntry,
) -> None:
"""Test an invalid login fails setup with the correct reason."""
assert ourgroceries_config_entry.state is ConfigEntryState.SETUP_ERROR
assert (
ourgroceries_config_entry.reason
== "Login to OurGroceries failed because the username or password is incorrect"
)