Removing a group member device leaves a stale group entity behind

Abierto
#875 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
embedded-iot

Línea de trabajo

Start at Gateway.device_removed(), which pops the device from self._devices and schedules Device.on_remove() but never touches its groups. Compare it with the group_member_removed path, which already calls Group.clear_caches() and re-runs discover_group_entities(), and check that Group.members (a cached_property) is recomputed. Done means that after removing a group member device, Group.members reports the remaining count, the group entity is removed once fewer than two members remain, and the removed device's entity subscription is dropped.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Removing a member device from the network — as opposed to removing its endpoint from the group — leaves the group's entity fully stale: the group entity survives, Group.members keeps reporting the removed device, and the group holds a subscription to an entity that has already been torn down.

Why it happens

Gateway.device_removed() pops the device from self._devices and schedules Device.on_remove(), but it never touches the groups that device belonged to — it does not call Group.clear_caches() and it does not re-run discover_group_entities(). Nothing else does either: zigpy's ControllerApplication._remove_device() only does self.devices.pop(device.ieee, None) and does not remove the device's endpoints from its groups, so no group_member_removed event is emitted.

Group.members is a cached_property that filters on member_ieee in self._gateway.devices, so it would return the right answer if it were recomputed — but without clear_caches() it keeps the pre-removal value.

Reproduction

Create a two-light group, then remove one of the member devices:

gateway.devices:  2          # coordinator + the remaining light
group.members:    2          # stale cached_property, should be 1
group_entities:   ['light_zha_group_0x0002']            # should be gone (only one member left)
entity_unsubs:    ['light_zha_group_0x0002',
                   '01:2d:6f:00:0a:90:69:e8-1',
                   '02:2d:6f:00:0a:90:69:e8-1']         # 02:… is the removed device's entity

The group entity stays registered and functional, backed by a single member, and the subscription to the removed device's light entity keeps the torn-down entity object alive.

Relation to #849

#849 fixes the teardown paths that do emit events — a group dropping below two members, a single platform losing eligibility, and group removal. This one is a different entry point (Gateway.device_removed) and is deliberately out of scope there. A fix probably means, for each group the removed device belonged to, calling clear_caches() and re-running discover_group_entities() — which is exactly what group_member_removed already does.

Lenguaje dominante
Python
Estrellas
96
Forks
84
Merge medio
3 d 1 h
PR fusionados (30 d)
13

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de zigpy/zha

Todos los issues de zigpy/zha

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.