Remove homekit_controller entity registry entries when backing char or service is gone (#109952)
This commit is contained in:
parent
122ac059bc
commit
4f404881dd
5 changed files with 108 additions and 0 deletions
|
@ -11,6 +11,31 @@ from homeassistant.core import Event, HomeAssistant
|
|||
from .const import CONTROLLER
|
||||
from .storage import async_get_entity_storage
|
||||
|
||||
IidTuple = tuple[int, int | None, int | None]
|
||||
|
||||
|
||||
def unique_id_to_iids(unique_id: str) -> IidTuple | None:
|
||||
"""Convert a unique_id to a tuple of accessory id, service iid and characteristic iid.
|
||||
|
||||
Depending on the field in the accessory map that is referenced, some of these may be None.
|
||||
|
||||
Returns None if this unique_id doesn't follow the homekit_controller scheme and is invalid.
|
||||
"""
|
||||
try:
|
||||
match unique_id.split("_"):
|
||||
case (unique_id, aid, sid, cid):
|
||||
return (int(aid), int(sid), int(cid))
|
||||
case (unique_id, aid, sid):
|
||||
return (int(aid), int(sid), None)
|
||||
case (unique_id, aid):
|
||||
return (int(aid), None, None)
|
||||
except ValueError:
|
||||
# One of the int conversions failed - this can't be a valid homekit_controller unique id
|
||||
# Fall through and return None
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@lru_cache
|
||||
def folded_name(name: str) -> str:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue