Add async_unload_entry to iCloud (#31917)
parent
e52adbb942
commit
3743aaf70f
|
@ -1,4 +1,5 @@
|
||||||
"""The iCloud component."""
|
"""The iCloud component."""
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -16,7 +17,7 @@ from .const import (
|
||||||
DEFAULT_GPS_ACCURACY_THRESHOLD,
|
DEFAULT_GPS_ACCURACY_THRESHOLD,
|
||||||
DEFAULT_MAX_INTERVAL,
|
DEFAULT_MAX_INTERVAL,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
ICLOUD_COMPONENTS,
|
PLATFORMS,
|
||||||
STORAGE_KEY,
|
STORAGE_KEY,
|
||||||
STORAGE_VERSION,
|
STORAGE_VERSION,
|
||||||
)
|
)
|
||||||
|
@ -127,9 +128,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||||
|
|
||||||
hass.data[DOMAIN][username] = account
|
hass.data[DOMAIN][username] = account
|
||||||
|
|
||||||
for component in ICLOUD_COMPONENTS:
|
for platform in PLATFORMS:
|
||||||
hass.async_create_task(
|
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:
|
def play_sound(service: ServiceDataType) -> None:
|
||||||
|
@ -212,3 +213,19 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
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
|
||||||
|
|
|
@ -13,7 +13,7 @@ DEFAULT_GPS_ACCURACY_THRESHOLD = 500 # meters
|
||||||
STORAGE_KEY = DOMAIN
|
STORAGE_KEY = DOMAIN
|
||||||
STORAGE_VERSION = 1
|
STORAGE_VERSION = 1
|
||||||
|
|
||||||
ICLOUD_COMPONENTS = ["device_tracker", "sensor"]
|
PLATFORMS = ["device_tracker", "sensor"]
|
||||||
|
|
||||||
# pyicloud.AppleDevice status
|
# pyicloud.AppleDevice status
|
||||||
DEVICE_BATTERY_LEVEL = "batteryLevel"
|
DEVICE_BATTERY_LEVEL = "batteryLevel"
|
||||||
|
|
Loading…
Reference in New Issue