stop tracking dynamic bytes that are not buttons - #153
Merged
Conversation
AdvertisementTracker decoded all 11 bytes of the dynamic block as button
reports and emitted a transition whenever any of them changed. Only the
bytes a BinaryInputs packet claims are buttons; the rest belong to touch
controllers and sensors, and every one of them decodes into a valid-looking
button report. A moving touch coordinate or a refreshed sensor reading
therefore produced phantom button_down / button_up / press_count_changed /
button_slot_changed events.
On a reTerminal E1003 (button byte 0, touch 1-5, SHT40 7-9) a 0.1 C change
in the sensor reading was enough:
unfiltered: 1 event(s) [('button_slot_changed', 7)]
filtered : 0 event(s) []
AdvertisementTracker now accepts the byte indices it should watch. Home
Assistant filters incoming events by the configured byte_index before
firing an entity, which is why this was invisible there, but the events
were still produced on every advertisement and any other consumer would
have believed them.
Add BinaryInputs.published_button_byte_index so callers derive those
indices without re-implementing the firmware's rule that 0xFF (its default)
means "not published" and indices past the block are ignored:
AdvertisementTracker(
idx
for bi in config.binary_inputs
if (idx := bi.published_button_byte_index) is not None
)
The parameter is optional and defaults to watching every byte, so existing
callers are unaffected until they opt in.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AdvertisementTrackerdecodes all 11 bytes of the dynamic block as button reports and emits a transition whenever any of them changes.But only the bytes a
BinaryInputspacket claims are buttons. The rest belong to touch controllers and sensors — and because a button report is justbutton_id | press_count << 3 | pressed << 7, any byte decodes into a valid-looking one. So a moving touch coordinate or a refreshed sensor reading produces phantombutton_down/button_up/press_count_changed/button_slot_changedevents.On a reTerminal E1003 (button byte 0, touch 1–5, SHT40 7–9), a 0.1 °C change in the sensor reading is enough:
This is pre-existing and not caused by the SHT40 work in #152 — touch controllers have triggered it since
TouchTrackerlanded. Home Assistant filters incoming events by the configuredbyte_indexbefore firing an entity, which is why it has been invisible there, but the events were still produced on every advertisement and any other consumer would have believed them.Fix
AdvertisementTrackernow takes the byte indices it should watch:The parameter is optional and defaults to watching every byte, so existing callers are unaffected until they opt in — no breaking change, no major version bump.
BinaryInputs.published_button_byte_indexis added so callers don't re-implement the firmware's rule that0xFF(its default) means "not published", and that indices past the 11-byte block are ignored.AdvertisementData.button_eventsis left decoding every byte — it's the raw primitive — but its docstring now says so explicitly, since that is what made the tracker wrong.Verification
979 tests pass; ruff, ruff-format, mypy strict and pylint clean. New coverage:button_down+press_count_changedpublished_button_byte_indexfor0,10,0xFFand an out-of-range indexFollow-up
Home Assistant should pass the indices when constructing the tracker in
coordinator.py; until it does, behaviour there is unchanged. Worth doing in the same pass as the SHT40 sensor entities so it rides one manifest bump.