Implement reauth_confirm in icloud (#77530)

This commit is contained in:
epenet 2022-08-31 06:07:32 +02:00 committed by GitHub
parent e192c99d2f
commit 3df2ec1ed6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 33 deletions

View file

@ -1,6 +1,10 @@
"""Config flow to configure the iCloud integration."""
from __future__ import annotations
from collections.abc import Mapping
import logging
import os
from typing import Any
from pyicloud import PyiCloudService
from pyicloud.exceptions import (
@ -13,6 +17,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.storage import Store
from .const import (
@ -173,22 +178,23 @@ class IcloudFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return await self._validate_and_create_entry(user_input, "user")
async def async_step_reauth(self, user_input=None):
"""Update password for a config entry that can't authenticate."""
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Initialise re-authentication."""
# Store existing entry data so it can be used later and set unique ID
# so existing config entry can be updated
if not self._existing_entry:
await self.async_set_unique_id(user_input.pop("unique_id"))
self._existing_entry = user_input.copy()
self._description_placeholders = {"username": user_input[CONF_USERNAME]}
user_input = None
await self.async_set_unique_id(self.context["unique_id"])
self._existing_entry = {**entry_data}
self._description_placeholders = {"username": entry_data[CONF_USERNAME]}
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Update password for a config entry that can't authenticate."""
if user_input is None:
return self._show_setup_form(step_id=config_entries.SOURCE_REAUTH)
return self._show_setup_form(step_id="reauth_confirm")
return await self._validate_and_create_entry(
user_input, config_entries.SOURCE_REAUTH
)
return await self._validate_and_create_entry(user_input, "reauth_confirm")
async def async_step_trusted_device(self, user_input=None, errors=None):
"""We need a trusted device."""