Fix ZHA group removal entity registry cleanup (#124889)

* Fix ZHA cleanup entity registry parameter

* Fix missing `gateway` when accessing coordinator device

* Get `ZHADeviceProxy` for coordinator device
This commit is contained in:
TheJulianJES 2024-08-30 02:13:47 +02:00 committed by GitHub
parent 175ffe29f6
commit 7eeebf198b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -802,21 +802,24 @@ class ZHAGatewayProxy(EventBase):
)
def _cleanup_group_entity_registry_entries(
self, zigpy_group: zigpy.group.Group
self, zha_group_proxy: ZHAGroupProxy
) -> None:
"""Remove entity registry entries for group entities when the groups are removed from HA."""
# first we collect the potential unique ids for entities that could be created from this group
possible_entity_unique_ids = [
f"{domain}_zha_group_0x{zigpy_group.group_id:04x}"
f"{domain}_zha_group_0x{zha_group_proxy.group.group_id:04x}"
for domain in GROUP_ENTITY_DOMAINS
]
# then we get all group entity entries tied to the coordinator
entity_registry = er.async_get(self.hass)
assert self.coordinator_zha_device
assert self.gateway.coordinator_zha_device
coordinator_proxy = self.device_proxies[
self.gateway.coordinator_zha_device.ieee
]
all_group_entity_entries = er.async_entries_for_device(
entity_registry,
self.coordinator_zha_device.device_id,
coordinator_proxy.device_id,
include_disabled_entities=True,
)