mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Reduce config entry setup/unload boilerplate D-F (#49733)
This commit is contained in:
parent
58ad3b61f7
commit
a67b9eff17
@ -68,10 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
except AdGuardHomeConnectionError as exception:
|
except AdGuardHomeConnectionError as exception:
|
||||||
raise ConfigEntryNotReady from exception
|
raise ConfigEntryNotReady from exception
|
||||||
|
|
||||||
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 add_url(call) -> None:
|
async def add_url(call) -> None:
|
||||||
"""Service call to add a new filter subscription to AdGuard Home."""
|
"""Service call to add a new filter subscription to AdGuard Home."""
|
||||||
@ -126,12 +123,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.services.async_remove(DOMAIN, SERVICE_DISABLE_URL)
|
hass.services.async_remove(DOMAIN, SERVICE_DISABLE_URL)
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_REFRESH)
|
hass.services.async_remove(DOMAIN, SERVICE_REFRESH)
|
||||||
|
|
||||||
for component in PLATFORMS:
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, component)
|
if unload_ok:
|
||||||
|
del hass.data[DOMAIN]
|
||||||
|
|
||||||
del hass.data[DOMAIN]
|
return unload_ok
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class AdGuardHomeEntity(Entity):
|
class AdGuardHomeEntity(Entity):
|
||||||
|
@ -27,6 +27,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
|
PLATFORMS = ["media_player"]
|
||||||
|
|
||||||
|
|
||||||
async def _await_cancel(task):
|
async def _await_cancel(task):
|
||||||
task.cancel()
|
task.cancel()
|
||||||
@ -60,23 +62,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: config_entries.ConfigEnt
|
|||||||
task = asyncio.create_task(_run_client(hass, client, DEFAULT_SCAN_INTERVAL))
|
task = asyncio.create_task(_run_client(hass, client, DEFAULT_SCAN_INTERVAL))
|
||||||
tasks[entry.entry_id] = task
|
tasks[entry.entry_id] = task
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "media_player")
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Cleanup before removing config entry."""
|
"""Cleanup before removing config entry."""
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, "media_player")
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
task = hass.data[DOMAIN_DATA_TASKS].pop(entry.entry_id)
|
task = hass.data[DOMAIN_DATA_TASKS].pop(entry.entry_id)
|
||||||
await _await_cancel(task)
|
await _await_cancel(task)
|
||||||
|
|
||||||
hass.data[DOMAIN_DATA_ENTRIES].pop(entry.entry_id)
|
hass.data[DOMAIN_DATA_ENTRIES].pop(entry.entry_id)
|
||||||
|
|
||||||
return True
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
async def _run_client(hass, client, interval):
|
async def _run_client(hass, client, interval):
|
||||||
|
@ -18,10 +18,11 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Azure DevOps from a config entry."""
|
"""Set up Azure DevOps from a config entry."""
|
||||||
@ -43,18 +44,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data.setdefault(instance_key, {})[DATA_AZURE_DEVOPS_CLIENT] = client
|
hass.data.setdefault(instance_key, {})[DATA_AZURE_DEVOPS_CLIENT] = client
|
||||||
|
|
||||||
# Setup components
|
# Setup components
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigType) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload Azure DevOps config entry."""
|
"""Unload Azure DevOps config entry."""
|
||||||
del hass.data[f"{DOMAIN}_{entry.data[CONF_ORG]}_{entry.data[CONF_PROJECT]}"]
|
del hass.data[f"{DOMAIN}_{entry.data[CONF_ORG]}_{entry.data[CONF_PROJECT]}"]
|
||||||
|
|
||||||
return await hass.config_entries.async_forward_entry_unload(entry, "sensor")
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
||||||
class AzureDevOpsEntity(Entity):
|
class AzureDevOpsEntity(Entity):
|
||||||
|
@ -14,6 +14,8 @@ from .const import CONF_PASSKEY, DATA_BSBLAN_CLIENT, DOMAIN
|
|||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
|
PLATFORMS = [CLIMATE_DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up BSB-Lan from a config entry."""
|
"""Set up BSB-Lan from a config entry."""
|
||||||
@ -36,9 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = {DATA_BSBLAN_CLIENT: bsblan}
|
hass.data[DOMAIN][entry.entry_id] = {DATA_BSBLAN_CLIENT: bsblan}
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, CLIMATE_DOMAIN)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -46,11 +46,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload BSBLan config entry."""
|
"""Unload BSBLan config entry."""
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, CLIMATE_DOMAIN)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
if unload_ok:
|
||||||
|
# Cleanup
|
||||||
|
del hass.data[DOMAIN][entry.entry_id]
|
||||||
|
if not hass.data[DOMAIN]:
|
||||||
|
del hass.data[DOMAIN]
|
||||||
|
|
||||||
# Cleanup
|
return unload_ok
|
||||||
del hass.data[DOMAIN][entry.entry_id]
|
|
||||||
if not hass.data[DOMAIN]:
|
|
||||||
del hass.data[DOMAIN]
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
@ -17,6 +17,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
SCAN_INTERVAL = timedelta(hours=12)
|
SCAN_INTERVAL = timedelta(hours=12)
|
||||||
|
|
||||||
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Load the saved entities."""
|
"""Load the saved entities."""
|
||||||
@ -32,15 +34,14 @@ 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=f"{host}:{port}")
|
hass.config_entries.async_update_entry(entry, unique_id=f"{host}:{port}")
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_forward_entry_unload(entry, "sensor")
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
||||||
class CertExpiryDataUpdateCoordinator(DataUpdateCoordinator[datetime]):
|
class CertExpiryDataUpdateCoordinator(DataUpdateCoordinator[datetime]):
|
||||||
|
@ -12,6 +12,8 @@ from .const import DATA_COORDINATOR, DATA_INFO, DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PLATFORMS = ["climate"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up Coolmaster from a config entry."""
|
"""Set up Coolmaster from a config entry."""
|
||||||
@ -31,20 +33,16 @@ async def async_setup_entry(hass, entry):
|
|||||||
DATA_INFO: info,
|
DATA_INFO: info,
|
||||||
DATA_COORDINATOR: coordinator,
|
DATA_COORDINATOR: coordinator,
|
||||||
}
|
}
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "climate")
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload a Coolmaster config entry."""
|
"""Unload a Coolmaster config entry."""
|
||||||
unload_ok = await hass.config_entries.async_forward_entry_unload(entry, "climate")
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, 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
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,25 +81,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
if not daikin_api:
|
if not daikin_api:
|
||||||
return False
|
return False
|
||||||
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api})
|
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_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, config_entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
await asyncio.wait(
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
[
|
if unload_ok:
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
for platform in PLATFORMS
|
if not hass.data[DOMAIN]:
|
||||||
]
|
hass.data.pop(DOMAIN)
|
||||||
)
|
return unload_ok
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
||||||
if not hass.data[DOMAIN]:
|
|
||||||
hass.data.pop(DOMAIN)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def daikin_api_setup(hass, host, key, uuid, password):
|
async def daikin_api_setup(hass, host, key, uuid, password):
|
||||||
|
@ -175,12 +175,7 @@ class DeconzGateway:
|
|||||||
except AuthenticationRequired as err:
|
except AuthenticationRequired as err:
|
||||||
raise ConfigEntryAuthFailed from err
|
raise ConfigEntryAuthFailed from err
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
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, platform
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
await async_setup_events(self)
|
await async_setup_events(self)
|
||||||
|
|
||||||
@ -250,10 +245,9 @@ class DeconzGateway:
|
|||||||
self.api.async_connection_status_callback = None
|
self.api.async_connection_status_callback = None
|
||||||
self.api.close()
|
self.api.close()
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
await self.hass.config_entries.async_unload_platforms(
|
||||||
await self.hass.config_entries.async_forward_entry_unload(
|
self.config_entry, PLATFORMS
|
||||||
self.config_entry, platform
|
)
|
||||||
)
|
|
||||||
|
|
||||||
async_unload_events(self)
|
async_unload_events(self)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ from .receiver import ConnectDenonAVR
|
|||||||
|
|
||||||
CONF_RECEIVER = "receiver"
|
CONF_RECEIVER = "receiver"
|
||||||
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
||||||
|
PLATFORMS = ["media_player"]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -56,9 +57,7 @@ async def async_setup_entry(
|
|||||||
UNDO_UPDATE_LISTENER: undo_listener,
|
UNDO_UPDATE_LISTENER: undo_listener,
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "media_player")
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -67,8 +66,8 @@ async def async_unload_entry(
|
|||||||
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
|
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
|
||||||
):
|
):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_forward_entry_unload(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
config_entry, "media_player"
|
config_entry, PLATFORMS
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
|
hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||||
|
@ -58,10 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
except GatewayOfflineError as err:
|
except GatewayOfflineError as err:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
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 shutdown(event):
|
def shutdown(event):
|
||||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||||
@ -79,14 +76,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
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 = all(
|
unload = 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
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
hass.async_add_executor_job(gateway.websocket_disconnect)
|
hass.async_add_executor_job(gateway.websocket_disconnect)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The Dexcom integration."""
|
"""The Dexcom integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -67,24 +66,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
COORDINATOR
|
COORDINATOR
|
||||||
].async_config_entry_first_refresh()
|
].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):
|
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][UNDO_UPDATE_LISTENER]()
|
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""The DirecTV integration."""
|
"""The DirecTV integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -42,25 +41,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = dtv
|
hass.data[DOMAIN][entry.entry_id] = dtv
|
||||||
|
|
||||||
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,5 +1,4 @@
|
|||||||
"""Support for DoorBird devices."""
|
"""Support for DoorBird devices."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
@ -167,10 +166,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
UNDO_UPDATE_LISTENER: undo_listener,
|
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
|
||||||
|
|
||||||
@ -184,14 +180,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||||
|
|
||||||
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 dsmr component."""
|
"""The dsmr component."""
|
||||||
import asyncio
|
|
||||||
from asyncio import CancelledError
|
from asyncio import CancelledError
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
|
|
||||||
@ -14,10 +13,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = {}
|
hass.data[DOMAIN][entry.entry_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)
|
|
||||||
)
|
|
||||||
|
|
||||||
listener = entry.add_update_listener(async_update_options)
|
listener = entry.add_update_listener(async_update_options)
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_LISTENER] = listener
|
hass.data[DOMAIN][entry.entry_id][DATA_LISTENER] = listener
|
||||||
@ -35,14 +31,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
with suppress(CancelledError):
|
with suppress(CancelledError):
|
||||||
await task
|
await task
|
||||||
|
|
||||||
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:
|
||||||
listener()
|
listener()
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""The Dune HD component."""
|
"""The Dune HD component."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from pdunehd import DuneHDPlayer
|
from pdunehd import DuneHDPlayer
|
||||||
|
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
@ -10,35 +8,24 @@ from .const import DOMAIN
|
|||||||
PLATFORMS = ["media_player"]
|
PLATFORMS = ["media_player"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
host = config_entry.data[CONF_HOST]
|
host = entry.data[CONF_HOST]
|
||||||
|
|
||||||
player = DuneHDPlayer(host)
|
player = DuneHDPlayer(host)
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = player
|
hass.data[DOMAIN][entry.entry_id] = player
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(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, entry):
|
||||||
"""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(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(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Support for the Dynalite networks."""
|
"""Support for the Dynalite networks."""
|
||||||
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
|
||||||
@ -267,17 +266,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
bridge = DynaliteBridge(hass, entry.data)
|
bridge = DynaliteBridge(hass, entry.data)
|
||||||
# need to do it before the listener
|
# need to do it before the listener
|
||||||
hass.data[DOMAIN][entry.entry_id] = bridge
|
hass.data[DOMAIN][entry.entry_id] = bridge
|
||||||
entry.add_update_listener(async_entry_changed)
|
entry.async_on_unload(entry.add_update_listener(async_entry_changed))
|
||||||
|
|
||||||
if not await bridge.async_setup():
|
if not await bridge.async_setup():
|
||||||
LOGGER.error("Could not set up bridge for entry %s", entry.data)
|
LOGGER.error("Could not set up bridge for entry %s", entry.data)
|
||||||
hass.data[DOMAIN][entry.entry_id] = None
|
hass.data[DOMAIN][entry.entry_id] = None
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -285,10 +281,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
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."""
|
||||||
LOGGER.debug("Unloading entry %s", entry.data)
|
LOGGER.debug("Unloading entry %s", entry.data)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
tasks = [
|
if unload_ok:
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
for platform in PLATFORMS
|
return unload_ok
|
||||||
]
|
|
||||||
results = await asyncio.gather(*tasks)
|
|
||||||
return False not in results
|
|
||||||
|
@ -2,22 +2,16 @@
|
|||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
PLATFORMS = ["sensor"]
|
||||||
async def async_setup(hass, config):
|
|
||||||
"""Set up devices."""
|
|
||||||
hass.data[DOMAIN] = {}
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up flood monitoring sensors for this config entry."""
|
"""Set up flood monitoring sensors for this config entry."""
|
||||||
hass.async_create_task(
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload flood monitoring sensors."""
|
"""Unload flood monitoring sensors."""
|
||||||
return await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for ecobee."""
|
"""Support for ecobee."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from pyecobee import ECOBEE_API_KEY, ECOBEE_REFRESH_TOKEN, Ecobee, ExpiredTokenError
|
from pyecobee import ECOBEE_API_KEY, ECOBEE_REFRESH_TOKEN, Ecobee, ExpiredTokenError
|
||||||
@ -60,10 +59,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
|
|
||||||
hass.data[DOMAIN] = data
|
hass.data[DOMAIN] = data
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -109,14 +105,9 @@ class EcobeeData:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload the config entry and platforms."""
|
"""Unload the config entry and platforms."""
|
||||||
hass.data.pop(DOMAIN)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
if unload_ok:
|
||||||
tasks = []
|
hass.data.pop(DOMAIN)
|
||||||
for platform in PLATFORMS:
|
return unload_ok
|
||||||
tasks.append(
|
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return all(await asyncio.gather(*tasks))
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for EcoNet products."""
|
"""Support for EcoNet products."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -62,10 +61,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
hass.data[DOMAIN][API_CLIENT][config_entry.entry_id] = api
|
hass.data[DOMAIN][API_CLIENT][config_entry.entry_id] = api
|
||||||
hass.data[DOMAIN][EQUIPMENT][config_entry.entry_id] = equipment
|
hass.data[DOMAIN][EQUIPMENT][config_entry.entry_id] = equipment
|
||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
api.subscribe()
|
api.subscribe()
|
||||||
|
|
||||||
@ -88,25 +84,21 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
"""Fetch the latest changes from the API."""
|
"""Fetch the latest changes from the API."""
|
||||||
await api.refresh_equipment()
|
await api.refresh_equipment()
|
||||||
|
|
||||||
async_track_time_interval(hass, resubscribe, INTERVAL)
|
config_entry.async_on_unload(async_track_time_interval(hass, resubscribe, INTERVAL))
|
||||||
async_track_time_interval(hass, fetch_update, INTERVAL + timedelta(minutes=1))
|
config_entry.async_on_unload(
|
||||||
|
async_track_time_interval(hass, fetch_update, INTERVAL + timedelta(minutes=1))
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload a EcoNet config entry."""
|
"""Unload a EcoNet config entry."""
|
||||||
tasks = [
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
if unload_ok:
|
||||||
for platform in PLATFORMS
|
hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id)
|
||||||
]
|
hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id)
|
||||||
|
return unload_ok
|
||||||
await asyncio.gather(*tasks)
|
|
||||||
|
|
||||||
hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id)
|
|
||||||
hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class EcoNetEntity(Entity):
|
class EcoNetEntity(Entity):
|
||||||
|
@ -12,6 +12,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
|
|
||||||
from .const import DATA_ELGATO_CLIENT, DOMAIN
|
from .const import DATA_ELGATO_CLIENT, DOMAIN
|
||||||
|
|
||||||
|
PLATFORMS = [LIGHT_DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Elgato Key Light from a config entry."""
|
"""Set up Elgato Key Light from a config entry."""
|
||||||
@ -31,10 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = {DATA_ELGATO_CLIENT: elgato}
|
hass.data[DOMAIN][entry.entry_id] = {DATA_ELGATO_CLIENT: elgato}
|
||||||
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, LIGHT_DOMAIN)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -42,11 +41,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload Elgato Key Light config entry."""
|
"""Unload Elgato Key Light config entry."""
|
||||||
# Unload entities for this entry/device.
|
# Unload entities for this entry/device.
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, LIGHT_DOMAIN)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
if unload_ok:
|
||||||
# Cleanup
|
# Cleanup
|
||||||
del hass.data[DOMAIN][entry.entry_id]
|
del hass.data[DOMAIN][entry.entry_id]
|
||||||
if not hass.data[DOMAIN]:
|
if not hass.data[DOMAIN]:
|
||||||
del hass.data[DOMAIN]
|
del hass.data[DOMAIN]
|
||||||
|
return unload_ok
|
||||||
return True
|
|
||||||
|
@ -262,10 +262,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
"keypads": {},
|
"keypads": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -286,14 +283,7 @@ def _find_elk_by_prefix(hass, prefix):
|
|||||||
|
|
||||||
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
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# disconnect cleanly
|
# disconnect cleanly
|
||||||
hass.data[DOMAIN][entry.entry_id]["elk"].disconnect()
|
hass.data[DOMAIN][entry.entry_id]["elk"].disconnect()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The SiteSage Emonitor integration."""
|
"""The SiteSage Emonitor integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -38,27 +37,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
hass.data.setdefault(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)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""The Enphase Envoy integration."""
|
"""The Enphase Envoy integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -79,25 +78,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
NAME: name,
|
NAME: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The epson integration."""
|
"""The epson integration."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from epson_projector import Projector
|
from epson_projector import Projector
|
||||||
@ -43,23 +42,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
return False
|
return False
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = projector
|
hass.data[DOMAIN][entry.entry_id] = projector
|
||||||
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)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -594,12 +594,9 @@ async def _cleanup_instance(
|
|||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload an esphome config entry."""
|
"""Unload an esphome config entry."""
|
||||||
entry_data = await _cleanup_instance(hass, entry)
|
entry_data = await _cleanup_instance(hass, entry)
|
||||||
tasks = []
|
return await hass.config_entries.async_unload_platforms(
|
||||||
for platform in entry_data.loaded_platforms:
|
entry, entry_data.loaded_platforms
|
||||||
tasks.append(hass.config_entries.async_forward_entry_unload(entry, platform))
|
)
|
||||||
if tasks:
|
|
||||||
await asyncio.wait(tasks)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def platform_async_setup_entry(
|
async def platform_async_setup_entry(
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for Ezviz camera."""
|
"""Support for Ezviz camera."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -82,10 +81,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
DATA_COORDINATOR: coordinator,
|
DATA_COORDINATOR: coordinator,
|
||||||
DATA_UNDO_UPDATE_LISTENER: undo_listener,
|
DATA_UNDO_UPDATE_LISTENER: undo_listener,
|
||||||
}
|
}
|
||||||
for component in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -96,19 +92,10 @@ async def async_unload_entry(hass, entry):
|
|||||||
if entry.data.get(CONF_TYPE) == ATTR_TYPE_CAMERA:
|
if entry.data.get(CONF_TYPE) == ATTR_TYPE_CAMERA:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
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, component)
|
|
||||||
for component 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]()
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The FAA Delays integration."""
|
"""The FAA Delays integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -30,27 +29,16 @@ 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)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The FireServiceRota integration."""
|
"""The FireServiceRota integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -59,10 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
DATA_COORDINATOR: coordinator,
|
DATA_COORDINATOR: 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
|
||||||
|
|
||||||
@ -73,19 +69,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.async_add_executor_job(
|
await hass.async_add_executor_job(
|
||||||
hass.data[DOMAIN][entry.entry_id].websocket.stop_listener
|
hass.data[DOMAIN][entry.entry_id].websocket.stop_listener
|
||||||
)
|
)
|
||||||
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
unload_ok = all(
|
|
||||||
await asyncio.gather(
|
|
||||||
*[
|
|
||||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
|
||||||
for platform in PLATFORMS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
del hass.data[DOMAIN][entry.entry_id]
|
del hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ from .const import CONF_TOKEN_EXPIRES_IN, CONF_TOKEN_EXPIRY, DOMAIN
|
|||||||
|
|
||||||
CONF_ID_TOKEN = "id_token"
|
CONF_ID_TOKEN = "id_token"
|
||||||
|
|
||||||
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Set up Flick Electric from a config entry."""
|
"""Set up Flick Electric from a config entry."""
|
||||||
@ -29,20 +31,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = FlickAPI(auth)
|
hass.data[DOMAIN][entry.entry_id] = FlickAPI(auth)
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
|
||||||
)
|
|
||||||
|
|
||||||
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."""
|
||||||
if await hass.config_entries.async_forward_entry_unload(entry, "sensor"):
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
return True
|
return unload_ok
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class HassFlickAuth(AbstractFlickAuth):
|
class HassFlickAuth(AbstractFlickAuth):
|
||||||
|
@ -44,25 +44,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
tasks = [device.async_refresh() for device in devices]
|
tasks = [device.async_refresh() for device in devices]
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The flume integration."""
|
"""The flume integration."""
|
||||||
import asyncio
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -74,24 +73,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
FLUME_HTTP_SESSION: http_session,
|
FLUME_HTTP_SESSION: http_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):
|
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][FLUME_HTTP_SESSION].close()
|
hass.data[DOMAIN][entry.entry_id][FLUME_HTTP_SESSION].close()
|
||||||
|
|
||||||
|
@ -31,15 +31,15 @@ async def async_setup(hass, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up Flu Near You as config entry."""
|
"""Set up Flu Near You as config entry."""
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id] = {}
|
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {}
|
||||||
|
|
||||||
websession = aiohttp_client.async_get_clientsession(hass)
|
websession = aiohttp_client.async_get_clientsession(hass)
|
||||||
client = Client(websession)
|
client = Client(websession)
|
||||||
|
|
||||||
latitude = config_entry.data.get(CONF_LATITUDE, hass.config.latitude)
|
latitude = entry.data.get(CONF_LATITUDE, hass.config.latitude)
|
||||||
longitude = config_entry.data.get(CONF_LONGITUDE, hass.config.longitude)
|
longitude = entry.data.get(CONF_LONGITUDE, hass.config.longitude)
|
||||||
|
|
||||||
async def async_update(api_category):
|
async def async_update(api_category):
|
||||||
"""Get updated date from the API based on category."""
|
"""Get updated date from the API based on category."""
|
||||||
@ -54,7 +54,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
data_init_tasks = []
|
data_init_tasks = []
|
||||||
for api_category in [CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT]:
|
for api_category in [CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT]:
|
||||||
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id][
|
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
|
||||||
api_category
|
api_category
|
||||||
] = DataUpdateCoordinator(
|
] = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
@ -67,25 +67,15 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
await asyncio.gather(*data_init_tasks)
|
await asyncio.gather(*data_init_tasks)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(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, entry):
|
||||||
"""Unload an Flu Near You config entry."""
|
"""Unload an Flu Near You 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(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(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -3,18 +3,18 @@ from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
|||||||
|
|
||||||
from .const import DOMAIN, HASS_DATA_REMOVE_LISTENERS_KEY, HASS_DATA_UPDATER_KEY
|
from .const import DOMAIN, HASS_DATA_REMOVE_LISTENERS_KEY, HASS_DATA_UPDATER_KEY
|
||||||
|
|
||||||
|
PLATFORMS = [MP_DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up forked-daapd from a config entry by forwarding to platform."""
|
"""Set up forked-daapd from a config entry by forwarding to platform."""
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, MP_DOMAIN)
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Remove forked-daapd component."""
|
"""Remove forked-daapd component."""
|
||||||
status = await hass.config_entries.async_forward_entry_unload(entry, MP_DOMAIN)
|
status = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if status and hass.data.get(DOMAIN) and hass.data[DOMAIN].get(entry.entry_id):
|
if status and hass.data.get(DOMAIN) and hass.data[DOMAIN].get(entry.entry_id):
|
||||||
hass.data[DOMAIN][entry.entry_id][
|
hass.data[DOMAIN][entry.entry_id][
|
||||||
HASS_DATA_UPDATER_KEY
|
HASS_DATA_UPDATER_KEY
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The foscam component."""
|
"""The foscam component."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from libpyfoscam import FoscamCamera
|
from libpyfoscam import FoscamCamera
|
||||||
|
|
||||||
@ -14,19 +13,11 @@ from .const import CONF_RTSP_PORT, DOMAIN, LOGGER, SERVICE_PTZ, SERVICE_PTZ_PRES
|
|||||||
PLATFORMS = ["camera"]
|
PLATFORMS = ["camera"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict):
|
|
||||||
"""Set up the foscam component."""
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Set up foscam from a config entry."""
|
"""Set up foscam from a config entry."""
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = entry.data
|
hass.data[DOMAIN][entry.entry_id] = entry.data
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -34,15 +25,7 @@ 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].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for Freebox devices (Freebox v6 and Freebox mini 4K)."""
|
"""Support for Freebox devices (Freebox v6 and Freebox mini 4K)."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -45,10 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.unique_id] = router
|
hass.data[DOMAIN][entry.unique_id] = router
|
||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Services
|
# Services
|
||||||
async def async_reboot(call):
|
async def async_reboot(call):
|
||||||
@ -70,14 +66,7 @@ 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:
|
||||||
router = hass.data[DOMAIN].pop(entry.unique_id)
|
router = hass.data[DOMAIN].pop(entry.unique_id)
|
||||||
await router.close()
|
await router.close()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for AVM Fritz!Box functions."""
|
"""Support for AVM Fritz!Box functions."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from fritzconnection.core.exceptions import FritzConnectionException, FritzSecurityError
|
from fritzconnection.core.exceptions import FritzConnectionException, FritzSecurityError
|
||||||
@ -52,10 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_unload)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_unload)
|
||||||
)
|
)
|
||||||
# Load the other platforms like switch
|
# Load the other platforms like switch
|
||||||
for domain in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, domain)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -65,14 +61,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigType) -> bool:
|
|||||||
fritzbox: FritzBoxTools = hass.data[DOMAIN][entry.entry_id]
|
fritzbox: FritzBoxTools = hass.data[DOMAIN][entry.entry_id]
|
||||||
fritzbox.async_unload()
|
fritzbox.async_unload()
|
||||||
|
|
||||||
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 @@
|
|||||||
"""Support for AVM Fritz!Box smarthome devices."""
|
"""Support for AVM Fritz!Box smarthome devices."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
|
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
|
||||||
@ -80,10 +79,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
def logout_fritzbox(event):
|
def logout_fritzbox(event):
|
||||||
"""Close connections to this fritzbox."""
|
"""Close connections to this fritzbox."""
|
||||||
@ -101,14 +97,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
fritz = hass.data[DOMAIN][entry.entry_id][CONF_CONNECTIONS]
|
fritz = hass.data[DOMAIN][entry.entry_id][CONF_CONNECTIONS]
|
||||||
await hass.async_add_executor_job(fritz.logout)
|
await hass.async_add_executor_job(fritz.logout)
|
||||||
|
|
||||||
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 fritzbox_callmonitor integration."""
|
"""The fritzbox_callmonitor integration."""
|
||||||
from asyncio import gather
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from fritzconnection.core.exceptions import FritzConnectionException, FritzSecurityError
|
from fritzconnection.core.exceptions import FritzConnectionException, FritzSecurityError
|
||||||
@ -54,10 +53,7 @@ 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
|
||||||
|
|
||||||
@ -65,13 +61,8 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unloading the fritzbox_callmonitor platforms."""
|
"""Unloading the fritzbox_callmonitor platforms."""
|
||||||
|
|
||||||
unload_ok = all(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await 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]()
|
||||||
|
@ -87,8 +87,6 @@ async def test_user_valid(hass):
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.foscam.config_flow.FoscamCamera",
|
"homeassistant.components.foscam.config_flow.FoscamCamera",
|
||||||
) as mock_foscam_camera, patch(
|
) as mock_foscam_camera, patch(
|
||||||
"homeassistant.components.foscam.async_setup", return_value=True
|
|
||||||
) as mock_setup, patch(
|
|
||||||
"homeassistant.components.foscam.async_setup_entry",
|
"homeassistant.components.foscam.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
@ -105,7 +103,6 @@ async def test_user_valid(hass):
|
|||||||
assert result["title"] == CAMERA_NAME
|
assert result["title"] == CAMERA_NAME
|
||||||
assert result["data"] == VALID_CONFIG
|
assert result["data"] == VALID_CONFIG
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
@ -263,8 +260,6 @@ async def test_import_user_valid(hass):
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.foscam.config_flow.FoscamCamera",
|
"homeassistant.components.foscam.config_flow.FoscamCamera",
|
||||||
) as mock_foscam_camera, patch(
|
) as mock_foscam_camera, patch(
|
||||||
"homeassistant.components.foscam.async_setup", return_value=True
|
|
||||||
) as mock_setup, patch(
|
|
||||||
"homeassistant.components.foscam.async_setup_entry",
|
"homeassistant.components.foscam.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
@ -282,7 +277,6 @@ async def test_import_user_valid(hass):
|
|||||||
assert result["title"] == CAMERA_NAME
|
assert result["title"] == CAMERA_NAME
|
||||||
assert result["data"] == VALID_CONFIG
|
assert result["data"] == VALID_CONFIG
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
@ -293,8 +287,6 @@ async def test_import_user_valid_with_name(hass):
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.foscam.config_flow.FoscamCamera",
|
"homeassistant.components.foscam.config_flow.FoscamCamera",
|
||||||
) as mock_foscam_camera, patch(
|
) as mock_foscam_camera, patch(
|
||||||
"homeassistant.components.foscam.async_setup", return_value=True
|
|
||||||
) as mock_setup, patch(
|
|
||||||
"homeassistant.components.foscam.async_setup_entry",
|
"homeassistant.components.foscam.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
@ -316,7 +308,6 @@ async def test_import_user_valid_with_name(hass):
|
|||||||
assert result["title"] == name
|
assert result["title"] == name
|
||||||
assert result["data"] == VALID_CONFIG
|
assert result["data"] == VALID_CONFIG
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user