Add async_unload_entry to iCloud (#31917)

pull/31932/head
Quentame 2020-02-17 22:23:24 +01:00 committed by GitHub
parent e52adbb942
commit 3743aaf70f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,5 @@
"""The iCloud component."""
import asyncio
import logging
import voluptuous as vol
@ -16,7 +17,7 @@ from .const import (
DEFAULT_GPS_ACCURACY_THRESHOLD,
DEFAULT_MAX_INTERVAL,
DOMAIN,
ICLOUD_COMPONENTS,
PLATFORMS,
STORAGE_KEY,
STORAGE_VERSION,
)
@ -127,9 +128,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
hass.data[DOMAIN][username] = account
for component in ICLOUD_COMPONENTS:
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
hass.config_entries.async_forward_entry_setup(entry, platform)
)
def play_sound(service: ServiceDataType) -> None:
@ -212,3 +213,19 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
)
return True
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in PLATFORMS
]
)
)
if unload_ok:
hass.data[DOMAIN].pop(entry.data[CONF_USERNAME])
return unload_ok

View File

@ -13,7 +13,7 @@ DEFAULT_GPS_ACCURACY_THRESHOLD = 500 # meters
STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1
ICLOUD_COMPONENTS = ["device_tracker", "sensor"]
PLATFORMS = ["device_tracker", "sensor"]
# pyicloud.AppleDevice status
DEVICE_BATTERY_LEVEL = "batteryLevel"