From 995d93dd33a944d421e84e438ef373a5b6c68851 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Wed, 6 Mar 2024 09:07:09 +0100 Subject: [PATCH] Remove deprecated `hass.components` usage in config entry flow (#111880) * Remove deprecated `hass.components` usage in config entry flow * Do local import * Also use local import for webhook --- homeassistant/helpers/config_entry_flow.py | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index b645fdb06bd..23638dc3549 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -220,21 +220,33 @@ class WebhookFlowHandler(config_entries.ConfigFlow): if user_input is None: return self.async_show_form(step_id="user") - webhook_id = self.hass.components.webhook.async_generate_id() + # Local import to be sure cloud is loaded and setup + # pylint: disable-next=import-outside-toplevel + from homeassistant.components.cloud import ( + async_active_subscription, + async_create_cloudhook, + async_is_connected, + ) - if ( - "cloud" in self.hass.config.components - and self.hass.components.cloud.async_active_subscription() + # Local import to be sure webhook is loaded and setup + # pylint: disable-next=import-outside-toplevel + from homeassistant.components.webhook import ( + async_generate_id, + async_generate_url, + ) + + webhook_id = async_generate_id() + + if "cloud" in self.hass.config.components and async_active_subscription( + self.hass ): - if not self.hass.components.cloud.async_is_connected(): + if not async_is_connected(self.hass): return self.async_abort(reason="cloud_not_connected") - webhook_url = await self.hass.components.cloud.async_create_cloudhook( - webhook_id - ) + webhook_url = await async_create_cloudhook(self.hass, webhook_id) cloudhook = True else: - webhook_url = self.hass.components.webhook.async_generate_url(webhook_id) + webhook_url = async_generate_url(self.hass, webhook_id) cloudhook = False self._description_placeholder["webhook_url"] = webhook_url @@ -267,4 +279,8 @@ async def webhook_async_remove_entry( if not entry.data.get("cloudhook") or "cloud" not in hass.config.components: return - await hass.components.cloud.async_delete_cloudhook(entry.data["webhook_id"]) + # Local import to be sure cloud is loaded and setup + # pylint: disable-next=import-outside-toplevel + from homeassistant.components.cloud import async_delete_cloudhook + + await async_delete_cloudhook(hass, entry.data["webhook_id"])