Skip to content

Add an optional compare mask to UARTEx state_debounce - #380

Merged
eigger merged 2 commits into
masterfrom
uartex-state-debounce-mask
Nov 24, 2026
Merged

eigger merged 2 commits into
masterfrom
uartex-state-debounce-mask

Conversation

@eigger

@eigger eigger commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #379 (refs #378). state_debounce can now compare only selected bits, so values that change often in the same packet (e.g. current temperature) are not delayed.

state_debounce: 2s          # unchanged: whole packet compared

state_debounce:             # when other values in the packet are delayed
  delay: 2s
  offset: 2                 # payload offset, same as `state`
  mask: [0xFF, 0xFF]        # only these bits are compared

Behaviour

  • Masked part equal to the last applied state → packet applied immediately (cancels any pending change); unmasked bytes update without delay.
  • Masked part changed → held for delay, then the latest whole packet is applied; post-command bypass uses the same masked comparison.
  • Out of range: byte present in only one packet = different, missing in both = equal.
  • mask is required in the dict form; delay: 0s with a mask is ignored; max 60s; state still required.
  • packet_validation warns when offset + len(mask) exceeds every fixed-frame payload length.

Tests

  • Native: masked-equal immediate apply, masked-different pending/latest wins, glitch revert, bypass with mask (one-shot), out-of-range, mask covering state_on/off byte — run.sh passes.
  • tests/components/uartex/common.yaml now validates both forms (climate 2s, switch dict form); esphome config / compile --only-generate pass; negative schema checks rejected as expected.
  • Not tested on hardware.

🤖 Generated with Claude Code

eigger and others added 2 commits November 24, 2026 12:14
state_debounce now also accepts {delay, offset, mask}. Only the masked
bits are compared with the last applied state: when they are unchanged
the packet is applied immediately, so other values in the same packet
(e.g. current temperature) are not delayed. The plain time form keeps
comparing whole packets.

Refs #378

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Distinguish a mask entirely outside the payload from a partial overlap,
skip the check when debounce is disabled, and cover it with unit tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eigger
eigger merged commit 7e54364 into master Nov 24, 2026
17 checks passed
@eigger
eigger deleted the uartex-state-debounce-mask branch November 24, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant