mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use new reauth helpers in prosegur (#128718)
This commit is contained in:
parent
908f649ea7
commit
088cfed794
@ -2,13 +2,13 @@
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
from typing import Any
|
||||
|
||||
from pyprosegur.auth import COUNTRY, Auth
|
||||
from pyprosegur.installation import Installation
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_COUNTRY, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@ -46,7 +46,6 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Prosegur Alarm."""
|
||||
|
||||
VERSION = 1
|
||||
entry: ConfigEntry
|
||||
auth: Auth
|
||||
user_input: dict
|
||||
contracts: list[dict[str, str]]
|
||||
@ -110,10 +109,6 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle initiation of re-authentication with Prosegur."""
|
||||
self.entry = cast(
|
||||
ConfigEntry,
|
||||
self.hass.config_entries.async_get_entry(self.context["entry_id"]),
|
||||
)
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
@ -122,9 +117,10 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle re-authentication with Prosegur."""
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
if user_input:
|
||||
try:
|
||||
user_input[CONF_COUNTRY] = self.entry.data[CONF_COUNTRY]
|
||||
user_input[CONF_COUNTRY] = reauth_entry.data[CONF_COUNTRY]
|
||||
self.auth, self.contracts = await validate_input(self.hass, user_input)
|
||||
|
||||
except CannotConnect:
|
||||
@ -135,25 +131,20 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.entry,
|
||||
data={
|
||||
**self.entry.data,
|
||||
return self.async_update_reload_and_abort(
|
||||
reauth_entry,
|
||||
data_updates={
|
||||
CONF_USERNAME: user_input[CONF_USERNAME],
|
||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
||||
},
|
||||
)
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(self.entry.entry_id)
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required(
|
||||
CONF_USERNAME, default=self.entry.data[CONF_USERNAME]
|
||||
CONF_USERNAME, default=reauth_entry.data[CONF_USERNAME]
|
||||
): str,
|
||||
vol.Required(CONF_PASSWORD): str,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user