Detect duplicate entities in discovery and log unique ID collisions

Aperta
#979 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Start with default entity discovery and Device._add_pending_entities in zha/zigbee/device.py; trace how input and output clusters produce entities with the same (platform, unique_id) and how the pending path handles them. Add coverage for duplicate discovery and for logging when a distinct entity is dropped, then verify discovery yields one entity and the collision log names both. The issue does not identify the relevant test files, so locate existing discovery and device entity tests first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

entities
Summary

Follow-up from zigpy/zha-device-handlers#5410, where duplicate entity detection and unique ID collisions were left for ZHA to fix. ZHA's default discovery can yield the same entity more than once. _add_pending_entities then keeps the first entity for each (platform, unique_id) and drops the rest without logging anything. Discovery should not yield duplicates, and a real collision should be logged.

Problem
  • A cluster that is both an input and an output cluster on an endpoint makes default discovery yield two entity objects with the same platform and unique ID. Seen on the NodOn SIN-4-RS-20 cover and the TS0041A switch snapshots.
  • Device._add_pending_entities (zha/zigbee/device.py, "Ignore entities that already exist") drops a later entity whose key is already taken, with no log. _add_entity raises on the same condition, but the pending path never reaches it.
  • The same silent drop hides quirk mistakes. Two .adds_entity() calls with the same ZCL class on one endpoint and no unique_id_suffix both get {ieee}-{endpoint}. An added ZCL entity without a suffix can also collide with a default light, switch or cover, which use the same {ieee}-{endpoint} form. In both cases only the first entity is created, with nothing in the log.
Effect on zha-quirks

QuirkV2Device._replace_entities (zhaquirks/builder/device.py) works around the duplicates: it matches on distinct (PLATFORM, unique_id) and replaces only the first copy. The second copy keeps the original class and still contributes its cluster configuration. If the replacement then fails its support check, ZHA adds that leftover copy, so the original entity comes back, while a single matching entity would produce no entity at all (the open review threads on device.py in zigpy/zha-device-handlers#5410). A replacement class on a different platform keeps the unique ID but not the (platform, unique_id) key, so the leftover copy is added next to the replacement. Once discovery no longer yields duplicates, all of this goes away without a quirks change.

Proposed fix
  • Don't yield an entity twice from default discovery, so QuirkV2Device and other consumers see each entity once.
  • In _add_pending_entities, log when a different entity is dropped because its (platform, unique_id) is already taken, naming both entities.
  • Optional, on the quirks side: reject colliding .adds_entity() calls when the quirk is built. In zigpy/zha-device-handlers#5410 puddly called that nice to have, not needed for a first pass.
Related
  • is_supported_in_list is the other implicit deduplication: IdentifyButton uses it to keep one identify button per device. puddly's fork branch puddly/drop-is-supported-in-list (no PR yet) removes is_supported_in_list and makes the identify button a single device-level entity. It does not touch the input/output cluster duplicates.
  • zigpy/zha#725 (entity discovery issues) has an is_supported_in_list item that this branch would also settle.
Lingua principale
Python
Stelle
96
Fork
84
Merge medio
3g 1h
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di zigpy/zha

Tutte le issue di zigpy/zha

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.