Allow manual delete of stale Unifi device from UI (#115267)

* Allow manual delete of stale device from UI

* Add unit tests for remove_config_entry_device
This commit is contained in:
wittypluck 2024-04-21 11:08:39 +02:00 committed by GitHub
parent b592225a87
commit 1c0c0bb0bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 112 additions and 1 deletions

View file

@ -7,6 +7,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType
@ -73,6 +74,18 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
return await hub.async_reset()
async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
) -> bool:
"""Remove config entry from a device."""
hub: UnifiHub = hass.data[UNIFI_DOMAIN][config_entry.entry_id]
return not any(
identifier
for _, identifier in device_entry.connections
if identifier in hub.api.clients or identifier in hub.api.devices
)
class UnifiWirelessClients:
"""Class to store clients known to be wireless.