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
This commit is contained in:
Jan-Philipp Benecke 2024-03-06 09:07:09 +01:00 committed by GitHub
parent 64dcc4606f
commit 995d93dd33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 10 deletions

View File

@ -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"])