Removing a group member device leaves a stale group entity behind

オープン
#875 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
embedded-iot

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
96
フォーク
84
平均マージ
3日 1時間
マージ済み PR(30日)
13

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

zigpy/zha のほかの issue

zigpy/zha の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。