Use _get_reauth/reconfigure_entry in enphase_envoy (#127281)

* Use _get_reauth/reconfigure_entry in enphase_envoy

* Adjust
This commit is contained in:
epenet 2024-10-02 14:22:16 +02:00 committed by GitHub
parent 81d7d2a70a
commit 583ce7dc46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,7 @@ import voluptuous as vol
from homeassistant.components import zeroconf
from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
@ -54,6 +55,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
_reauth_entry: ConfigEntry
_reconnect_entry: ConfigEntry
def __init__(self) -> None:
@ -61,7 +63,6 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
self.ip_address: str | None = None
self.username = None
self.protovers: str | None = None
self._reauth_entry: ConfigEntry | None = None
@staticmethod
@callback
@ -78,7 +79,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
schema[vol.Required(CONF_HOST, default=self.ip_address)] = vol.In(
[self.ip_address]
)
elif not self._reauth_entry:
elif self.source != SOURCE_REAUTH:
schema[vol.Required(CONF_HOST)] = str
default_username = ""
@ -151,10 +152,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle configuration by re-auth."""
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
assert self._reauth_entry is not None
self._reauth_entry = self._get_reauth_entry()
if unique_id := self._reauth_entry.unique_id:
await self.async_set_unique_id(unique_id, raise_on_progress=False)
return await self.async_step_user()
@ -170,7 +168,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
errors: dict[str, str] = {}
description_placeholders: dict[str, str] = {}
if self._reauth_entry:
if self.source == SOURCE_REAUTH:
host = self._reauth_entry.data[CONF_HOST]
else:
host = (user_input or {}).get(CONF_HOST) or self.ip_address or ""
@ -195,7 +193,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
else:
name = self._async_envoy_name()
if self._reauth_entry:
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
self._reauth_entry,
data=self._reauth_entry.data | user_input,
@ -238,9 +236,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Add reconfigure step to allow to manually reconfigure a config entry."""
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
assert entry
self._reconnect_entry = entry
self._reconnect_entry = self._get_reconfigure_entry()
return await self.async_step_reconfigure_confirm()
async def async_step_reconfigure_confirm(