Reduce boilerplate to setup config entry platforms A-C (#49681)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
922eec0909
commit
51be2f860a
34 changed files with 119 additions and 409 deletions
|
@ -1,5 +1,4 @@
|
||||||
"""Support for the Abode Security System."""
|
"""Support for the Abode Security System."""
|
||||||
from asyncio import gather
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
@ -131,10 +130,7 @@ async def async_setup_entry(hass, config_entry):
|
||||||
|
|
||||||
hass.data[DOMAIN] = AbodeSystem(abode, polling)
|
hass.data[DOMAIN] = AbodeSystem(abode, polling)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
await setup_hass_events(hass)
|
await setup_hass_events(hass)
|
||||||
await hass.async_add_executor_job(setup_hass_services, hass)
|
await hass.async_add_executor_job(setup_hass_services, hass)
|
||||||
|
@ -149,22 +145,17 @@ async def async_unload_entry(hass, config_entry):
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_CAPTURE_IMAGE)
|
hass.services.async_remove(DOMAIN, SERVICE_CAPTURE_IMAGE)
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_TRIGGER_AUTOMATION)
|
hass.services.async_remove(DOMAIN, SERVICE_TRIGGER_AUTOMATION)
|
||||||
|
|
||||||
tasks = []
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
|
config_entry, PLATFORMS
|
||||||
for platform in PLATFORMS:
|
|
||||||
tasks.append(
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await gather(*tasks)
|
|
||||||
|
|
||||||
await hass.async_add_executor_job(hass.data[DOMAIN].abode.events.stop)
|
await hass.async_add_executor_job(hass.data[DOMAIN].abode.events.stop)
|
||||||
await hass.async_add_executor_job(hass.data[DOMAIN].abode.logout)
|
await hass.async_add_executor_job(hass.data[DOMAIN].abode.logout)
|
||||||
|
|
||||||
hass.data[DOMAIN].logout_listener()
|
hass.data[DOMAIN].logout_listener()
|
||||||
hass.data.pop(DOMAIN)
|
hass.data.pop(DOMAIN)
|
||||||
|
|
||||||
return True
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
def setup_hass_services(hass):
|
def setup_hass_services(hass):
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The AccuWeather component."""
|
"""The AccuWeather component."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -46,23 +45,15 @@ async def async_setup_entry(hass, config_entry) -> bool:
|
||||||
UNDO_UPDATE_LISTENER: undo_listener,
|
UNDO_UPDATE_LISTENER: undo_listener,
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
|
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Rollease Acmeda Automate integration."""
|
"""The Rollease Acmeda Automate integration."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant import config_entries, core
|
from homeassistant import config_entries, core
|
||||||
|
|
||||||
|
@ -23,10 +22,7 @@ async def async_setup_entry(
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = hub
|
hass.data[DOMAIN][config_entry.entry_id] = hub
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -37,14 +33,10 @@ async def async_unload_entry(
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
hub = hass.data[DOMAIN][config_entry.entry_id]
|
hub = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not await hub.async_reset():
|
if not await hub.async_reset():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Advantage Air climate integration."""
|
"""Advantage Air climate integration."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -58,24 +57,14 @@ async def async_setup_entry(hass, entry):
|
||||||
"async_change": async_change,
|
"async_change": async_change,
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload Advantage Air Config."""
|
"""Unload Advantage Air Config."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The AEMET OpenData component."""
|
"""The AEMET OpenData component."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aemet_opendata.interface import AEMET
|
from aemet_opendata.interface import AEMET
|
||||||
|
@ -32,24 +31,17 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||||
ENTRY_WEATHER_COORDINATOR: weather_coordinator,
|
ENTRY_WEATHER_COORDINATOR: weather_coordinator,
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for Agent."""
|
"""Support for Agent."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from agent import AgentError
|
from agent import AgentError
|
||||||
from agent.a import Agent
|
from agent.a import Agent
|
||||||
|
@ -47,24 +46,14 @@ async def async_setup_entry(hass, config_entry):
|
||||||
sw_version=agent_client.version,
|
sw_version=agent_client.version,
|
||||||
)
|
)
|
||||||
|
|
||||||
for forward in FORWARDS:
|
hass.config_entries.async_setup_platforms(config_entry, FORWARDS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, forward)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(config_entry, FORWARDS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, forward)
|
|
||||||
for forward in FORWARDS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.data[AGENT_DOMAIN][config_entry.entry_id][CONNECTION].close()
|
await hass.data[AGENT_DOMAIN][config_entry.entry_id][CONNECTION].close()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Airly integration."""
|
"""The Airly integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
@ -69,24 +68,17 @@ async def async_setup_entry(hass, config_entry):
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The AirNow integration."""
|
"""The AirNow integration."""
|
||||||
import asyncio
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -60,24 +59,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The airvisual component."""
|
"""The airvisual component."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
|
@ -258,10 +257,7 @@ async def async_setup_entry(hass, config_entry):
|
||||||
hass, config_entry.data[CONF_API_KEY]
|
hass, config_entry.data[CONF_API_KEY]
|
||||||
)
|
)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -310,14 +306,10 @@ async def async_migrate_entry(hass, config_entry):
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload an AirVisual config entry."""
|
"""Unload an AirVisual config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR].pop(config_entry.entry_id)
|
hass.data[DOMAIN][DATA_COORDINATOR].pop(config_entry.entry_id)
|
||||||
remove_listener = hass.data[DOMAIN][DATA_LISTENER].pop(config_entry.entry_id)
|
remove_listener = hass.data[DOMAIN][DATA_LISTENER].pop(config_entry.entry_id)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for AlarmDecoder devices."""
|
"""Support for AlarmDecoder devices."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -125,10 +124,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
await open_connection()
|
await open_connection()
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,14 +133,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a AlarmDecoder entry."""
|
"""Unload a AlarmDecoder entry."""
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_RESTART] = False
|
hass.data[DOMAIN][entry.entry_id][DATA_RESTART] = False
|
||||||
|
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not unload_ok:
|
if not unload_ok:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for Ambient Weather Station Service."""
|
"""Support for Ambient Weather Station Service."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from aioambient import Client
|
from aioambient import Client
|
||||||
from aioambient.errors import WebsocketError
|
from aioambient.errors import WebsocketError
|
||||||
|
@ -369,14 +368,7 @@ async def async_unload_entry(hass, config_entry):
|
||||||
ambient = hass.data[DOMAIN][DATA_CLIENT].pop(config_entry.entry_id)
|
ambient = hass.data[DOMAIN][DATA_CLIENT].pop(config_entry.entry_id)
|
||||||
hass.async_create_task(ambient.ws_disconnect())
|
hass.async_create_task(ambient.ws_disconnect())
|
||||||
|
|
||||||
tasks = [
|
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
|
|
||||||
await asyncio.gather(*tasks)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_migrate_entry(hass, config_entry):
|
async def async_migrate_entry(hass, config_entry):
|
||||||
|
@ -475,11 +467,8 @@ class AmbientStation:
|
||||||
# attempt forward setup of the config entry (because it will have
|
# attempt forward setup of the config entry (because it will have
|
||||||
# already been done):
|
# already been done):
|
||||||
if not self._entry_setup_complete:
|
if not self._entry_setup_complete:
|
||||||
for platform in PLATFORMS:
|
self._hass.config_entries.async_setup_platforms(
|
||||||
self._hass.async_create_task(
|
self._config_entry, PLATFORMS
|
||||||
self._hass.config_entries.async_forward_entry_setup(
|
|
||||||
self._config_entry, platform
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self._entry_setup_complete = True
|
self._entry_setup_complete = True
|
||||||
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
|
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
|
||||||
|
|
|
@ -71,14 +71,8 @@ async def async_setup_entry(hass, entry):
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload an Apple TV config entry."""
|
"""Unload an Apple TV config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
manager = hass.data[DOMAIN].pop(entry.unique_id)
|
manager = hass.data[DOMAIN].pop(entry.unique_id)
|
||||||
await manager.disconnect()
|
await manager.disconnect()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for ASUSWRT devices."""
|
"""Support for ASUSWRT devices."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -125,10 +124,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
router.async_on_close(entry.add_update_listener(update_listener))
|
router.async_on_close(entry.add_update_listener(update_listener))
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_close_connection(event):
|
async def async_close_connection(event):
|
||||||
"""Close AsusWrt connection on HA Stop."""
|
"""Close AsusWrt connection on HA Stop."""
|
||||||
|
@ -148,14 +144,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][entry.entry_id]["stop_listener"]()
|
hass.data[DOMAIN][entry.entry_id]["stop_listener"]()
|
||||||
router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT]
|
router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT]
|
||||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.components.climate import DOMAIN as CLIMATE
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR
|
from homeassistant.components.sensor import DOMAIN as SENSOR
|
||||||
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER
|
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, asyncio
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
|
@ -52,24 +52,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
if entry.unique_id is None:
|
if entry.unique_id is None:
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=atag.id)
|
hass.config_entries.async_update_entry(entry, unique_id=atag.id)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload Atag config entry."""
|
"""Unload Atag config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
|
@ -52,14 +52,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_AUGUST].async_stop()
|
hass.data[DOMAIN][entry.entry_id][DATA_AUGUST].async_stop()
|
||||||
|
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
@ -85,10 +78,7 @@ async def async_setup_august(hass, config_entry, august_gateway):
|
||||||
}
|
}
|
||||||
await data[DATA_AUGUST].async_setup()
|
await data[DATA_AUGUST].async_setup()
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""The aurora component."""
|
"""The aurora component."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -69,24 +68,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
AURORA_API: api,
|
AURORA_API: api,
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -28,23 +28,17 @@ async def async_setup_entry(hass, config_entry) -> bool:
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry) -> bool:
|
async def async_unload_entry(hass, config_entry) -> bool:
|
||||||
"""Unload Awair configuration."""
|
"""Unload Awair configuration."""
|
||||||
tasks = []
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
for platform in PLATFORMS:
|
config_entry, PLATFORMS
|
||||||
tasks.append(
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
unload_ok = all(await gather(*tasks))
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -264,20 +264,9 @@ class AxisNetworkDevice:
|
||||||
"""Reset this device to default state."""
|
"""Reset this device to default state."""
|
||||||
self.disconnect_from_stream()
|
self.disconnect_from_stream()
|
||||||
|
|
||||||
unload_ok = all(
|
return await self.hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
self.config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
self.hass.config_entries.async_forward_entry_unload(
|
|
||||||
self.config_entry, platform
|
|
||||||
)
|
)
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if not unload_ok:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def get_device(hass, host, port, username, password):
|
async def get_device(hass, host, port, username, password):
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The BleBox devices integration."""
|
"""The BleBox devices integration."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from blebox_uniapi.error import Error
|
from blebox_uniapi.error import Error
|
||||||
|
@ -43,24 +42,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
domain_entry = domain.setdefault(entry.entry_id, {})
|
domain_entry = domain.setdefault(entry.entry_id, {})
|
||||||
product = domain_entry.setdefault(PRODUCT, product)
|
product = domain_entry.setdefault(PRODUCT, product)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for Blink Home Camera System."""
|
"""Support for Blink Home Camera System."""
|
||||||
import asyncio
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -86,10 +85,7 @@ async def async_setup_entry(hass, entry):
|
||||||
if not hass.data[DOMAIN][entry.entry_id].available:
|
if not hass.data[DOMAIN][entry.entry_id].available:
|
||||||
raise ConfigEntryNotReady
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
def blink_refresh(event_time=None):
|
def blink_refresh(event_time=None):
|
||||||
"""Call blink to refresh info."""
|
"""Call blink to refresh info."""
|
||||||
|
@ -130,14 +126,7 @@ def _async_import_options_from_data_if_missing(hass, entry):
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload Blink entry."""
|
"""Unload Blink entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not unload_ok:
|
if not unload_ok:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Reads vehicle status from BMW connected drive portal."""
|
"""Reads vehicle status from BMW connected drive portal."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from bimmer_connected.account import ConnectedDriveAccount
|
from bimmer_connected.account import ConnectedDriveAccount
|
||||||
|
@ -138,10 +137,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
await _async_update_all()
|
await _async_update_all()
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(
|
||||||
if platform != NOTIFY_DOMAIN:
|
entry, [platform for platform in PLATFORMS if platform != NOTIFY_DOMAIN]
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# set up notify platform, no entry support for notify platform yet,
|
# set up notify platform, no entry support for notify platform yet,
|
||||||
|
@ -161,14 +158,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
entry, [platform for platform in PLATFORMS if platform != NOTIFY_DOMAIN]
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
if platform != NOTIFY_DOMAIN
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only remove services if it is the last account and not read only
|
# Only remove services if it is the last account and not read only
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Bond integration."""
|
"""The Bond integration."""
|
||||||
import asyncio
|
|
||||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||||
|
|
||||||
from aiohttp import ClientError, ClientTimeout
|
from aiohttp import ClientError, ClientTimeout
|
||||||
|
@ -75,24 +74,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
_async_remove_old_device_identifiers(config_entry_id, device_registry, hub)
|
_async_remove_old_device_identifiers(config_entry_id, device_registry, hub)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
data = hass.data[DOMAIN][entry.entry_id]
|
data = hass.data[DOMAIN][entry.entry_id]
|
||||||
data[_STOP_CANCEL]()
|
data[_STOP_CANCEL]()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Bravia TV component."""
|
"""The Bravia TV component."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from bravia_tv import BraviaRC
|
from bravia_tv import BraviaRC
|
||||||
|
|
||||||
|
@ -23,23 +22,15 @@ async def async_setup_entry(hass, config_entry):
|
||||||
UNDO_UPDATE_LISTENER: undo_listener,
|
UNDO_UPDATE_LISTENER: undo_listener,
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
|
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for Broadlink devices."""
|
"""Support for Broadlink devices."""
|
||||||
import asyncio
|
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
@ -112,12 +111,9 @@ class BroadlinkDevice:
|
||||||
self.reset_jobs.append(config.add_update_listener(self.async_update))
|
self.reset_jobs.append(config.add_update_listener(self.async_update))
|
||||||
|
|
||||||
# Forward entry setup to related domains.
|
# Forward entry setup to related domains.
|
||||||
tasks = (
|
self.hass.config_entries.async_setup_platforms(
|
||||||
self.hass.config_entries.async_forward_entry_setup(config, domain)
|
config, get_domains(self.api.type)
|
||||||
for domain in get_domains(self.api.type)
|
|
||||||
)
|
)
|
||||||
for entry_setup in tasks:
|
|
||||||
self.hass.async_create_task(entry_setup)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -129,12 +125,9 @@ class BroadlinkDevice:
|
||||||
while self.reset_jobs:
|
while self.reset_jobs:
|
||||||
self.reset_jobs.pop()()
|
self.reset_jobs.pop()()
|
||||||
|
|
||||||
tasks = (
|
return await self.hass.config_entries.async_unload_platforms(
|
||||||
self.hass.config_entries.async_forward_entry_unload(self.config, domain)
|
self.config, get_domains(self.api.type)
|
||||||
for domain in get_domains(self.api.type)
|
|
||||||
)
|
)
|
||||||
results = await asyncio.gather(*tasks)
|
|
||||||
return all(results)
|
|
||||||
|
|
||||||
async def async_auth(self):
|
async def async_auth(self):
|
||||||
"""Authenticate to the device."""
|
"""Authenticate to the device."""
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Brother component."""
|
"""The Brother component."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -37,24 +36,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
hass.data[DOMAIN][DATA_CONFIG_ENTRY][entry.entry_id] = coordinator
|
hass.data[DOMAIN][DATA_CONFIG_ENTRY][entry.entry_id] = coordinator
|
||||||
hass.data[DOMAIN][SNMP] = snmp_engine
|
hass.data[DOMAIN][SNMP] = snmp_engine
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][DATA_CONFIG_ENTRY].pop(entry.entry_id)
|
hass.data[DOMAIN][DATA_CONFIG_ENTRY].pop(entry.entry_id)
|
||||||
if not hass.data[DOMAIN][DATA_CONFIG_ENTRY]:
|
if not hass.data[DOMAIN][DATA_CONFIG_ENTRY]:
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Support for Canary devices."""
|
"""Support for Canary devices."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -104,24 +103,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
DATA_UNDO_UPDATE_LISTENER: undo_listener,
|
DATA_UNDO_UPDATE_LISTENER: undo_listener,
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_UNDO_UPDATE_LISTENER]()
|
hass.data[DOMAIN][entry.entry_id][DATA_UNDO_UPDATE_LISTENER]()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""The ClimaCell integration."""
|
"""The ClimaCell integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
@ -162,23 +161,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await asyncio.gather(
|
config_entry, PLATFORMS
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Control4 integration."""
|
"""The Control4 integration."""
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -107,10 +106,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
entry_data[CONF_CONFIG_LISTENER] = entry.add_update_listener(update_listener)
|
entry_data[CONF_CONFIG_LISTENER] = entry.add_update_listener(update_listener)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -123,14 +119,8 @@ async def update_listener(hass, config_entry):
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
hass.data[DOMAIN][entry.entry_id][CONF_CONFIG_LISTENER]()
|
hass.data[DOMAIN][entry.entry_id][CONF_CONFIG_LISTENER]()
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The Coronavirus integration."""
|
"""The Coronavirus integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -48,24 +47,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
if not coordinator.last_update_success:
|
if not coordinator.last_update_success:
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return all(
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def get_coordinator(
|
async def get_coordinator(
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Mapping
|
from collections.abc import Iterable, Mapping
|
||||||
from contextvars import ContextVar
|
from contextvars import ContextVar
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
@ -999,6 +999,14 @@ class ConfigEntries:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_setup_platforms(
|
||||||
|
self, entry: ConfigEntry, platforms: Iterable[str]
|
||||||
|
) -> None:
|
||||||
|
"""Forward the setup of an entry to platforms."""
|
||||||
|
for platform in platforms:
|
||||||
|
self.hass.async_create_task(self.async_forward_entry_setup(entry, platform))
|
||||||
|
|
||||||
async def async_forward_entry_setup(self, entry: ConfigEntry, domain: str) -> bool:
|
async def async_forward_entry_setup(self, entry: ConfigEntry, domain: str) -> bool:
|
||||||
"""Forward the setup of an entry to a different component.
|
"""Forward the setup of an entry to a different component.
|
||||||
|
|
||||||
|
@ -1021,6 +1029,19 @@ class ConfigEntries:
|
||||||
await entry.async_setup(self.hass, integration=integration)
|
await entry.async_setup(self.hass, integration=integration)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def async_unload_platforms(
|
||||||
|
self, entry: ConfigEntry, platforms: Iterable[str]
|
||||||
|
) -> bool:
|
||||||
|
"""Forward the unloading of an entry to platforms."""
|
||||||
|
return all(
|
||||||
|
await asyncio.gather(
|
||||||
|
*[
|
||||||
|
self.async_forward_entry_unload(entry, platform)
|
||||||
|
for platform in platforms
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
async def async_forward_entry_unload(self, entry: ConfigEntry, domain: str) -> bool:
|
async def async_forward_entry_unload(self, entry: ConfigEntry, domain: str) -> bool:
|
||||||
"""Forward the unloading of an entry to a different component."""
|
"""Forward the unloading of an entry to a different component."""
|
||||||
# It was never loaded.
|
# It was never loaded.
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
"""The NEW_NAME integration."""
|
"""The NEW_NAME integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
@ -18,24 +16,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
# TODO Store an API object for your platforms to access
|
# TODO Store an API object for your platforms to access
|
||||||
# hass.data[DOMAIN][entry.entry_id] = MyApi(...)
|
# hass.data[DOMAIN][entry.entry_id] = MyApi(...)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
"""The NEW_NAME integration."""
|
"""The NEW_NAME integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
@ -18,24 +16,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
# TODO Store an API object for your platforms to access
|
# TODO Store an API object for your platforms to access
|
||||||
# hass.data[DOMAIN][entry.entry_id] = MyApi(...)
|
# hass.data[DOMAIN][entry.entry_id] = MyApi(...)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""The NEW_NAME integration."""
|
"""The NEW_NAME integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -75,24 +74,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
aiohttp_client.async_get_clientsession(hass), session
|
aiohttp_client.async_get_clientsession(hass), session
|
||||||
)
|
)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
|
|
|
@ -257,14 +257,12 @@ async def test_remove_entry(hass, manager):
|
||||||
|
|
||||||
async def mock_setup_entry(hass, entry):
|
async def mock_setup_entry(hass, entry):
|
||||||
"""Mock setting up entry."""
|
"""Mock setting up entry."""
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, ["light"])
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "light")
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def mock_unload_entry(hass, entry):
|
async def mock_unload_entry(hass, entry):
|
||||||
"""Mock unloading an entry."""
|
"""Mock unloading an entry."""
|
||||||
result = await hass.config_entries.async_forward_entry_unload(entry, "light")
|
result = await hass.config_entries.async_unload_platforms(entry, ["light"])
|
||||||
assert result
|
assert result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue