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
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any
|
||||||
|
|
||||||
from pyprosegur.auth import COUNTRY, Auth
|
from pyprosegur.auth import COUNTRY, Auth
|
||||||
from pyprosegur.installation import Installation
|
from pyprosegur.installation import Installation
|
||||||
import voluptuous as vol
|
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.const import CONF_COUNTRY, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -46,7 +46,6 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a config flow for Prosegur Alarm."""
|
"""Handle a config flow for Prosegur Alarm."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
entry: ConfigEntry
|
|
||||||
auth: Auth
|
auth: Auth
|
||||||
user_input: dict
|
user_input: dict
|
||||||
contracts: list[dict[str, str]]
|
contracts: list[dict[str, str]]
|
||||||
@ -110,10 +109,6 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle initiation of re-authentication with Prosegur."""
|
"""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()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -122,9 +117,10 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle re-authentication with Prosegur."""
|
"""Handle re-authentication with Prosegur."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
if user_input:
|
if user_input:
|
||||||
try:
|
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)
|
self.auth, self.contracts = await validate_input(self.hass, user_input)
|
||||||
|
|
||||||
except CannotConnect:
|
except CannotConnect:
|
||||||
@ -135,25 +131,20 @@ class ProsegurConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self.entry,
|
reauth_entry,
|
||||||
data={
|
data_updates={
|
||||||
**self.entry.data,
|
|
||||||
CONF_USERNAME: user_input[CONF_USERNAME],
|
CONF_USERNAME: user_input[CONF_USERNAME],
|
||||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
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(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_USERNAME, default=self.entry.data[CONF_USERNAME]
|
CONF_USERNAME, default=reauth_entry.data[CONF_USERNAME]
|
||||||
): str,
|
): str,
|
||||||
vol.Required(CONF_PASSWORD): str,
|
vol.Required(CONF_PASSWORD): str,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user