mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Reduce config entry setup/unload boilerplate T-U (#49786)
This commit is contained in:
parent
87420627a8
commit
4b74c57285
@ -1,5 +1,4 @@
|
|||||||
"""Support for the (unofficial) Tado API."""
|
"""Support for the (unofficial) Tado API."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -85,10 +84,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
UPDATE_LISTENER: update_listener,
|
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
|
||||||
|
|
||||||
@ -108,14 +104,7 @@ async def _async_update_listener(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
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id][UPDATE_TRACK]()
|
hass.data[DOMAIN][entry.entry_id][UPDATE_TRACK]()
|
||||||
hass.data[DOMAIN][entry.entry_id][UPDATE_LISTENER]()
|
hass.data[DOMAIN][entry.entry_id][UPDATE_LISTENER]()
|
||||||
|
@ -104,14 +104,7 @@ async def async_unload_entry(hass, entry):
|
|||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
|
||||||
# cleanup platforms
|
# cleanup platforms
|
||||||
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
|
||||||
|
|
||||||
|
@ -119,15 +119,13 @@ async def async_unload_entry(hass, config_entry):
|
|||||||
hass.data[NEW_CLIENT_TASK].cancel()
|
hass.data[NEW_CLIENT_TASK].cancel()
|
||||||
interval_tracker = hass.data.pop(INTERVAL_TRACKER)
|
interval_tracker = hass.data.pop(INTERVAL_TRACKER)
|
||||||
interval_tracker()
|
interval_tracker()
|
||||||
await asyncio.wait(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
[
|
config_entry, CONFIG_ENTRY_IS_SETUP
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
||||||
for platform in hass.data.pop(CONFIG_ENTRY_IS_SETUP)
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
del hass.data[DOMAIN]
|
del hass.data[DOMAIN]
|
||||||
del hass.data[DATA_CONFIG_ENTRY_LOCK]
|
del hass.data[DATA_CONFIG_ENTRY_LOCK]
|
||||||
return True
|
del hass.data[CONFIG_ENTRY_IS_SETUP]
|
||||||
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class TelldusLiveClient:
|
class TelldusLiveClient:
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for Tesla cars."""
|
"""Support for Tesla cars."""
|
||||||
import asyncio
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
@ -188,23 +187,15 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
for device in all_devices:
|
for device in all_devices:
|
||||||
entry_data["devices"][device.hass_type].append(device)
|
entry_data["devices"][device.hass_type].append(device)
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
_LOGGER.debug("Loading %s", platform)
|
|
||||||
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 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
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
for listener in hass.data[DOMAIN][config_entry.entry_id][DATA_LISTENER]:
|
for listener in hass.data[DOMAIN][config_entry.entry_id][DATA_LISTENER]:
|
||||||
listener()
|
listener()
|
||||||
|
@ -73,10 +73,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
_LOGGER.error("Failed to login. %s", exp)
|
_LOGGER.error("Failed to login. %s", exp)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
# set up notify platform, no entry support for notify component yet,
|
# set up notify platform, no entry support for notify component yet,
|
||||||
# have to use discovery to load platform.
|
# have to use discovery to load platform.
|
||||||
@ -90,17 +87,10 @@ async def async_setup_entry(hass, entry):
|
|||||||
|
|
||||||
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:
|
||||||
tibber_connection = hass.data.get(DOMAIN)
|
tibber_connection = hass.data.get(DOMAIN)
|
||||||
await tibber_connection.rt_disconnect()
|
await tibber_connection.rt_disconnect()
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The Tile component."""
|
"""The Tile component."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
@ -74,25 +73,14 @@ async def async_setup_entry(hass, entry):
|
|||||||
|
|
||||||
await gather_with_concurrency(DEFAULT_INIT_TASK_LIMIT, *coordinator_init_tasks)
|
await gather_with_concurrency(DEFAULT_INIT_TASK_LIMIT, *coordinator_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(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload a Tile config entry."""
|
"""Unload a Tile 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_COORDINATOR].pop(entry.entry_id)
|
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for Toon van Eneco devices."""
|
"""Support for Toon van Eneco devices."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -115,10 +114,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Spin up the platforms
|
# Spin up the platforms
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
# If Home Assistant is already in a running state, register the webhook
|
# If Home Assistant is already in a running state, register the webhook
|
||||||
# immediately, else trigger it after Home Assistant has finished starting.
|
# immediately, else trigger it after Home Assistant has finished starting.
|
||||||
@ -139,14 +135,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.data[DOMAIN][entry.entry_id].unregister_webhook()
|
await hass.data[DOMAIN][entry.entry_id].unregister_webhook()
|
||||||
|
|
||||||
# Unload entities for this entry/device.
|
# Unload entities for this entry/device.
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The totalconnect component."""
|
"""The totalconnect component."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from total_connect_client import TotalConnectClient
|
from total_connect_client import TotalConnectClient
|
||||||
@ -58,24 +57,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = client
|
hass.data[DOMAIN][entry.entry_id] = client
|
||||||
|
|
||||||
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: ConfigEntry):
|
async def async_unload_entry(hass, 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)
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
DOMAIN = "tplink"
|
DOMAIN = "tplink"
|
||||||
|
|
||||||
|
PLATFORMS = [CONF_LIGHT, CONF_SWITCH]
|
||||||
|
|
||||||
TPLINK_HOST_SCHEMA = vol.Schema({vol.Required(CONF_HOST): cv.string})
|
TPLINK_HOST_SCHEMA = vol.Schema({vol.Required(CONF_HOST): cv.string})
|
||||||
|
|
||||||
|
|
||||||
@ -109,17 +111,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigType):
|
|||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
forward_unload = hass.config_entries.async_forward_entry_unload
|
platforms = [platform for platform in PLATFORMS if platform in hass.data[DOMAIN]]
|
||||||
remove_lights = remove_switches = False
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, platforms)
|
||||||
if hass.data[DOMAIN][CONF_LIGHT]:
|
if unload_ok:
|
||||||
remove_lights = await forward_unload(entry, "light")
|
|
||||||
if hass.data[DOMAIN][CONF_SWITCH]:
|
|
||||||
remove_switches = await forward_unload(entry, "switch")
|
|
||||||
|
|
||||||
if remove_lights or remove_switches:
|
|
||||||
hass.data[DOMAIN].clear()
|
hass.data[DOMAIN].clear()
|
||||||
return True
|
|
||||||
|
|
||||||
# We were not able to unload the platforms, either because there
|
return unload_ok
|
||||||
# were none or one of the forward_unloads failed.
|
|
||||||
return False
|
|
||||||
|
@ -25,6 +25,9 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
PLATFORMS = [DEVICE_TRACKER]
|
||||||
|
|
||||||
|
|
||||||
TRACKER_UPDATE = f"{DOMAIN}_tracker_update"
|
TRACKER_UPDATE = f"{DOMAIN}_tracker_update"
|
||||||
|
|
||||||
|
|
||||||
@ -93,9 +96,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
DOMAIN, "Traccar", entry.data[CONF_WEBHOOK_ID], handle_webhook
|
DOMAIN, "Traccar", entry.data[CONF_WEBHOOK_ID], handle_webhook
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, DEVICE_TRACKER)
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -103,8 +104,7 @@ async def async_unload_entry(hass, entry):
|
|||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
||||||
hass.data[DOMAIN]["unsub_device_tracker"].pop(entry.entry_id)()
|
hass.data[DOMAIN]["unsub_device_tracker"].pop(entry.entry_id)()
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, DEVICE_TRACKER)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async_remove_entry = config_entry_flow.webhook_async_remove_entry
|
async_remove_entry = config_entry_flow.webhook_async_remove_entry
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for IKEA Tradfri."""
|
"""Support for IKEA Tradfri."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -149,10 +148,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
sw_version=gateway_info.firmware_version,
|
sw_version=gateway_info.firmware_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
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_keep_alive(now):
|
async def async_keep_alive(now):
|
||||||
if hass.is_stopping:
|
if hass.is_stopping:
|
||||||
@ -172,14 +168,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:
|
||||||
tradfri_data = hass.data[DOMAIN].pop(entry.entry_id)
|
tradfri_data = hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
factory = tradfri_data[FACTORY]
|
factory = tradfri_data[FACTORY]
|
||||||
|
@ -127,8 +127,9 @@ async def async_unload_entry(hass, config_entry):
|
|||||||
if client.unsub_timer:
|
if client.unsub_timer:
|
||||||
client.unsub_timer()
|
client.unsub_timer()
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
config_entry, PLATFORMS
|
||||||
|
)
|
||||||
|
|
||||||
if not hass.data[DOMAIN]:
|
if not hass.data[DOMAIN]:
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_ADD_TORRENT)
|
hass.services.async_remove(DOMAIN, SERVICE_ADD_TORRENT)
|
||||||
@ -136,7 +137,7 @@ async def async_unload_entry(hass, config_entry):
|
|||||||
hass.services.async_remove(DOMAIN, SERVICE_START_TORRENT)
|
hass.services.async_remove(DOMAIN, SERVICE_START_TORRENT)
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_STOP_TORRENT)
|
hass.services.async_remove(DOMAIN, SERVICE_STOP_TORRENT)
|
||||||
|
|
||||||
return True
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
async def get_api(hass, entry):
|
async def get_api(hass, entry):
|
||||||
@ -198,12 +199,7 @@ class TransmissionClient:
|
|||||||
self.add_options()
|
self.add_options()
|
||||||
self.set_scan_interval(self.config_entry.options[CONF_SCAN_INTERVAL])
|
self.set_scan_interval(self.config_entry.options[CONF_SCAN_INTERVAL])
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_torrent(service):
|
def add_torrent(service):
|
||||||
"""Add new torrent to download."""
|
"""Add new torrent to download."""
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support for Tuya Smart devices."""
|
"""Support for Tuya Smart devices."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -250,17 +249,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):
|
||||||
"""Unloading the Tuya platforms."""
|
"""Unloading the Tuya platforms."""
|
||||||
domain_data = hass.data[DOMAIN]
|
domain_data = hass.data[DOMAIN]
|
||||||
|
platforms = [platform.split(".", 1)[0] for platform in domain_data[ENTRY_IS_SETUP]]
|
||||||
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.split(".", 1)[0]
|
|
||||||
)
|
|
||||||
for platform in domain_data[ENTRY_IS_SETUP]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
domain_data["listener"]()
|
domain_data["listener"]()
|
||||||
domain_data[STOP_CANCEL]()
|
domain_data[STOP_CANCEL]()
|
||||||
|
@ -28,6 +28,8 @@ SCAN_INTERVAL = timedelta(seconds=3600)
|
|||||||
SERVICE_UPDATE = "update"
|
SERVICE_UPDATE = "update"
|
||||||
SERVICE_SCHEMA = vol.Schema({vol.Optional(CONF_ID): cv.string})
|
SERVICE_SCHEMA = vol.Schema({vol.Optional(CONF_ID): cv.string})
|
||||||
|
|
||||||
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
|
|
||||||
async def _update_twentemilieu(hass: HomeAssistant, unique_id: str | None) -> None:
|
async def _update_twentemilieu(hass: HomeAssistant, unique_id: str | None) -> None:
|
||||||
"""Update Twente Milieu."""
|
"""Update Twente Milieu."""
|
||||||
@ -71,9 +73,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
unique_id = entry.data[CONF_ID]
|
unique_id = entry.data[CONF_ID]
|
||||||
hass.data.setdefault(DOMAIN, {})[unique_id] = twentemilieu
|
hass.data.setdefault(DOMAIN, {})[unique_id] = twentemilieu
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _interval_update(now=None) -> None:
|
async def _interval_update(now=None) -> None:
|
||||||
"""Update Twente Milieu data."""
|
"""Update Twente Milieu data."""
|
||||||
@ -86,8 +86,8 @@ 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 Twente Milieu config entry."""
|
"""Unload Twente Milieu config entry."""
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, "sensor")
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
del hass.data[DOMAIN][entry.data[CONF_ID]]
|
del hass.data[DOMAIN][entry.data[CONF_ID]]
|
||||||
|
|
||||||
return True
|
return unload_ok
|
||||||
|
@ -8,11 +8,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
|
|
||||||
from .const import CONF_ENTRY_HOST, CONF_ENTRY_ID, DOMAIN
|
from .const import CONF_ENTRY_HOST, CONF_ENTRY_ID, DOMAIN
|
||||||
|
|
||||||
|
PLATFORMS = ["light"]
|
||||||
async def async_setup(hass: HomeAssistant, config: dict):
|
|
||||||
"""Set up the twinkly integration."""
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||||
@ -27,9 +23,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
|||||||
host, async_get_clientsession(hass)
|
host, async_get_clientsession(hass)
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, "light")
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -362,12 +362,7 @@ class UniFiController:
|
|||||||
self.wireless_clients = wireless_clients.get_data(self.config_entry)
|
self.wireless_clients = wireless_clients.get_data(self.config_entry)
|
||||||
self.update_wireless_clients()
|
self.update_wireless_clients()
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.api.start_websocket()
|
self.api.start_websocket()
|
||||||
|
|
||||||
@ -452,16 +447,10 @@ class UniFiController:
|
|||||||
"""
|
"""
|
||||||
self.api.stop_websocket()
|
self.api.stop_websocket()
|
||||||
|
|
||||||
unload_ok = all(
|
unload_ok = 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:
|
if not unload_ok:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Support the UPB PIM."""
|
"""Support the UPB PIM."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import upb_lib
|
import upb_lib
|
||||||
|
|
||||||
@ -29,10 +28,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = {"upb": upb}
|
hass.data[DOMAIN][config_entry.entry_id] = {"upb": upb}
|
||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _element_changed(element, changeset):
|
def _element_changed(element, changeset):
|
||||||
change = changeset.get("last_change")
|
change = changeset.get("last_change")
|
||||||
@ -60,21 +56,13 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload the config_entry."""
|
"""Unload the config_entry."""
|
||||||
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
unload_ok = all(
|
config_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:
|
||||||
upb = hass.data[DOMAIN][config_entry.entry_id]["upb"]
|
upb = hass.data[DOMAIN][config_entry.entry_id]["upb"]
|
||||||
upb.disconnect()
|
upb.disconnect()
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,22 +223,20 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
upcloud_data.coordinators[config_entry.data[CONF_USERNAME]] = coordinator
|
upcloud_data.coordinators[config_entry.data[CONF_USERNAME]] = coordinator
|
||||||
|
|
||||||
# Forward entry setup
|
# Forward entry setup
|
||||||
for domain in CONFIG_ENTRY_DOMAINS:
|
hass.config_entries.async_setup_platforms(config_entry, CONFIG_ENTRY_DOMAINS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, domain)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass, config_entry):
|
||||||
"""Unload the config entry."""
|
"""Unload the config entry."""
|
||||||
for domain in CONFIG_ENTRY_DOMAINS:
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
await hass.config_entries.async_forward_entry_unload(config_entry, domain)
|
config_entry, CONFIG_ENTRY_DOMAINS
|
||||||
|
)
|
||||||
|
|
||||||
hass.data[DATA_UPCLOUD].coordinators.pop(config_entry.data[CONF_USERNAME])
|
hass.data[DATA_UPCLOUD].coordinators.pop(config_entry.data[CONF_USERNAME])
|
||||||
|
|
||||||
return True
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class UpCloudServerEntity(CoordinatorEntity):
|
class UpCloudServerEntity(CoordinatorEntity):
|
||||||
|
@ -31,6 +31,8 @@ from .device import Device
|
|||||||
NOTIFICATION_ID = "upnp_notification"
|
NOTIFICATION_ID = "upnp_notification"
|
||||||
NOTIFICATION_TITLE = "UPnP/IGD Setup"
|
NOTIFICATION_TITLE = "UPnP/IGD Setup"
|
||||||
|
|
||||||
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.Schema(
|
DOMAIN: vol.Schema(
|
||||||
@ -144,9 +146,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
|
|
||||||
# Create sensors.
|
# Create sensors.
|
||||||
_LOGGER.debug("Enabling sensors")
|
_LOGGER.debug("Enabling sensors")
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, "sensor")
|
|
||||||
)
|
|
||||||
|
|
||||||
# Start device updater.
|
# Start device updater.
|
||||||
await device.async_start()
|
await device.async_start()
|
||||||
@ -166,4 +166,4 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
del hass.data[DOMAIN][DOMAIN_DEVICES][udn]
|
del hass.data[DOMAIN][DOMAIN_DEVICES][udn]
|
||||||
|
|
||||||
_LOGGER.debug("Deleting sensors")
|
_LOGGER.debug("Deleting sensors")
|
||||||
return await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
|
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user