Reduce config entry setup/unload boilerplate T-U (#49786)

This commit is contained in:
J. Nick Koston 2021-04-27 10:19:57 -10:00 committed by GitHub
parent 87420627a8
commit 4b74c57285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 64 additions and 198 deletions

View file

@ -1,5 +1,4 @@
"""The totalconnect component."""
import asyncio
import logging
from total_connect_client import TotalConnectClient
@ -58,24 +57,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = client
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True
async def async_unload_entry(hass, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in PLATFORMS
]
)
)
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)