Teach homekit about entity registry ids in device triggers (#95009)

pull/94995/head^2
Erik Montnemery 2023-06-21 23:28:43 +02:00 committed by GitHub
parent 235f50a341
commit f10256169b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -47,10 +47,12 @@ class DeviceTriggerAccessory(HomeAccessory):
type_: str = trigger["type"] type_: str = trigger["type"]
subtype: str | None = trigger.get("subtype") subtype: str | None = trigger.get("subtype")
unique_id = f'{type_}-{subtype or ""}' unique_id = f'{type_}-{subtype or ""}'
if (entity_id := trigger.get("entity_id")) and ( entity_id: str | None = None
entry := ent_reg.async_get(entity_id) if (entity_id_or_uuid := trigger.get("entity_id")) and (
entry := ent_reg.async_get(entity_id_or_uuid)
): ):
unique_id += f"-entity_unique_id:{get_system_unique_id(entry)}" unique_id += f"-entity_unique_id:{get_system_unique_id(entry)}"
entity_id = entry.entity_id
trigger_name_parts = [] trigger_name_parts = []
if entity_id and (state := self.hass.states.get(entity_id)): if entity_id and (state := self.hass.states.get(entity_id)):
trigger_name_parts.append(state.name) trigger_name_parts.append(state.name)