mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use reauth_confirm in nanoleaf (#128698)
This commit is contained in:
parent
7e68368d0a
commit
ff6261ccc8
@ -11,7 +11,7 @@ from aionanoleaf import InvalidToken, Nanoleaf, Unauthorized, Unavailable
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import ssdp, zeroconf
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.json import save_json
|
||||
@ -34,8 +34,6 @@ USER_SCHEMA: Final = vol.Schema(
|
||||
class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Nanoleaf config flow."""
|
||||
|
||||
reauth_entry: ConfigEntry | None = None
|
||||
|
||||
nanoleaf: Nanoleaf
|
||||
|
||||
# For discovery integration import
|
||||
@ -81,14 +79,10 @@ class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle Nanoleaf reauth flow if token is invalid."""
|
||||
self.reauth_entry = cast(
|
||||
ConfigEntry,
|
||||
self.hass.config_entries.async_get_entry(self.context["entry_id"]),
|
||||
)
|
||||
self.nanoleaf = Nanoleaf(
|
||||
async_get_clientsession(self.hass), entry_data[CONF_HOST]
|
||||
)
|
||||
self.context["title_placeholders"] = {"name": self.reauth_entry.title}
|
||||
self.context["title_placeholders"] = {"name": self._get_reauth_entry().title}
|
||||
return await self.async_step_link()
|
||||
|
||||
async def async_step_zeroconf(
|
||||
@ -177,16 +171,11 @@ class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
_LOGGER.exception("Unknown error authorizing Nanoleaf")
|
||||
return self.async_show_form(step_id="link", errors={"base": "unknown"})
|
||||
|
||||
if self.reauth_entry is not None:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.reauth_entry,
|
||||
data={
|
||||
**self.reauth_entry.data,
|
||||
CONF_TOKEN: self.nanoleaf.auth_token,
|
||||
},
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reauth_entry(),
|
||||
data_updates={CONF_TOKEN: self.nanoleaf.auth_token},
|
||||
)
|
||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
return await self.async_setup_finish()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user