Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of reauthentication flow #124

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions custom_components/myskoda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.util.ssl import get_default_context
from myskoda import MySkoda
from myskoda.myskoda import TRACE_CONFIG
from myskoda.auth.authorization import AuthorizationFailedError

from .const import COORDINATORS, DOMAIN
from .coordinator import MySkodaDataUpdateCoordinator
Expand Down Expand Up @@ -41,6 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:

try:
await myskoda.connect(config.data["email"], config.data["password"])
except AuthorizationFailedError:
raise ConfigEntryAuthFailed("Log in failed for MySkoda")
except Exception:
_LOGGER.exception("Login with MySkoda failed.")
return False
Expand Down
17 changes: 17 additions & 0 deletions custom_components/myskoda/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
from collections.abc import Mapping
from typing import Any

import voluptuous as vol
Expand Down Expand Up @@ -118,6 +119,22 @@ def async_get_options_flow(
"""Create the options flow."""
return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW)

async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle reauthentication."""
return await self.async_step_reauth_confirm()

async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Dialog that informs the user reauthentication is needed."""
if user_input is None:
return self.async_show_form(
step_id="reauth_confirm", data_schema=STEP_USER_DATA_SCHEMA
)
return await self.async_step_user()


class CannotConnect(HomeAssistantError):
"""Error to indicate we cannot connect."""
Expand Down