diff --git a/homeassistant/components/icloud/__init__.py b/homeassistant/components/icloud/__init__.py index 62eb2fb91ac..687c6bf93de 100644 --- a/homeassistant/components/icloud/__init__.py +++ b/homeassistant/components/icloud/__init__.py @@ -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 diff --git a/homeassistant/components/icloud/const.py b/homeassistant/components/icloud/const.py index 57a3f48936c..3349615ed57 100644 --- a/homeassistant/components/icloud/const.py +++ b/homeassistant/components/icloud/const.py @@ -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"