From 990987ac9277ade270c3f5d15b7252fa17a0bbbc Mon Sep 17 00:00:00 2001
From: epenet <6771947+epenet@users.noreply.github.com>
Date: Sat, 19 Oct 2024 19:21:43 +0200
Subject: [PATCH] Use new reauth helpers in verisure (#128778)

---
 .../components/verisure/config_flow.py        | 34 ++++++-------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/homeassistant/components/verisure/config_flow.py b/homeassistant/components/verisure/config_flow.py
index ccf74cd6791..42ce7f9e9fe 100644
--- a/homeassistant/components/verisure/config_flow.py
+++ b/homeassistant/components/verisure/config_flow.py
@@ -3,7 +3,7 @@
 from __future__ import annotations
 
 from collections.abc import Mapping
-from typing import Any, cast
+from typing import Any
 
 from verisure import (
     Error as VerisureError,
@@ -38,7 +38,6 @@ class VerisureConfigFlowHandler(ConfigFlow, domain=DOMAIN):
     VERSION = 2
 
     email: str
-    entry: ConfigEntry
     password: str
     verisure: Verisure
 
@@ -179,10 +178,6 @@ class VerisureConfigFlowHandler(ConfigFlow, domain=DOMAIN):
         self, entry_data: Mapping[str, Any]
     ) -> ConfigFlowResult:
         """Handle initiation of re-authentication with Verisure."""
-        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(
@@ -230,25 +225,21 @@ class VerisureConfigFlowHandler(ConfigFlow, domain=DOMAIN):
                 LOGGER.debug("Unexpected response from Verisure, %s", ex)
                 errors["base"] = "unknown"
             else:
-                data = self.entry.data.copy()
-                self.hass.config_entries.async_update_entry(
-                    self.entry,
-                    data={
-                        **data,
+                return self.async_update_reload_and_abort(
+                    self._get_reauth_entry(),
+                    data_updates={
                         CONF_EMAIL: user_input[CONF_EMAIL],
                         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_EMAIL, default=self.entry.data[CONF_EMAIL]): str,
+                    vol.Required(
+                        CONF_EMAIL, default=self._get_reauth_entry().data[CONF_EMAIL]
+                    ): str,
                     vol.Required(CONF_PASSWORD): str,
                 }
             ),
@@ -274,18 +265,13 @@ class VerisureConfigFlowHandler(ConfigFlow, domain=DOMAIN):
                 LOGGER.debug("Unexpected response from Verisure, %s", ex)
                 errors["base"] = "unknown"
             else:
-                self.hass.config_entries.async_update_entry(
-                    self.entry,
-                    data={
-                        **self.entry.data,
+                return self.async_update_reload_and_abort(
+                    self._get_reauth_entry(),
+                    data_updates={
                         CONF_EMAIL: self.email,
                         CONF_PASSWORD: self.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_mfa",
-- 
GitLab