IAS Zone `zone_state` cached as `Not_enrolled` (0) in appdb due to race with proactive `enroll_response`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
調査の方向性
Read zha/zigbee/cluster_handlers/security.py, especially IASZoneClusterHandler.async_configure() and the cluster_command handler, then trace how zone_state is initialized and persisted through AttributeReadEvent. Compare the timing of the proactive and device-initiated enrollment responses with the attribute read. Done means the post-enrollment zone_state is refreshed so a transient Not_enrolled value is not persisted as the lasting cached value.
索引モデルが issue の本文から書いたものです。
説明
Summary
The IAS Zone zone_state attribute (0x0000) is sometimes persisted as Not_enrolled (0) in the appdb / diagnostics dumps, even when the device is actually enrolled and reporting status normally. Because the cached value is reused on every restart (only_cache=True), the bad value sticks indefinitely.
Root cause
In IASZoneClusterHandler.async_configure() (zha/zigbee/cluster_handlers/security.py:361-400):
await self.bind()await self.write_attributes_safe({cie_addr: ieee})— per ZCL spec, writing CIE address can transition the device back toNot_enrolleduntil enrollment completesself._cluster.create_catching_task(self.enroll_response(...))— fire-and-forget, not awaited- Returns
Then async_initialize() runs, and zone_state (in ZCL_INIT_ATTRS with cached=True) is read from the device because the cache is empty (fresh pair) or wiped (re-interview). The read can race the proactive enroll_response, so the device returns 0 (Not_enrolled). That value is cached, persisted to appdb via AttributeReadEvent, and reused forever.
ZHA's cluster_command handler for the device-initiated enroll command (security.py:353-359) sends enroll_response but does not trigger a re-read of zone_state, so even when enrollment subsequently completes, the cached value isn't refreshed.
Why both fresh pair and re-interview are affected
- Fresh pair: Cache is empty → reads from device → race. After successful enrollment via the device's own
enrollcommand, no re-read happens, so the stale0persists in the appdb. - Re-interview: zigpy's
_device_reinterviewedcascade-deletes the old attribute cache, so the new shadow device starts with empty cache and goes through the same race. Worse, re-interview re-writescie_addron a device that was already enrolled, which on spec-compliant devices forces them back toNot_enrolleduntil the new enroll handshake completes — and the device usually doesn't initiate a newenrollafter re-interview, so the proactiveenroll_responseis the only path back. If the read beats it,0sticks again. - Restart:
async_initialize(from_cache=True)readszone_statecache-only, so a previously-bad value is never re-validated.
Note
ZHA itself doesn't consume zone_state for any entity — it's effectively diagnostics-only data, but it's misleading in dumps and bug reports.
Possible fixes
awaitthe enroll response task instead ofcreate_catching_task, then re-readzone_stateso the post-enroll value is what gets cached.- Re-read
zone_statein the response task itself — wrap the proactive enroll into a small helper that sends the response and then reads the attribute back. - Re-read
zone_stateincluster_commandwhen the device initiates anenroll, so even devices that take their time to sendenrollget a fresh value cached. - Drop
zone_statefromZCL_INIT_ATTRS— nothing in ZHA uses it, and on-demand reads would avoid persisting stale state.
Likely the cleanest is a combination of (2) and (3): always re-read after replying with enroll_response.
- 主要言語
- Python
- スター
- 96
- フォーク
- 84
- 平均マージ
- 3日 1時間
- マージ済み PR(30日)
- 13
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
zigpy/zha のほかの issue
-
Analog output numbers and analog input sensors show eleven BACnet engineering units as a different unit対応中かも @zigpy-review-bot が 3 日前に担当しました。 オープンbot: code audit
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
device specific quirks
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
entities
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
quirks
難易度 3/5 半日 初心者へのやさしさ 58/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
separate_packages splits imports from the same explicitly configured package対応中かも @rahul05ranjan が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
TigreGotico/text2spoken#626 ·
メンテナーはふだん 1 日以内に返信
-
oncoref MappingProxyType in proteome.layers breaks deepcopy in reference_coverage._inventory対応中かも @iskandr が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pipecat-ai/pipecat#7014 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NL-BioImaging/biomero#136 ·
メンテナーはふだん 1 日以内に返信