From 12b55f176fb4f7b3a99d765087de3412048b3680 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 13 Apr 2026 14:56:48 -1000 Subject: [PATCH] [light] Clearer uniformity scan + note edge case in uniform path --- esphome/components/light/addressable_light.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/esphome/components/light/addressable_light.cpp b/esphome/components/light/addressable_light.cpp index f52f27c63d3..5f5f123fe70 100644 --- a/esphome/components/light/addressable_light.cpp +++ b/esphome/components/light/addressable_light.cpp @@ -66,11 +66,15 @@ void AddressableLightTransformer::start() { this->uniform_start_color_.reset(); if (this->light_.size() > 0) { Color first = this->light_[0].get(); + bool uniform = true; for (int32_t i = 1; i < this->light_.size(); i++) { - if (this->light_[i].get() != first) - return; + if (this->light_[i].get() != first) { + uniform = false; + break; + } } - this->uniform_start_color_ = first; + if (uniform) + this->uniform_start_color_ = first; } } @@ -115,6 +119,11 @@ optional AddressableLightTransformer::apply() { // All LEDs started at the same color: compute the interpolated value once and write it to // every LED. No read-back, so each LED's stored byte advances through every gamma threshold // as smoothed_progress crosses it, instead of stalling at 0 for low pre-gamma values. + // + // Trade-off: any mid-transition writes to individual LEDs (e.g. from a user lambda) will be + // overwritten on the next apply() here. The fallback path below would have respected them + // via its read-back. Concurrent per-LED mutation during a transition isn't a pattern we + // support, so this is acceptable. // lerp(start, target, progress) via existing helper: target - (target-start)*(1-progress). const Color &start = *this->uniform_start_color_; int32_t remaining = int32_t(256.f * (1.f - smoothed_progress));