mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Use _get_reauth/reconfigure_entry in enphase_envoy (#127281)
* Use _get_reauth/reconfigure_entry in enphase_envoy * Adjust
This commit is contained in:
parent
81d7d2a70a
commit
583ce7dc46
@ -13,6 +13,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_REAUTH,
|
||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
@ -54,6 +55,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
_reauth_entry: ConfigEntry
|
||||||
_reconnect_entry: ConfigEntry
|
_reconnect_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@ -61,7 +63,6 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self.ip_address: str | None = None
|
self.ip_address: str | None = None
|
||||||
self.username = None
|
self.username = None
|
||||||
self.protovers: str | None = None
|
self.protovers: str | None = None
|
||||||
self._reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
@ -78,7 +79,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
schema[vol.Required(CONF_HOST, default=self.ip_address)] = vol.In(
|
schema[vol.Required(CONF_HOST, default=self.ip_address)] = vol.In(
|
||||||
[self.ip_address]
|
[self.ip_address]
|
||||||
)
|
)
|
||||||
elif not self._reauth_entry:
|
elif self.source != SOURCE_REAUTH:
|
||||||
schema[vol.Required(CONF_HOST)] = str
|
schema[vol.Required(CONF_HOST)] = str
|
||||||
|
|
||||||
default_username = ""
|
default_username = ""
|
||||||
@ -151,10 +152,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle configuration by re-auth."""
|
"""Handle configuration by re-auth."""
|
||||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
self._reauth_entry = self._get_reauth_entry()
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
assert self._reauth_entry is not None
|
|
||||||
if unique_id := self._reauth_entry.unique_id:
|
if unique_id := self._reauth_entry.unique_id:
|
||||||
await self.async_set_unique_id(unique_id, raise_on_progress=False)
|
await self.async_set_unique_id(unique_id, raise_on_progress=False)
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
@ -170,7 +168,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
description_placeholders: dict[str, str] = {}
|
description_placeholders: dict[str, str] = {}
|
||||||
|
|
||||||
if self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
host = self._reauth_entry.data[CONF_HOST]
|
host = self._reauth_entry.data[CONF_HOST]
|
||||||
else:
|
else:
|
||||||
host = (user_input or {}).get(CONF_HOST) or self.ip_address or ""
|
host = (user_input or {}).get(CONF_HOST) or self.ip_address or ""
|
||||||
@ -195,7 +193,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
else:
|
else:
|
||||||
name = self._async_envoy_name()
|
name = self._async_envoy_name()
|
||||||
|
|
||||||
if self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._reauth_entry,
|
self._reauth_entry,
|
||||||
data=self._reauth_entry.data | user_input,
|
data=self._reauth_entry.data | user_input,
|
||||||
@ -238,9 +236,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Add reconfigure step to allow to manually reconfigure a config entry."""
|
"""Add reconfigure step to allow to manually reconfigure a config entry."""
|
||||||
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
self._reconnect_entry = self._get_reconfigure_entry()
|
||||||
assert entry
|
|
||||||
self._reconnect_entry = entry
|
|
||||||
return await self.async_step_reconfigure_confirm()
|
return await self.async_step_reconfigure_confirm()
|
||||||
|
|
||||||
async def async_step_reconfigure_confirm(
|
async def async_step_reconfigure_confirm(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user