sec_touch: research multiple listeners per property ID / duplicate poll IDs

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
embedded-iot

Direzione di ricerca

Read components/sec_touch/sec_touch.h and components/sec_touch/sec_touch.cpp, especially the listener maps and register_* functions, then trace the example registration in components/sec_touch/switch/sec_touch_summer_ventilation_switch.cpp. Compare the proposed options for duplicate listeners and poll IDs, including RAM and flash costs and whether register_fan needs the same rule. Done means choosing and implementing a consistent policy, with duplicates handled as intended.

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

Descrizione

question

Problem

Property listeners in sec_touch hold one callback per property ID, and registration does not de-duplicate the poll ID lists.

  • The listener maps are std::map<int, UpdateCallbackListener>: recursive_update_listeners and manual_update_listeners (sec_touch.h#L78-L84). PR #20 adds a third one, string_update_listeners (std::map<int, StringUpdateCallbackListener>), with the same pattern.
  • Each register_* function (sec_touch.cpp#L295-L311, plus register_global_setting_string_listener in PR #20) does map[property_id] = std::move(listener) and then push_back(property_id) onto fan_level_property_ids_, fan_label_property_ids_ or global_setting_property_ids_.

When two entities register for the same property ID:

  1. The second listener silently replaces the first. The first entity never gets updates.
  2. The ID appears twice in the poll list, so it is requested twice per update cycle.

An int listener and a string listener on the same ID live in separate maps, so both fire. That is intended and not part of this issue.

This is a pre-existing pattern on main, not something PR #20 introduced. It came up while reviewing that PR.

Reproduction

switch:
  - platform: sec_touch
    name: "Summer ventilation A"
  - platform: sec_touch
    name: "Summer ventilation B"

Both switches register SUMMER_VENTILATION_PROPERTY_ID via register_global_setting_recursive_listener (sec_touch_summer_ventilation_switch.cpp#L17). Only "B" gets state updates, and the ID is polled twice. With PR #20, two sensor: - platform: sec_touch entries that each set clock_drift hit the same issue on the date/clock IDs.

Open questions

  • Is more than one entity per property ID a realistic use case at all (for example a second entity with different filters or a different name), or is it always a config mistake?
  • Which option fits?
    • Multiple listeners per ID: std::multimap or std::map<int, std::vector<Listener>>, plus de-duplicated ID lists.
    • De-duplicate the ID lists only: fixes the double poll but keeps last-wins listeners.
    • Reject duplicates in Python config validation with a clear error. This fails at compile time and needs no runtime cost.
    • Log a warning on re-registration: the cheapest change, but it only shows up in the device logs.
  • What does each option cost in ESP RAM and flash? A vector per map entry adds heap allocations per property. Today's configs have a small, fixed number of IDs.
  • Should the same rule apply to register_fan / fans_ (also keyed by level ID)?
Lingua principale
C++
Stelle
8
Fork
4
Merge medio
15h 58m
PR unite (30g)
5

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 distante/esphome-components

Tutte le issue di distante/esphome-components

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.