sec_touch: research multiple listeners per property ID / duplicate poll IDs
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Active
- Tech stack
- cpp
- Domain
- embedded-iot
Research direction
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.
Written by the indexing model from the issue text.
Description
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_listenersandmanual_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, plusregister_global_setting_string_listenerin PR #20) doesmap[property_id] = std::move(listener)and thenpush_back(property_id)ontofan_level_property_ids_,fan_label_property_ids_orglobal_setting_property_ids_.
When two entities register for the same property ID:
- The second listener silently replaces the first. The first entity never gets updates.
- 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::multimaporstd::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.
- Multiple listeners per ID:
- 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)?
- Dominant language
- C++
- Stars
- 8
- Forks
- 4
- Avg merge
- 15h 58m
- Merged PRs (30d)
- 5
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from distante/esphome-components
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Sniffer: hub message tap with raw strings and scan outcomePossibly taken @distante claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 53/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Sniffer: HTML pageOpen
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
All issues in distante/esphome-components
Similar issues
-
upstream-blocked
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ROCm/FastFlowLM#1057 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
NatronGitHub/openfx-gmic#45 ·
Maintainers usually reply within 1 day
-
app area::installer bug wg::gui-app
Difficulty 1/5 Under an hour Newbie friendliness 88/100
lemonade-sdk/lemonade#4186 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100