Reduce config entry setup/unload boilerplate G-J (#49737)
This commit is contained in:
parent
157dd273da
commit
a1fdf84dba
43 changed files with 172 additions and 493 deletions
|
@ -1,5 +1,4 @@
|
|||
"""The Garmin Connect integration."""
|
||||
import asyncio
|
||||
from datetime import date, timedelta
|
||||
import logging
|
||||
|
||||
|
@ -52,27 +51,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = garmin_data
|
||||
|
||||
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: HomeAssistant, 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)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The Global Disaster Alert and Coordination System (GDACS) integration."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -97,17 +96,11 @@ async def async_setup_entry(hass, config_entry):
|
|||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, config_entry):
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload an GDACS component config entry."""
|
||||
manager = hass.data[DOMAIN][FEED].pop(config_entry.entry_id)
|
||||
manager = hass.data[DOMAIN][FEED].pop(entry.entry_id)
|
||||
await manager.async_stop()
|
||||
await asyncio.wait(
|
||||
[
|
||||
hass.config_entries.async_forward_entry_unload(config_entry, domain)
|
||||
for domain in PLATFORMS
|
||||
]
|
||||
)
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
class GdacsFeedEntityManager:
|
||||
|
@ -142,12 +135,7 @@ class GdacsFeedEntityManager:
|
|||
async def async_init(self):
|
||||
"""Schedule initial and regular updates based on configured time interval."""
|
||||
|
||||
for domain in PLATFORMS:
|
||||
self._hass.async_create_task(
|
||||
self._hass.config_entries.async_forward_entry_setup(
|
||||
self._config_entry, domain
|
||||
)
|
||||
)
|
||||
self._hass.config_entries.async_setup_platforms(self._config_entry, PLATFORMS)
|
||||
|
||||
async def update(event_time):
|
||||
"""Update."""
|
||||
|
|
|
@ -19,6 +19,8 @@ from homeassistant.util import slugify
|
|||
|
||||
from .const import DOMAIN
|
||||
|
||||
PLATFORMS = [DEVICE_TRACKER]
|
||||
|
||||
CONF_MOBILE_BEACONS = "mobile_beacons"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
|
@ -136,9 +138,7 @@ async def async_setup_entry(hass, entry):
|
|||
DOMAIN, "Geofency", entry.data[CONF_WEBHOOK_ID], handle_webhook
|
||||
)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, DEVICE_TRACKER)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -146,8 +146,7 @@ async def async_unload_entry(hass, entry):
|
|||
"""Unload a config entry."""
|
||||
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
||||
hass.data[DOMAIN]["unsub_device_tracker"].pop(entry.entry_id)()
|
||||
await hass.config_entries.async_forward_entry_unload(entry, DEVICE_TRACKER)
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async_remove_entry = config_entry_flow.webhook_async_remove_entry
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The GeoNet NZ Quakes integration."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -104,17 +103,11 @@ async def async_setup_entry(hass, config_entry):
|
|||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, config_entry):
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload an GeoNet NZ Quakes component config entry."""
|
||||
manager = hass.data[DOMAIN][FEED].pop(config_entry.entry_id)
|
||||
manager = hass.data[DOMAIN][FEED].pop(entry.entry_id)
|
||||
await manager.async_stop()
|
||||
await asyncio.wait(
|
||||
[
|
||||
hass.config_entries.async_forward_entry_unload(config_entry, domain)
|
||||
for domain in PLATFORMS
|
||||
]
|
||||
)
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
class GeonetnzQuakesFeedEntityManager:
|
||||
|
@ -150,12 +143,7 @@ class GeonetnzQuakesFeedEntityManager:
|
|||
async def async_init(self):
|
||||
"""Schedule initial and regular updates based on configured time interval."""
|
||||
|
||||
for domain in PLATFORMS:
|
||||
self._hass.async_create_task(
|
||||
self._hass.config_entries.async_forward_entry_setup(
|
||||
self._config_entry, domain
|
||||
)
|
||||
)
|
||||
self._hass.config_entries.async_setup_platforms(self._config_entry, PLATFORMS)
|
||||
|
||||
async def update(event_time):
|
||||
"""Update."""
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""The GeoNet NZ Volcano integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
|
@ -25,7 +24,7 @@ from homeassistant.helpers.event import async_track_time_interval
|
|||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .config_flow import configured_instances
|
||||
from .const import DEFAULT_RADIUS, DEFAULT_SCAN_INTERVAL, DOMAIN, FEED
|
||||
from .const import DEFAULT_RADIUS, DEFAULT_SCAN_INTERVAL, DOMAIN, FEED, PLATFORMS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -94,14 +93,11 @@ async def async_setup_entry(hass, config_entry):
|
|||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, config_entry):
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload an GeoNet NZ Volcano component config entry."""
|
||||
manager = hass.data[DOMAIN][FEED].pop(config_entry.entry_id)
|
||||
manager = hass.data[DOMAIN][FEED].pop(entry.entry_id)
|
||||
await manager.async_stop()
|
||||
await asyncio.wait(
|
||||
[hass.config_entries.async_forward_entry_unload(config_entry, "sensor")]
|
||||
)
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
class GeonetnzVolcanoFeedEntityManager:
|
||||
|
@ -133,11 +129,7 @@ class GeonetnzVolcanoFeedEntityManager:
|
|||
async def async_init(self):
|
||||
"""Schedule initial and regular updates based on configured time interval."""
|
||||
|
||||
self._hass.async_create_task(
|
||||
self._hass.config_entries.async_forward_entry_setup(
|
||||
self._config_entry, "sensor"
|
||||
)
|
||||
)
|
||||
self._hass.config_entries.async_setup_platforms(self._config_entry, PLATFORMS)
|
||||
|
||||
async def update(event_time):
|
||||
"""Update."""
|
||||
|
|
|
@ -14,3 +14,5 @@ ATTR_HAZARDS = "hazards"
|
|||
DEFAULT_ICON = "mdi:image-filter-hdr"
|
||||
DEFAULT_RADIUS = 50.0
|
||||
DEFAULT_SCAN_INTERVAL = timedelta(minutes=5)
|
||||
|
||||
PLATFORMS = ["sensor"]
|
||||
|
|
|
@ -12,10 +12,12 @@ from .const import CONF_STATION_ID, DOMAIN, SCAN_INTERVAL
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = ["air_quality"]
|
||||
|
||||
async def async_setup_entry(hass, config_entry):
|
||||
|
||||
async def async_setup_entry(hass, entry):
|
||||
"""Set up GIOS as config entry."""
|
||||
station_id = config_entry.data[CONF_STATION_ID]
|
||||
station_id = entry.data[CONF_STATION_ID]
|
||||
_LOGGER.debug("Using station_id: %s", station_id)
|
||||
|
||||
websession = async_get_clientsession(hass)
|
||||
|
@ -24,19 +26,17 @@ async def async_setup_entry(hass, config_entry):
|
|||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, "air_quality")
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, config_entry):
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload a config entry."""
|
||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, "air_quality")
|
||||
return True
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
class GiosDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
|
|
|
@ -36,6 +36,8 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = ["sensor"]
|
||||
|
||||
GLANCES_SCHEMA = vol.All(
|
||||
vol.Schema(
|
||||
{
|
||||
|
@ -79,11 +81,12 @@ async def async_setup_entry(hass, config_entry):
|
|||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, config_entry):
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload a config entry."""
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
|
||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
return True
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
return unload_ok
|
||||
|
||||
|
||||
class GlancesData:
|
||||
|
@ -127,13 +130,12 @@ class GlancesData:
|
|||
|
||||
self.add_options()
|
||||
self.set_scan_interval(self.config_entry.options[CONF_SCAN_INTERVAL])
|
||||
self.config_entry.async_on_unload(
|
||||
self.config_entry.add_update_listener(self.async_options_updated)
|
||||
)
|
||||
|
||||
self.hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS)
|
||||
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_forward_entry_setup(
|
||||
self.config_entry, "sensor"
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
def add_options(self):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The Goal Zero Yeti integration."""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from goalzero import Yeti, exceptions
|
||||
|
@ -56,24 +55,14 @@ async def async_setup_entry(hass, entry):
|
|||
DATA_KEY_COORDINATOR: coordinator,
|
||||
}
|
||||
|
||||
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: HomeAssistant, 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)
|
||||
return unload_ok
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The gogogate2 component."""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.cover import DOMAIN as COVER
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR
|
||||
|
@ -13,40 +12,28 @@ from .const import DEVICE_TYPE_GOGOGATE2
|
|||
PLATFORMS = [COVER, SENSOR]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Do setup of Gogogate2."""
|
||||
|
||||
# Update the config entry.
|
||||
config_updates = {}
|
||||
if CONF_DEVICE not in config_entry.data:
|
||||
if CONF_DEVICE not in entry.data:
|
||||
config_updates["data"] = {
|
||||
**config_entry.data,
|
||||
**entry.data,
|
||||
**{CONF_DEVICE: DEVICE_TYPE_GOGOGATE2},
|
||||
}
|
||||
|
||||
if config_updates:
|
||||
hass.config_entries.async_update_entry(config_entry, **config_updates)
|
||||
hass.config_entries.async_update_entry(entry, **config_updates)
|
||||
|
||||
data_update_coordinator = get_data_update_coordinator(hass, config_entry)
|
||||
data_update_coordinator = get_data_update_coordinator(hass, entry)
|
||||
await data_update_coordinator.async_config_entry_first_refresh()
|
||||
|
||||
for platform in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload Gogogate2 config entry."""
|
||||
unload_ok = all(
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
||||
for platform in PLATFORMS
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The google_travel_time component."""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -9,23 +8,10 @@ PLATFORMS = ["sensor"]
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Set up Google Maps Travel Time from a config entry."""
|
||||
for component in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
||||
)
|
||||
|
||||
hass.config_entries.async_setup_platforms(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
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -28,6 +28,8 @@ from .const import (
|
|||
DOMAIN,
|
||||
)
|
||||
|
||||
PLATFORMS = [DEVICE_TRACKER]
|
||||
|
||||
TRACKER_UPDATE = f"{DOMAIN}_tracker_update"
|
||||
|
||||
|
||||
|
@ -98,9 +100,8 @@ async def async_setup_entry(hass, entry):
|
|||
DOMAIN, "GPSLogger", entry.data[CONF_WEBHOOK_ID], handle_webhook
|
||||
)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, DEVICE_TRACKER)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
@ -108,8 +109,7 @@ async def async_unload_entry(hass, entry):
|
|||
"""Unload a config entry."""
|
||||
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
||||
hass.data[DOMAIN]["unsub_device_tracker"].pop(entry.entry_id)()
|
||||
await hass.config_entries.async_forward_entry_unload(entry, DEVICE_TRACKER)
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async_remove_entry = config_entry_flow.webhook_async_remove_entry
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The Gree Climate integration."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -21,26 +20,17 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict):
|
||||
"""Set up the Gree Climate component."""
|
||||
hass.data[DOMAIN] = {}
|
||||
return True
|
||||
PLATFORMS = [CLIMATE_DOMAIN, SWITCH_DOMAIN]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Set up Gree Climate from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
gree_discovery = DiscoveryService(hass)
|
||||
hass.data[DATA_DISCOVERY_SERVICE] = gree_discovery
|
||||
|
||||
hass.data[DOMAIN].setdefault(DISPATCHERS, [])
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, CLIMATE_DOMAIN)
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, SWITCH_DOMAIN)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
async def _async_scan_update(_=None):
|
||||
await gree_discovery.discovery.scan()
|
||||
|
@ -67,12 +57,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
if hass.data.get(DATA_DISCOVERY_SERVICE) is not None:
|
||||
hass.data.pop(DATA_DISCOVERY_SERVICE)
|
||||
|
||||
results = asyncio.gather(
|
||||
hass.config_entries.async_forward_entry_unload(entry, CLIMATE_DOMAIN),
|
||||
hass.config_entries.async_forward_entry_unload(entry, SWITCH_DOMAIN),
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
unload_ok = all(await results)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(COORDINATORS, None)
|
||||
hass.data[DOMAIN].pop(DISPATCHERS, None)
|
||||
|
|
|
@ -105,24 +105,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
].async_add_listener(async_process_paired_sensor_uids)
|
||||
|
||||
# Set up all of the Guardian entity platforms:
|
||||
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: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""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][DATA_CLIENT].pop(entry.entry_id)
|
||||
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The habitica integration."""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from habitipy.aio import HabitipyAsync
|
||||
|
@ -100,7 +99,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up habitica from a config entry."""
|
||||
|
||||
class HAHabitipyAsync(HabitipyAsync):
|
||||
|
@ -131,7 +130,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
)
|
||||
|
||||
data = hass.data.setdefault(DOMAIN, {})
|
||||
config = config_entry.data
|
||||
config = entry.data
|
||||
websession = async_get_clientsession(hass)
|
||||
url = config[CONF_URL]
|
||||
username = config[CONF_API_USER]
|
||||
|
@ -143,15 +142,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
if name is None:
|
||||
name = user["profile"]["name"]
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry,
|
||||
data={**config_entry.data, CONF_NAME: name},
|
||||
entry,
|
||||
data={**entry.data, CONF_NAME: name},
|
||||
)
|
||||
data[config_entry.entry_id] = api
|
||||
data[entry.entry_id] = api
|
||||
|
||||
for platform in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
if not hass.services.has_service(DOMAIN, SERVICE_API_CALL):
|
||||
hass.services.async_register(
|
||||
|
@ -163,14 +159,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
|
||||
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, 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)
|
||||
|
||||
|
|
|
@ -58,10 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
CANCEL_STOP: cancel_stop,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
@ -115,14 +112,7 @@ async def _update_listener(hass: HomeAssistant, entry: ConfigEntry):
|
|||
|
||||
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, platform)
|
||||
for platform in PLATFORMS
|
||||
]
|
||||
)
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
# Shutdown a harmony remote for removal
|
||||
entry_data = hass.data[DOMAIN][entry.entry_id]
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Hass.io."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import os
|
||||
|
@ -518,31 +517,21 @@ async def async_setup(hass: HomeAssistant, config: Config) -> bool: # noqa: C90
|
|||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
dev_reg = await async_get_registry(hass)
|
||||
coordinator = HassioDataUpdateCoordinator(hass, config_entry, dev_reg)
|
||||
coordinator = HassioDataUpdateCoordinator(hass, entry, dev_reg)
|
||||
hass.data[ADDONS_COORDINATOR] = coordinator
|
||||
await coordinator.async_refresh()
|
||||
|
||||
for platform in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = all(
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
||||
for platform in PLATFORMS
|
||||
]
|
||||
)
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
# Pop add-on data
|
||||
hass.data.pop(ADDONS_COORDINATOR, None)
|
||||
|
|
|
@ -28,6 +28,8 @@ from .const import (
|
|||
SIGNAL_HEOS_UPDATED,
|
||||
)
|
||||
|
||||
PLATFORMS = [MEDIA_PLAYER_DOMAIN]
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Schema({vol.Required(CONF_HOST): cv.string})}, extra=vol.ALLOW_EXTRA
|
||||
)
|
||||
|
@ -119,9 +121,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
|
||||
services.register(hass, controller)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, MEDIA_PLAYER_DOMAIN)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
@ -133,9 +134,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
|
||||
services.remove(hass)
|
||||
|
||||
return await hass.config_entries.async_forward_entry_unload(
|
||||
entry, MEDIA_PLAYER_DOMAIN
|
||||
)
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
class ControllerManager:
|
||||
|
|
|
@ -15,6 +15,8 @@ from .const import DOMAIN
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = [CLIMATE_DOMAIN]
|
||||
|
||||
|
||||
def coerce_ip(value):
|
||||
"""Validate that provided value is a valid IP address."""
|
||||
|
@ -70,13 +72,10 @@ async def async_setup(hass, config):
|
|||
|
||||
async def async_setup_entry(hass, entry):
|
||||
"""Set up a config entry for Hisense AEH-W4A1."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, CLIMATE_DOMAIN)
|
||||
)
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_forward_entry_unload(entry, CLIMATE_DOMAIN)
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Support for the Hive devices and services."""
|
||||
import asyncio
|
||||
from functools import wraps
|
||||
import logging
|
||||
|
||||
|
@ -92,15 +91,7 @@ async def async_setup_entry(hass, entry):
|
|||
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload a config entry."""
|
||||
|
||||
unload_ok = all(
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.config_entries.async_forward_entry_unload(entry, component)
|
||||
for component in PLATFORMS
|
||||
]
|
||||
)
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = ["switch"]
|
||||
|
||||
DATA_DEVICE_REGISTER = "hlk_sw16_device_register"
|
||||
DATA_DEVICE_LISTENER = "hlk_sw16_device_listener"
|
||||
|
||||
|
@ -111,9 +113,7 @@ async def async_setup_entry(hass, entry):
|
|||
hass.data[DOMAIN][entry.entry_id][DATA_DEVICE_REGISTER] = client
|
||||
|
||||
# Load entities
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, "switch")
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
_LOGGER.info("Connected to HLK-SW16 device: %s", address)
|
||||
|
||||
|
@ -126,8 +126,7 @@ async def async_unload_entry(hass, entry):
|
|||
"""Unload a config entry."""
|
||||
client = hass.data[DOMAIN][entry.entry_id].pop(DATA_DEVICE_REGISTER)
|
||||
client.stop()
|
||||
unload_ok = await hass.config_entries.async_forward_entry_unload(entry, "switch")
|
||||
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
if hass.data[DOMAIN][entry.entry_id]:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Support for BSH Home Connect appliances."""
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -71,24 +70,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
await update_all_devices(hass, entry)
|
||||
|
||||
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: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""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)
|
||||
|
||||
|
|
|
@ -157,13 +157,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
"""Unload the Legrand Home+ Control config entry."""
|
||||
unload_ok = all(
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.config_entries.async_forward_entry_unload(config_entry, component)
|
||||
for component in PLATFORMS
|
||||
]
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||
config_entry, PLATFORMS
|
||||
)
|
||||
if unload_ok:
|
||||
# Unsubscribe the config_entry signal dispatcher connections
|
||||
|
|
|
@ -269,17 +269,9 @@ class HKDevice:
|
|||
|
||||
await self.pairing.unsubscribe(self.watchable_characteristics)
|
||||
|
||||
unloads = []
|
||||
for platform in self.platforms:
|
||||
unloads.append(
|
||||
self.hass.config_entries.async_forward_entry_unload(
|
||||
self.config_entry, platform
|
||||
return await self.hass.config_entries.async_unload_platforms(
|
||||
self.config_entry, self.platforms
|
||||
)
|
||||
)
|
||||
|
||||
results = await asyncio.gather(*unloads)
|
||||
|
||||
return False not in results
|
||||
|
||||
async def async_refresh_entity_map(self, config_num):
|
||||
"""Handle setup of a HomeKit accessory."""
|
||||
|
|
|
@ -101,12 +101,8 @@ class HomematicipHAP:
|
|||
"Connected to HomematicIP with HAP %s", self.config_entry.unique_id
|
||||
)
|
||||
|
||||
for platform in PLATFORMS:
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_forward_entry_setup(
|
||||
self.config_entry, platform
|
||||
)
|
||||
)
|
||||
self.hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
@callback
|
||||
|
@ -214,9 +210,8 @@ class HomematicipHAP:
|
|||
self._retry_task.cancel()
|
||||
await self.home.disable_events()
|
||||
_LOGGER.info("Closed connection to HomematicIP cloud server")
|
||||
for platform in PLATFORMS:
|
||||
await self.hass.config_entries.async_forward_entry_unload(
|
||||
self.config_entry, platform
|
||||
await self.hass.config_entries.async_unload_platforms(
|
||||
self.config_entry, PLATFORMS
|
||||
)
|
||||
self.hmip_device_by_entity_id = {}
|
||||
return True
|
||||
|
|
|
@ -420,10 +420,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
)
|
||||
|
||||
# Forward config entry setup to platforms
|
||||
for domain in CONFIG_ENTRY_PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, domain)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(config_entry, CONFIG_ENTRY_PLATFORMS)
|
||||
|
||||
# Notify doesn't support config entry setup yet, load with discovery for now
|
||||
await discovery.async_load_platform(
|
||||
hass,
|
||||
|
@ -462,8 +460,9 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||
"""Unload config entry."""
|
||||
|
||||
# Forward config entry unload to platforms
|
||||
for domain in CONFIG_ENTRY_PLATFORMS:
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, domain)
|
||||
await hass.config_entries.async_unload_platforms(
|
||||
config_entry, CONFIG_ENTRY_PLATFORMS
|
||||
)
|
||||
|
||||
# Forget about the router and invoke its cleanup
|
||||
router = hass.data[DOMAIN].routers.pop(config_entry.data[CONF_URL])
|
||||
|
|
|
@ -29,6 +29,9 @@ from .sensor_base import SensorManager
|
|||
|
||||
# How long should we sleep if the hub is busy
|
||||
HUB_BUSY_SLEEP = 0.5
|
||||
|
||||
PLATFORMS = ["light", "binary_sensor", "sensor"]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -101,17 +104,7 @@ class HueBridge:
|
|||
self.api = bridge
|
||||
self.sensor_manager = SensorManager(self)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(self.config_entry, "light")
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(
|
||||
self.config_entry, "binary_sensor"
|
||||
)
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(self.config_entry, "sensor")
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS)
|
||||
|
||||
self.parallel_updates_semaphore = asyncio.Semaphore(
|
||||
3 if self.api.config.modelid == "BSB001" else 10
|
||||
|
@ -179,21 +172,10 @@ class HueBridge:
|
|||
|
||||
# If setup was successful, we set api variable, forwarded entry and
|
||||
# register service
|
||||
results = await asyncio.gather(
|
||||
self.hass.config_entries.async_forward_entry_unload(
|
||||
self.config_entry, "light"
|
||||
),
|
||||
self.hass.config_entries.async_forward_entry_unload(
|
||||
self.config_entry, "binary_sensor"
|
||||
),
|
||||
self.hass.config_entries.async_forward_entry_unload(
|
||||
self.config_entry, "sensor"
|
||||
),
|
||||
return await self.hass.config_entries.async_unload_platforms(
|
||||
self.config_entry, PLATFORMS
|
||||
)
|
||||
|
||||
# None and True are OK
|
||||
return False not in results
|
||||
|
||||
async def hue_activate_scene(self, data, skip_reload=False, hide_warnings=False):
|
||||
"""Service to call directly into bridge to set scenes."""
|
||||
group_name = data[ATTR_GROUP_NAME]
|
||||
|
|
|
@ -23,20 +23,17 @@ from .const import (
|
|||
SOURCE_TYPES,
|
||||
)
|
||||
|
||||
PLATFORMS = ["sensor"]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict):
|
||||
"""Set up the Huisbaasje component."""
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Set up Huisbaasje from a config entry."""
|
||||
# Create the Huisbaasje client
|
||||
huisbaasje = Huisbaasje(
|
||||
username=config_entry.data[CONF_USERNAME],
|
||||
password=config_entry.data[CONF_PASSWORD],
|
||||
username=entry.data[CONF_USERNAME],
|
||||
password=entry.data[CONF_PASSWORD],
|
||||
source_types=SOURCE_TYPES,
|
||||
request_timeout=FETCH_TIMEOUT,
|
||||
)
|
||||
|
@ -63,28 +60,22 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
|||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
# Load the client in the data of home assistant
|
||||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = {
|
||||
DATA_COORDINATOR: coordinator
|
||||
}
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {DATA_COORDINATOR: coordinator}
|
||||
|
||||
# Offload the loading of entities to the platform
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, "sensor")
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Unload a config entry."""
|
||||
# Forward the unloading of the entry to the platform
|
||||
unload_ok = await hass.config_entries.async_forward_entry_unload(
|
||||
config_entry, "sensor"
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
# If successful, unload the Huisbaasje client
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The Hunter Douglas PowerView integration."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -127,10 +126,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
DEVICE_INFO: device_info,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
@ -172,15 +168,7 @@ def _async_map_data_by_id(data):
|
|||
|
||||
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, 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)
|
||||
|
||||
return unload_ok
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The HVV integration."""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as DOMAIN_BINARY_SENSOR
|
||||
from homeassistant.components.sensor import DOMAIN as DOMAIN_SENSOR
|
||||
|
@ -27,22 +26,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = hub
|
||||
|
||||
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: HomeAssistant, 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
|
||||
]
|
||||
)
|
||||
)
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -297,13 +297,8 @@ async def _async_entry_updated(hass: HomeAssistant, config_entry: ConfigEntry) -
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = all(
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
||||
for platform in PLATFORMS
|
||||
]
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||
config_entry, PLATFORMS
|
||||
)
|
||||
if unload_ok and config_entry.entry_id in hass.data[DOMAIN]:
|
||||
config_data = hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||
|
||||
from .const import DATA_COORDINATOR, DOMAIN, IALARM_TO_HASS
|
||||
|
||||
PLATFORM = "alarm_control_panel"
|
||||
PLATFORMS = ["alarm_control_panel"]
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -39,20 +39,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
DATA_COORDINATOR: coordinator,
|
||||
}
|
||||
|
||||
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: HomeAssistant, entry: ConfigEntry):
|
||||
"""Unload iAlarm config."""
|
||||
unload_ok = await hass.config_entries.async_forward_entry_unload(entry, PLATFORM)
|
||||
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,14 @@ _LOGGER = logging.getLogger(__name__)
|
|||
ATTR_CONFIG = "config"
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
PLATFORMS = [
|
||||
BINARY_SENSOR_DOMAIN,
|
||||
CLIMATE_DOMAIN,
|
||||
LIGHT_DOMAIN,
|
||||
SENSOR_DOMAIN,
|
||||
SWITCH_DOMAIN,
|
||||
]
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
|
@ -160,24 +168,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
forward_unload = hass.config_entries.async_forward_entry_unload
|
||||
|
||||
tasks = []
|
||||
|
||||
if hass.data[DOMAIN][BINARY_SENSOR_DOMAIN]:
|
||||
tasks += [forward_unload(entry, BINARY_SENSOR_DOMAIN)]
|
||||
if hass.data[DOMAIN][CLIMATE_DOMAIN]:
|
||||
tasks += [forward_unload(entry, CLIMATE_DOMAIN)]
|
||||
if hass.data[DOMAIN][LIGHT_DOMAIN]:
|
||||
tasks += [forward_unload(entry, LIGHT_DOMAIN)]
|
||||
if hass.data[DOMAIN][SENSOR_DOMAIN]:
|
||||
tasks += [forward_unload(entry, SENSOR_DOMAIN)]
|
||||
if hass.data[DOMAIN][SWITCH_DOMAIN]:
|
||||
tasks += [forward_unload(entry, SWITCH_DOMAIN)]
|
||||
platforms_to_unload = [
|
||||
platform for platform in PLATFORMS if platform in hass.data[DOMAIN]
|
||||
]
|
||||
|
||||
hass.data[DOMAIN].clear()
|
||||
|
||||
return all(await asyncio.gather(*tasks))
|
||||
return await hass.config_entries.async_unload_platforms(entry, platforms_to_unload)
|
||||
|
||||
|
||||
def refresh_system(func):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The iCloud component."""
|
||||
import asyncio
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -135,10 +134,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
hass.data[DOMAIN][entry.unique_id] = account
|
||||
|
||||
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)
|
||||
|
||||
def play_sound(service: ServiceDataType) -> None:
|
||||
"""Play sound on the device."""
|
||||
|
@ -224,15 +220,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
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, platform)
|
||||
for platform in PLATFORMS
|
||||
]
|
||||
)
|
||||
)
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.data[CONF_USERNAME])
|
||||
|
||||
return unload_ok
|
||||
|
|
|
@ -4,16 +4,15 @@ from .const import DOMAIN # noqa: F401
|
|||
|
||||
DEFAULT_NAME = "ipma"
|
||||
|
||||
PLATFORMS = ["weather"]
|
||||
|
||||
async def async_setup_entry(hass, config_entry):
|
||||
|
||||
async def async_setup_entry(hass, entry):
|
||||
"""Set up IPMA station as config entry."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, "weather")
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, config_entry):
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload a config entry."""
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, "weather")
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""The Internet Printing Protocol (IPP) integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
@ -58,28 +57,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
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: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""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)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
|
|
|
@ -85,28 +85,16 @@ async def async_setup_entry(hass, entry):
|
|||
|
||||
await asyncio.gather(*init_data_update_tasks)
|
||||
|
||||
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):
|
||||
"""Unload an OpenUV 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][DATA_COORDINATOR].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = ["sensor"]
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
|
@ -63,9 +64,7 @@ async def async_unload_entry(hass, config_entry):
|
|||
if hass.data[DOMAIN].event_unsub:
|
||||
hass.data[DOMAIN].event_unsub()
|
||||
hass.data.pop(DOMAIN)
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
|
||||
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||
|
||||
|
||||
class IslamicPrayerClient:
|
||||
|
@ -180,11 +179,7 @@ class IslamicPrayerClient:
|
|||
await self.async_update()
|
||||
self.config_entry.add_update_listener(self.async_options_updated)
|
||||
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_forward_entry_setup(
|
||||
self.config_entry, "sensor"
|
||||
)
|
||||
)
|
||||
self.hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support the ISY-994 controllers."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from functools import partial
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
@ -177,10 +176,7 @@ async def async_setup_entry(
|
|||
await _async_get_or_create_isy_device_in_registry(hass, entry, isy)
|
||||
|
||||
# Load platforms for the devices in the ISY controller that we support.
|
||||
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)
|
||||
|
||||
def _start_auto_update() -> None:
|
||||
"""Start isy auto update."""
|
||||
|
@ -245,14 +241,7 @@ async def async_unload_entry(
|
|||
hass: HomeAssistant, entry: config_entries.ConfigEntry
|
||||
) -> bool:
|
||||
"""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)
|
||||
|
||||
hass_isy_data = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ from homeassistant.helpers.typing import ConfigType
|
|||
from .const import DATA_CONFIG, IZONE
|
||||
from .discovery import async_start_discovery_service, async_stop_discovery_service
|
||||
|
||||
PLATFORMS = ["climate"]
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
IZONE: vol.Schema(
|
||||
|
@ -45,15 +47,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType):
|
|||
async def async_setup_entry(hass, entry):
|
||||
"""Set up from a config entry."""
|
||||
await async_start_discovery_service(hass)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, "climate")
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload the config entry and stop discovery process."""
|
||||
await async_stop_discovery_service(hass)
|
||||
await hass.config_entries.async_forward_entry_unload(entry, "climate")
|
||||
return True
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The JuiceNet integration."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -91,25 +90,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
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: HomeAssistant, 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)
|
||||
|
||||
return unload_ok
|
||||
|
|
|
@ -82,15 +82,7 @@ async def test_hap_setup_works():
|
|||
assert await hap.async_setup()
|
||||
|
||||
assert hap.home is home
|
||||
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 8
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == (
|
||||
entry,
|
||||
"alarm_control_panel",
|
||||
)
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == (
|
||||
entry,
|
||||
"binary_sensor",
|
||||
)
|
||||
assert len(hass.config_entries.async_setup_platforms.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_hap_setup_connection_error():
|
||||
|
|
|
@ -26,8 +26,6 @@ async def test_form(hass):
|
|||
"huisbaasje.Huisbaasje.get_user_id",
|
||||
return_value="test-id",
|
||||
) as mock_get_user_id, patch(
|
||||
"homeassistant.components.huisbaasje.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.huisbaasje.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
|
@ -49,7 +47,6 @@ async def test_form(hass):
|
|||
}
|
||||
assert len(mock_authenticate.mock_calls) == 1
|
||||
assert len(mock_get_user_id.mock_calls) == 1
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
@ -139,8 +136,6 @@ async def test_form_entry_exists(hass):
|
|||
with patch("huisbaasje.Huisbaasje.authenticate", return_value=None), patch(
|
||||
"huisbaasje.Huisbaasje.get_user_id",
|
||||
return_value="test-id",
|
||||
), patch(
|
||||
"homeassistant.components.huisbaasje.async_setup", return_value=True
|
||||
), patch(
|
||||
"homeassistant.components.huisbaasje.async_setup_entry",
|
||||
return_value=True,
|
||||
|
|
Loading…
Add table
Reference in a new issue