Reconfiguration support for webhook flow helper (#151729)

This commit is contained in:
Manu
2026-02-18 15:31:48 +01:00
committed by GitHub
parent 680f7fac1c
commit 4dcfd5fb91
11 changed files with 165 additions and 3 deletions

View File

@@ -215,11 +215,19 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
self, user_input: dict[str, Any] | None = None
) -> config_entries.ConfigFlowResult:
"""Handle a user initiated set up flow to create a webhook."""
if not self._allow_multiple and self._async_current_entries():
if (
not self._allow_multiple
and self._async_current_entries()
and self.source != config_entries.SOURCE_RECONFIGURE
):
return self.async_abort(reason="single_instance_allowed")
if user_input is None:
return self.async_show_form(step_id="user")
return self.async_show_form(
step_id="reconfigure"
if self.source == config_entries.SOURCE_RECONFIGURE
else "user"
)
# Local import to be sure cloud is loaded and setup
from homeassistant.components.cloud import ( # noqa: PLC0415
@@ -234,7 +242,11 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
async_generate_url,
)
webhook_id = async_generate_id()
if self.source == config_entries.SOURCE_RECONFIGURE:
entry = self._get_reconfigure_entry()
webhook_id = entry.data["webhook_id"]
else:
webhook_id = async_generate_id()
if "cloud" in self.hass.config.components and async_active_subscription(
self.hass
@@ -250,12 +262,30 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
self._description_placeholder["webhook_url"] = webhook_url
if self.source == config_entries.SOURCE_RECONFIGURE:
if self.hass.config_entries.async_update_entry(
entry=entry,
data={"webhook_id": webhook_id, "cloudhook": cloudhook},
):
self.hass.config_entries.async_schedule_reload(entry.entry_id)
return self.async_abort(
reason="reconfigure_successful",
description_placeholders=self._description_placeholder,
)
return self.async_create_entry(
title=self._title,
data={"webhook_id": webhook_id, "cloudhook": cloudhook},
description_placeholders=self._description_placeholder,
)
async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> config_entries.ConfigFlowResult:
"""Handle a user initiated flow to re-configure a webhook."""
return await self.async_step_user(user_input)
def register_webhook_flow(
domain: str, title: str, description_placeholder: dict, allow_multiple: bool = False