Skip to content

Make UARTEx optimistic default true and honor optimistic: false - #383

Merged
eigger merged 2 commits into
masterfrom
uartex-optimistic-default
Nov 26, 2026
Merged

eigger merged 2 commits into
masterfrom
uartex-optimistic-default

Conversation

@eigger

@eigger eigger commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Fixes #382

Problem

Each entity's control() used enqueue_tx_cmd(cmd) || optimistic_. enqueue_tx_cmd() returns true as soon as the command is queued, so optimistic: false (the old default) still reflected the request immediately. A periodic wallpad packet that arrived between control() and the actual TX then reverted the state (27 → 15 → 27).

Change

  • optimistic now defaults to true. The request is reflected immediately, with or without a command. This matches ESPHome template entities and suits UART latency.
  • optimistic: false queues the command and updates state only from received state packets, so there is no bounce.
  • The option is accepted only on controllable platforms: switch, climate, cover, fan, lock, media_player, number, select, text, valve and water_heater. It is rejected on light, sensor, binary_sensor, text_sensor and button.
  • climate: when the mode command lambda already carried the target temperature, no second temperature command is sent, even with optimistic: false.
  • select: restore_value now also saves on feedback. control() saves only when the value is reflected.
  • light: the internal dedupe fields always follow ESPHome's light state, so feedback can also correct lights that have no command.
  • Rejections: new UARTExDevice::enqueue_and_reflect() reflects only when optimistic and the command is not configured or produced data. This keeps the wallpad packages' empty-lambda rejections working (fixes the cvnet regression test).
  • media_player: comment explaining why muted_ is updated regardless of optimistic.
  • Docs (README EN/KO, PACKET_GUIDE): updated.

Breaking changes

  • switch now reflects immediately by default. Set optimistic: false to wait for feedback (the behaviour since Fix UARTEx command handling and wallpad packet processing #370).
  • Requests with no command configured used to be ignored. They are now reflected under the default (virtual entity). Set optimistic: false to keep the old behaviour.
  • A command lambda that returns no data is treated as a rejection and is never reflected, even with optimistic: true. In climate, a rejected mode packet that read the target also rejects that target, and no separate temperature command is sent.
  • optimistic on light/sensor/binary_sensor/text_sensor/button now fails config validation. Remove the key.

Verification

  • Native suite tests/native/uartex_parser/run.sh (WSL g++, -Werror) passes. The switch tests were updated for the new default and the true/false cases. The suite compiles only the switch platform; the other platform .cpp files were not compiled.
  • esphome config (2026.7.4) reports valid for every tests/components/uartex fixture.
  • Schema probes: a switch without the key resolves to optimistic: true. optimistic on light or binary_sensor is rejected.
  • Python test_packet_validation.py: 12 tests OK.
  • Wallpad protocol regression tests (tests/packages/wallpad/protocol): 14 tests OK, including test_cvnet_combined_climate_calls.
  • esphome compile test.esp8266-ard.yaml succeeds. A cover entity was added to the fixture so CI compiles cover too.

Review notes

  • Reviewed by an independent reviewer until no must-fix items remained.
  • Optional suggestion not applied: the Korean README row omits two minor clauses present in the English one.
  • Pre-existing water_heater away/ON gating bugs and the missing valve has_value() check are left for a follow-up PR.

🤖 Generated with Claude Code

eigger and others added 2 commits November 26, 2026 17:41
control() used to reflect the requested state whenever enqueue_tx_cmd()
queued a command, so optimistic: false never waited for feedback and a
stale wallpad packet between control() and TX made the state bounce
(#382).

- optimistic now defaults to true and means: reflect the request
  immediately, with or without a command. optimistic: false queues the
  command and updates state only from received packets.
- The option is accepted only on controllable platforms (switch, climate,
  cover, fan, lock, media_player, number, select, text, valve,
  water_heater); light, sensor, binary_sensor, text_sensor and button
  reject it.
- climate: a mode command that carried the target temperature no longer
  triggers a second temperature command when optimistic is false.
- select: restore_value saves on feedback, and control() saves only when
  the value is reflected.
- light: internal dedupe fields always follow the light state, so
  feedback corrects lights without commands.
- Docs (EN/KO) and switch native tests updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A command lambda returning no data is how wallpad packages reject a
request. With optimistic now defaulting to true, rejected requests (and
the target temperature a rejected climate mode packet carried) were
reflected, failing the cvnet regression test.

- Add UARTExDevice::enqueue_and_reflect(): reflect only when optimistic
  and the command is either not configured (virtual entity) or produced
  data. Use it on every optimistic-gated control path.
- climate: a mode command that read the target never triggers a separate
  temperature command; mode/target are reflected only when accepted.
- Docs: clarify rejection, combined climate packets and optimistic: false.
- Tests: rejected-lambda switch case; cover entity in the ESPHome fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eigger
eigger merged commit 5b8a7df into master Nov 26, 2026
17 checks passed
@eigger
eigger deleted the uartex-optimistic-default branch November 26, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant