From ef593986d292076f2c8040a83b82876c5f12c502 Mon Sep 17 00:00:00 2001 From: "Teemu R." Date: Fri, 6 Sep 2024 15:42:26 +0200 Subject: [PATCH] Use async_forward_entry_setups (#32) --- .../upnp_availability/__init__.py | 21 +++---------------- custom_components/upnp_availability/const.py | 3 +++ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/custom_components/upnp_availability/__init__.py b/custom_components/upnp_availability/__init__.py index e36c362..6f8948d 100644 --- a/custom_components/upnp_availability/__init__.py +++ b/custom_components/upnp_availability/__init__.py @@ -1,17 +1,14 @@ """The UPnP Availability integration.""" -import asyncio import logging import voluptuous as vol from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from .const import DOMAIN +from .const import DOMAIN, PLATFORMS CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA) -PLATFORMS = ["binary_sensor"] - _LOGGER = logging.getLogger(__name__) @@ -30,25 +27,13 @@ async def async_setup(hass: HomeAssistant, config: dict): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up UPnP Availability from a config entry.""" - for component in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, component) - ) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, component) - for component in PLATFORMS - ] - ) - ) - if unload_ok: - hass.data[DOMAIN].clear() + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) return unload_ok diff --git a/custom_components/upnp_availability/const.py b/custom_components/upnp_availability/const.py index 7556d4a..b001e3f 100644 --- a/custom_components/upnp_availability/const.py +++ b/custom_components/upnp_availability/const.py @@ -1,3 +1,6 @@ """Constants for the UPnP Availability integration.""" +from homeassistant.const import Platform + DOMAIN = "upnp_availability" +PLATFORMS = [Platform.BINARY_SENSOR]