Use reauth helpers in justnimbus (#128649)
This commit is contained in:
parent
080842e44c
commit
3cf9e2d9f6
1 changed files with 5 additions and 15 deletions
|
@ -9,7 +9,7 @@ from typing import Any
|
|||
import justnimbus
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_CLIENT_ID
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
|
@ -29,7 +29,6 @@ class JustNimbusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"""Handle a config flow for JustNimbus."""
|
||||
|
||||
VERSION = 1
|
||||
reauth_entry: ConfigEntry | None = None
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
|
@ -44,7 +43,7 @@ class JustNimbusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
unique_id = f"{user_input[CONF_CLIENT_ID]}{user_input[CONF_ZIP_CODE]}"
|
||||
await self.async_set_unique_id(unique_id=unique_id)
|
||||
if not self.reauth_entry:
|
||||
if self.source != SOURCE_REAUTH:
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
client = justnimbus.JustNimbusClient(
|
||||
|
@ -60,18 +59,12 @@ class JustNimbusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
if not self.reauth_entry:
|
||||
if self.source != SOURCE_REAUTH:
|
||||
return self.async_create_entry(title="JustNimbus", data=user_input)
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.reauth_entry, data=user_input, unique_id=unique_id
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reauth_entry(), data=user_input, unique_id=unique_id
|
||||
)
|
||||
|
||||
# Reload the config entry otherwise devices will remain unavailable
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
@ -80,7 +73,4 @@ class JustNimbusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Perform reauth upon an API authentication error."""
|
||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
return await self.async_step_user()
|
||||
|
|
Loading…
Add table
Reference in a new issue