Use new reauth helpers in whirlpool (#128825)

This commit is contained in:
epenet 2024-10-20 09:55:16 +02:00 committed by GitHub
parent 0ede15dcbf
commit 87c9c0c3b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,7 @@ from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector from whirlpool.backendselector import BackendSelector
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
@ -71,14 +71,11 @@ class WhirlpoolConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Whirlpool Sixth Sense.""" """Handle a config flow for Whirlpool Sixth Sense."""
VERSION = 1 VERSION = 1
entry: ConfigEntry | None
async def async_step_reauth( async def async_step_reauth(
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle re-authentication with Whirlpool Sixth Sense.""" """Handle re-authentication with Whirlpool Sixth Sense."""
self.entry = 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(
@ -88,10 +85,10 @@ class WhirlpoolConfigFlow(ConfigFlow, domain=DOMAIN):
errors: dict[str, str] = {} errors: dict[str, str] = {}
if user_input: if user_input:
assert self.entry is not None reauth_entry = self._get_reauth_entry()
password = user_input[CONF_PASSWORD] password = user_input[CONF_PASSWORD]
brand = user_input[CONF_BRAND] brand = user_input[CONF_BRAND]
data = {**self.entry.data, CONF_PASSWORD: password, CONF_BRAND: brand} data = {**reauth_entry.data, CONF_PASSWORD: password, CONF_BRAND: brand}
try: try:
await validate_input(self.hass, data) await validate_input(self.hass, data)
@ -100,9 +97,7 @@ class WhirlpoolConfigFlow(ConfigFlow, domain=DOMAIN):
except (CannotConnect, TimeoutError): except (CannotConnect, TimeoutError):
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
else: else:
self.hass.config_entries.async_update_entry(self.entry, data=data) return self.async_update_reload_and_abort(reauth_entry, data=data)
await 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",