mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +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
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import ssdp, zeroconf
|
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.const import CONF_HOST, CONF_TOKEN
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.json import save_json
|
from homeassistant.helpers.json import save_json
|
||||||
@ -34,8 +34,6 @@ USER_SCHEMA: Final = vol.Schema(
|
|||||||
class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Nanoleaf config flow."""
|
"""Nanoleaf config flow."""
|
||||||
|
|
||||||
reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
nanoleaf: Nanoleaf
|
nanoleaf: Nanoleaf
|
||||||
|
|
||||||
# For discovery integration import
|
# For discovery integration import
|
||||||
@ -81,14 +79,10 @@ class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle Nanoleaf reauth flow if token is invalid."""
|
"""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(
|
self.nanoleaf = Nanoleaf(
|
||||||
async_get_clientsession(self.hass), entry_data[CONF_HOST]
|
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()
|
return await self.async_step_link()
|
||||||
|
|
||||||
async def async_step_zeroconf(
|
async def async_step_zeroconf(
|
||||||
@ -177,16 +171,11 @@ class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unknown error authorizing Nanoleaf")
|
_LOGGER.exception("Unknown error authorizing Nanoleaf")
|
||||||
return self.async_show_form(step_id="link", errors={"base": "unknown"})
|
return self.async_show_form(step_id="link", errors={"base": "unknown"})
|
||||||
|
|
||||||
if self.reauth_entry is not None:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self.reauth_entry,
|
self._get_reauth_entry(),
|
||||||
data={
|
data_updates={CONF_TOKEN: self.nanoleaf.auth_token},
|
||||||
**self.reauth_entry.data,
|
|
||||||
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()
|
return await self.async_setup_finish()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user