Commit Graph
389 Commits
Author SHA1 Message Date
J. Nick Koston 6abb9fd815 Merge remote-tracking branch 'upstream/decouple_scheduler_loop_cadence' into integration
# Conflicts:
#	esphome/core/application.h
2026-04-18 07:12:36 -05:00
J. Nick Koston 43d98cb445 Merge remote-tracking branch 'upstream/dev' into decouple_scheduler_loop_cadence
# Conflicts:
#	esphome/core/scheduler.cpp
2026-04-17 09:33:59 -05:00
J. Nick Koston 162bd415ce Merge remote-tracking branch 'upstream/fix-delay-action-mutable-lambda' into integration 2026-04-17 08:36:08 -05:00
J. Nick Koston 523c6f2376 [core] coerce set_interval(0) / update_interval: 0ms to 1ms (#15799) 2026-04-17 02:45:50 -10:00
J. Nick Koston a0ac226e6c [core] decouple main loop cadence from scheduler wake timing
Restructures Application::loop() into two independent phases to stop the
scheduler from silently pulling the component loop cadence forward.

Before: Application::loop() bounded its sleep by
  min(loop_interval_ - elapsed, next_schedule_in())
with a delay_time/2 floor. Any scheduler item due sooner than
loop_interval_/2 dragged the whole component phase with it. On a typical
ESP32 config with default loop_interval_=16ms, combined scheduler
activity from api / esp32_ble / esp32_ble_tracker / debug was keeping
every component's loop() running at ~128 Hz instead of the documented
~62 Hz.

This has become more visible recently as more components convert to
PollingComponent (which uses set_interval internally) and more in-tree
code uses set_interval / set_timeout directly. Adding or removing any
scheduled item silently changed every other component's loop cadence.
App.set_loop_interval() for power savings was also silently defeated.

After:
- Phase A (every tick): drain wake notifications, run scheduler.call(),
  feed WDT
- Phase B (gated by loop_interval_ or HighFrequencyLoopRequester):
  iterate registered components and update last_loop_

Sleep = min(time-until-next-component-phase, next_schedule_in()). When
a scheduler event wakes us early, Phase A services it and the component
phase stays gated independently. loop_interval_ is now a true minimum
interval between component phases.

The delay_time/2 floor is removed. Any legitimate need to wake faster
than loop_interval_ has proper mechanisms:
- HighFrequencyLoopRequester for sustained fast-loop needs
- Application::wake_loop_threadsafe() from any context (new in 2026.4.0)
  for one-shot wake-on-event

Also guards against set_interval(0) misuse — it asks the main loop to
spin forever, which was never the intended API. Warns at creation time
pointing authors at HighFrequencyLoopRequester. set_timeout(0)/defer()
is unaffected; zero-delay one-shots remain legitimate.

Runtime stats: process_pending_stats is now called on every tick (not
just when the component phase runs) so log_interval_ isn't quantized to
the component-phase cadence. Added an inline fast-path gate in
runtime_stats.h that early-outs unless now >= next_log_time_, keeping
Application::loop() slim; the log_stats_ work stays out-of-line.

Ordering constraints preserved:
- defer() callbacks still FIFO before components same-tick (Phase A
  runs before Phase B)
- Scheduled items still execute before components when both due
- Scheduled callbacks still run on main thread only
- loop_component_start_time_ is still set fresh at each component's loop
- WDT is still fed at least once per tick
2026-04-16 14:27:39 -10:00
J. Nick Koston b232fc91ab [runtime_stats] Track main loop active time and report overhead (#15743) 2026-04-16 14:07:26 -10:00
J. Nick Koston 21e6498ee2 Merge remote-tracking branch 'upstream/runtime-stats-loop-overhead' into integration 2026-04-14 16:34:42 -10:00
J. Nick Koston 2f14912196 [runtime_stats] Widen iteration counters, fix overhead total, test main_loop line
- Widen period/total iteration counters to uint64_t to avoid wrapping on
  long-running high-frequency loops.
- Compute total component-time sum over all components (not just the
  period-active subset) so total overhead is not inflated by components
  that ran earlier but are idle now.
- Extend integration test to parse the main_loop line and validate the
  iters/active_avg/active_total/overhead_total fields.
2026-04-14 16:33:39 -10:00
J. Nick Koston e48c7165c5 [light] Avoid addressable transition stall at low gamma-corrected values (#15726) 2026-04-15 07:45:42 +12:00
J. Nick Koston da9fbb8044 [core] Fix app_state_ status bits clobbered for non-looping components (#15658) 2026-04-14 07:50:11 -10:00
J. Nick Koston 651e37dcdc Merge branch 'light-addressable-gamma-transition-stall' into integration 2026-04-13 22:57:50 -10:00
J. Nick Koston 111e2cc9ed cleanups 2026-04-13 22:56:32 -10:00
J. Nick Koston 4696d70b8a Merge remote-tracking branch 'origin/light-addressable-gamma-transition-stall' into integration 2026-04-13 15:04:07 -10:00
J. Nick Koston b324630f8e [light] Type-annotate to_code in mock_addressable_light 2026-04-13 14:56:02 -10:00
J. Nick Koston 8da24fd1d9 [light] Use existing integration test helpers in transition test 2026-04-13 14:54:39 -10:00
J. Nick Koston 32130e1cb1 [light] Address Copilot review feedback on PR #15726
- mock_addressable_light.h: add direct <memory>/<cstdint>/<cstddef> includes
- test: use asyncio.get_running_loop() instead of deprecated get_event_loop()
- test: rebase timing to command-issue time (not first-nonzero) and use
  absolute progress for assertion 2, so late-transition check can't skew
  when the first nonzero sample happens to land near the assertion-1 limit
2026-04-13 14:53:17 -10:00
J. Nick Koston 3f56e0255a [light] Avoid addressable transition stall at low gamma-corrected values
When a uniform-colored addressable strip transitions from one color to
another, interpolate math-only against a cached start color instead of
reading each LED's current value back through the 8-bit stored byte.

The old algorithm used led.get_red()/etc. every step as the source for
the delta, which round-tripped through gamma uncorrect/correct and the
8-bit stored byte. At gamma 2.8, any pre-gamma value below ~27 rounds
to stored byte 0, so small early-transition steps produced stored 0 and
the next step read back 0, stalling progress until ~90% of the transition
before a single step produced a large-enough pre-gamma value to clear
the gamma threshold. Result: dark for the first 9s of a 10s fade, then
jump on in the final 1s.

Detect uniform start state in start() and take a cheap math-only lerp
path when true, so the stored byte advances through each gamma threshold
as smoothed_progress crosses it. Falls back to the existing per-LED
read-back algorithm when the buffer is non-uniform (e.g. when
transitioning out of an addressable effect).
2026-04-13 14:17:21 -10:00
J. Nick Koston 8800c10181 [core] Address review: fix docstrings per Copilot feedback
- get_app_state(): say 'STATUS_LED_* only', not 'STATUS_LED_* and lifecycle'
  since lifecycle bits are no longer maintained in app_state_.
- STATUS_LED_SETTLE_S: remove incorrect mention of feed_wdt re-dispatch;
  status_led_light is driven by the main loop, not feed_wdt.
- snapshot_led service: say 'status_led_light output' not 'pin state'
  since the fixture uses a template output, not GPIO.
2026-04-11 17:37:59 -10:00
J. Nick Koston 79f27d7a19 Merge branch 'drop-redundant-app-state-or' into integration 2026-04-11 16:39:14 -10:00
J. Nick Koston 515ec544ce [tests] Extract STATUS_LED_SETTLE_S constant, fix idle count check
Extract the 0.3s magic sleep into a named constant explaining why that
duration is chosen (feed_wdt re-dispatches every ~3 ms; 300 ms gives
~100 opportunities). Fix the idle-write check to snapshot AFTER the
clear instead of before it, so writes still in-flight from the error
phase don't inflate the delta.
2026-04-11 16:32:15 -10:00
J. Nick Koston 542b1fc7f3 [tests] Add set→clear→re-set round-trip check for status_led
Verifies that after clearing all status flags, re-setting a flag makes
status_led_light resume writing to its output. Guards against a future
idle optimization (like #15642) where status_led disables its own
loop() when idle: if the re-enable path were broken, the second set
would not produce writes.

Also checks that writes STOP after all flags are cleared (counter
should not keep growing), proving status_led_light correctly stops
blinking in steady state.
2026-04-11 16:28:54 -10:00
J. Nick Koston 424f1c7b0a [core] Rename any_component_has_status_flag and add integration tests
Drop the trailing underscore from any_component_has_status_flag now
that the method is public. Trailing underscores in the codebase are
reserved for protected/private members per clang-tidy naming rules,
which caused a CI failure on the previously-named public helper.

Add integration tests covering:
- Single-component status_set/clear for warning and error
- Multi-component OR semantics (both clear orders)
- Warning and error independence
- End-to-end proof that status_led_light::loop() reads App.app_state_
  and writes its output when the bits are set (via a fake template
  output whose write_action bumps a counter exposed as a sensor)
2026-04-11 16:20:05 -10:00
J. Nick Koston 8e02d0a20e [fan] Store preset mode vector on Fan entity to eliminate heap allocation (#15209) 2026-04-09 10:25:37 +12:00
J. Nick Koston faa05031a7 [climate] Store custom mode vectors on Climate entity to eliminate heap allocation (#15206) 2026-04-09 10:25:29 +12:00
J. Nick Koston 5d31f4aeba [light] Use function-pointer fields in LightControlAction (#15132) 2026-04-07 12:00:17 -10:00
J. Nick Koston cf78b035be Merge remote-tracking branch 'upstream/dev' into integration 2026-04-07 08:53:34 -10:00
J. Nick Koston 674d030cbb [core] Reschedule fired intervals directly into heap (#15516) 2026-04-07 07:36:55 -10:00
J. Nick Koston 9d43ed77c6 Merge remote-tracking branch 'origin/scheduler-interval-direct-heap' into integration 2026-04-06 20:58:44 -10:00
J. Nick Koston cf704b6b91 Address review: remove unused global, fix assertion messages 2026-04-06 20:54:01 -10:00
J. Nick Koston c79e7f4018 [core] Reschedule fired intervals directly into heap instead of to_add_
When an interval fires in Scheduler::call(), push it directly back into
items_ via push_back() + push_heap() instead of routing through the
to_add_ staging vector and process_to_add_slow_path_().

This eliminates per-cycle overhead of process_to_add_slow_path_() which
acquires a lock, iterates to_add_, pushes each item into the heap, clears
the vector, and resets the atomic counter.
2026-04-06 20:37:04 -10:00
J. Nick Koston d0b3cdebdb Merge remote-tracking branch 'upstream/fan-store-preset-modes-on-entity' into integration 2026-04-06 19:19:34 -10:00
J. Nick Koston e3d95817a1 Merge remote-tracking branch 'upstream/climate-store-custom-modes-on-entity' into integration 2026-04-06 19:18:58 -10:00
J. Nick Koston 60b5893ec7 Merge branch 'dev' into climate-store-custom-modes-on-entity 2026-04-06 18:46:43 -10:00
J. Nick Koston 6db21ec054 Merge branch 'dev' into fan-store-preset-modes-on-entity 2026-04-06 18:46:32 -10:00
J. Nick Koston 945a6b1063 Merge remote-tracking branch 'upstream/dev' into integration 2026-04-03 14:33:20 -10:00
Bonne EgglestonandJ. Nick Koston c6bb1fe141 [modbus] Add integration tests for server and server via controller (#14845)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
2026-04-03 20:24:02 +00:00
J. Nick Koston 6f4f852d8e Merge remote-tracking branch 'upstream/dev' into integration 2026-03-31 20:15:36 -10:00
J. Nick Koston 9b97e95cf3 [binary_sensor] Add on_multi_click integration test (#15329) 2026-03-31 07:42:12 -10:00
J. Nick Koston 85529ee518 Merge remote-tracking branch 'upstream/api/peel-first-write-iteration' into integration 2026-03-29 12:36:30 -10:00
J. Nick Koston 584807b039 [ld2410] Fix flaky integration test race condition (#15299) 2026-03-29 11:58:03 -10:00
J. Nick Koston fc1d590186 Merge remote-tracking branch 'upstream/dev' into integration 2026-03-27 11:24:23 -10:00
J. Nick Koston f5cd1e5e76 [ld2450] Fix flaky integration test race condition (#15226) 2026-03-27 08:23:26 -10:00
J. Nick Koston 05a5c27b90 Add 2026.11.0 removal comments to integration test and fixture 2026-03-26 16:21:30 -10:00
J. Nick Koston 592371f9f6 Add 2026.11.0 removal comments to integration test and fixture 2026-03-26 16:20:32 -10:00
J. Nick Koston b5df9de79b Remove unnecessary get_setup_priority from test fixture 2026-03-26 16:08:08 -10:00
J. Nick Koston 541ab9abf9 Fix fan test: use fan_schema(), remove unnecessary get_setup_priority 2026-03-26 16:07:20 -10:00
J. Nick Koston a3f5458ae3 Fix unused services variable in test 2026-03-26 15:54:54 -10:00
J. Nick Koston 3388d420ec Fix unused services variable in test 2026-03-26 15:42:36 -10:00
J. Nick Koston 317db8438c Move set_supported_custom_* out of traits() hot path
- Midea: frost protection preset now set once in on_status_change()
  when autoconf completes, guarded by a flag
- BedJet: custom fan modes and presets moved from traits() to setup()
- Test fixture: use has_custom_fan_mode() instead of nullptr check
2026-03-26 15:36:56 -10:00
J. Nick Koston 95cdc90835 Fix to_code signature: add ConfigType annotation 2026-03-26 15:27:20 -10:00