Skip to content

Commit

Permalink
Merge pull request #34 from dala318/recofigure
Browse files Browse the repository at this point in the history
Add reconfiguration flow
  • Loading branch information
dala318 authored Oct 22, 2024
2 parents d9756e6 + f542c71 commit 1fbb169
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

_LOGGER = logging.getLogger(__name__)

PLACEHOLDERS = {
CONF_API_KEY: "API key",
}


class PoolLabConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""PoolLab config flow."""
Expand Down Expand Up @@ -67,15 +71,49 @@ async def async_step_user(
vol.Required(CONF_API_KEY, default=None): cv.string,
}
)
return self.async_show_form(
step_id="user",
data_schema=user_schema,
description_placeholders=PLACEHOLDERS,
errors=errors,
)

placeholders = {
CONF_API_KEY: "API key",
}
async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle user reconfiguration step."""
errors = {}

config_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
if config_entry is None:
return self.async_abort(reason="reconfigure_failed")

if user_input is not None:
try:
await self.is_valid(user_input)
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unhandled exception in user step")
errors["base"] = "unknown"
if not errors:
return self.async_update_reload_and_abort(
config_entry,
data=user_input,
)

default_api_key = config_entry.data.get(CONF_API_KEY) or None
user_schema = vol.Schema(
{
vol.Required(CONF_API_KEY, default=default_api_key): cv.string,
}
)
return self.async_show_form(
step_id="user",
step_id="reconfigure",
data_schema=user_schema,
description_placeholders=placeholders,
description_placeholders=PLACEHOLDERS,
errors=errors,
)

Expand Down

0 comments on commit 1fbb169

Please sign in to comment.