Move Sonoff occupancy config entities to quirks, or expose the ultrasonic delay for all occupancy sensors

Aperta
#1,081 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
25/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

The entities are in zha/application/platforms/number/init.py (SonoffPresenceSenorTimeout, PIROccupiedToUnoccupiedDelayConfigurationEntity) and zha/application/platforms/select.py (SonoffPresenceDetectionSensitivity). Compare them with the SNZB-06P and SNZB-03P quirks in zhaquirks/sonoff/, then check which snapshots in tests/data/devices hold ultrasonic_o_to_u_delay. Done when the chosen option is agreed in the thread and the affected snapshot tests still pass.

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

Descrizione

entities quirks
Problem

ZHA creates the "presence detection timeout" number entity only for two Sonoff models. SonoffPresenceSenorTimeout is a ZHA-native entity on OccupancySensing.ultrasonic_o_to_u_delay (0x0020), matched by models=frozenset({"SNZB-06P", "SNZB-03P"}), range 15–60 s, unique ID {ieee}-1-1030-presence_detection_timeout. Its sibling SonoffPresenceDetectionSensitivity (ultrasonic_u_to_o_threshold, unique ID suffix detection_sensitivity) uses the same model match.

So device-specific config lives in the ZHA library, and quirks have to work around it. The SNZB-03P quirk in zigpy/zha-device-handlers#4628 imports SonoffPresenceSenorTimeout from zha.application.platforms.number and uses .replaces_entity() only to change the minimum to 5 s and add a unit and device class. Meanwhile any other sensor exposing ultrasonic_o_to_u_delay gets no entity for it, while the PIR equivalent, PIROccupiedToUnoccupiedDelayConfigurationEntity, matches every OccupancySensing server cluster (0–65535 s, created when the attribute is supported and cached).

Raised in zigpy/zha-device-handlers#4628 (review thread on zhaquirks/sonoff/snzb03p.py). We need to decide between two directions:

Option A: move it to quirks entirely
  • The SNZB-06P quirk (zhaquirks/sonoff/snzb06p.py) and the SNZB-03P quirk from zigpy/zha-device-handlers#4628 declare the timeout with .number(...) on ultrasonic_o_to_u_delay and the sensitivity with .enum(...) on ultrasonic_u_to_o_threshold, each with its own range.
  • Existing entity IDs are kept with unique_id_suffix="1030-presence_detection_timeout" and unique_id_suffix="1030-detection_sensitivity". v2 IDs don't include the cluster ID, so it has to be in the suffix.
  • After that quirks release, ZHA removes both Sonoff classes and SonoffPresenceDetectionSensitivityEnum. This is the same coupled order used for the Inovelli and STARKVIND moves: quirks first, then ZHA bumps its quirks pin and drops the classes.
  • The ZHA match is on the model string alone (eWeLink SNZB-03P, SONOFF SNZB-06P in the snapshots). Check that the quirks cover every manufacturer string that currently gets the entities.
Option B: a generic ultrasonic delay entity for all occupancy sensors
  • Add an UltrasonicOccupiedToUnoccupiedDelayConfigurationEntity to ZHA next to the PIR one: no model filter, 0–65535 s, duration device class, seconds. Optionally add the u→o delay too, like the PIR pair.
  • The Sonoff devices must not end up with both the generic and the Sonoff entity, and their existing unique ID (presence_detection_timeout) has to stay. Either the generic class takes over and keeps that suffix for those models, or the Sonoff-specific range moves to the quirks (Option A for the range only).
  • Other devices gain the entity. Of the current snapshots in tests/data/devices, ultrasonic_o_to_u_delay is supported and cached on sunricher-hk-dim-0x00000036 (value 0) and tze200-jva8ink8-ts0601 (value 600, a Tuya TS0601 whose occupancy cluster comes from the tuya_motion quirk). For the Tuya one, check whether a write reaches the device at all before exposing it there.
  • The sensitivity select stays Sonoff-specific. Its 1/2/3 enum is not a generic meaning of ultrasonic_u_to_o_threshold.
Either way

zigpy/zha-device-handlers#4628 imports SonoffPresenceSenorTimeout from ZHA. Removing or renaming that class breaks the quirk's import, so the quirk has to be updated in the same release step.

Lingua principale
Python
Stelle
96
Fork
84
Merge medio
2g 4h
PR unite (30g)
30

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.