Add async_remove_config_entry_device support to lookin (#73381)

This commit is contained in:
J. Nick Koston 2022-06-12 13:46:20 -10:00 committed by GitHub
parent a1637e4fce
commit 0bcc5d7a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import CONF_HOST, Platform from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN, PLATFORMS, TYPE_TO_PLATFORM from .const import DOMAIN, PLATFORMS, TYPE_TO_PLATFORM
@ -182,3 +183,19 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
manager: LookinUDPManager = hass.data[DOMAIN][UDP_MANAGER] manager: LookinUDPManager = hass.data[DOMAIN][UDP_MANAGER]
await manager.async_stop() await manager.async_stop()
return unload_ok return unload_ok
async def async_remove_config_entry_device(
hass: HomeAssistant, entry: ConfigEntry, device_entry: dr.DeviceEntry
) -> bool:
"""Remove lookin config entry from a device."""
data: LookinData = hass.data[DOMAIN][entry.entry_id]
all_identifiers: set[tuple[str, str]] = {
(DOMAIN, data.lookin_device.id),
*((DOMAIN, remote["UUID"]) for remote in data.devices),
}
return not any(
identifier
for identifier in device_entry.identifiers
if identifier in all_identifiers
)