Add support for async_remove_config_entry_device to lutron_caseta (#73382)
parent
f732c51600
commit
a05c539abe
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
|
from itertools import chain
|
||||||
import logging
|
import logging
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ from .device_trigger import (
|
||||||
DEVICE_TYPE_SUBTYPE_MAP_TO_LIP,
|
DEVICE_TYPE_SUBTYPE_MAP_TO_LIP,
|
||||||
LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP,
|
LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP,
|
||||||
)
|
)
|
||||||
|
from .util import serial_to_unique_id
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -358,3 +360,41 @@ class LutronCasetaDeviceUpdatableEntity(LutronCasetaDevice):
|
||||||
"""Update when forcing a refresh of the device."""
|
"""Update when forcing a refresh of the device."""
|
||||||
self._device = self._smartbridge.get_device_by_id(self.device_id)
|
self._device = self._smartbridge.get_device_by_id(self.device_id)
|
||||||
_LOGGER.debug(self._device)
|
_LOGGER.debug(self._device)
|
||||||
|
|
||||||
|
|
||||||
|
def _id_to_identifier(lutron_id: str) -> None:
|
||||||
|
"""Convert a lutron caseta identifier to a device identifier."""
|
||||||
|
return (DOMAIN, lutron_id)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_remove_config_entry_device(
|
||||||
|
hass: HomeAssistant, entry: config_entries.ConfigEntry, device_entry: dr.DeviceEntry
|
||||||
|
) -> bool:
|
||||||
|
"""Remove lutron_caseta config entry from a device."""
|
||||||
|
bridge: Smartbridge = hass.data[DOMAIN][entry.entry_id][BRIDGE_LEAP]
|
||||||
|
devices = bridge.get_devices()
|
||||||
|
buttons = bridge.buttons
|
||||||
|
occupancy_groups = bridge.occupancy_groups
|
||||||
|
bridge_device = devices[BRIDGE_DEVICE_ID]
|
||||||
|
bridge_unique_id = serial_to_unique_id(bridge_device["serial"])
|
||||||
|
all_identifiers: set[tuple[str, str]] = {
|
||||||
|
# Base bridge
|
||||||
|
_id_to_identifier(bridge_unique_id),
|
||||||
|
# Motion sensors and occupancy groups
|
||||||
|
*(
|
||||||
|
_id_to_identifier(
|
||||||
|
f"occupancygroup_{bridge_unique_id}_{device['occupancy_group_id']}"
|
||||||
|
)
|
||||||
|
for device in occupancy_groups.values()
|
||||||
|
),
|
||||||
|
# Button devices such as pico remotes and all other devices
|
||||||
|
*(
|
||||||
|
_id_to_identifier(device["serial"])
|
||||||
|
for device in chain(devices.values(), buttons.values())
|
||||||
|
),
|
||||||
|
}
|
||||||
|
return not any(
|
||||||
|
identifier
|
||||||
|
for identifier in device_entry.identifiers
|
||||||
|
if identifier in all_identifiers
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue