Skip to content

Fix brighness not being applied properly in nightlight mode#5625

Merged
DedeHai merged 5 commits into
wled:mainfrom
DedeHai:FixNightlighDimming
Jun 22, 2026
Merged

Fix brighness not being applied properly in nightlight mode#5625
DedeHai merged 5 commits into
wled:mainfrom
DedeHai:FixNightlighDimming

Conversation

@DedeHai

@DedeHai DedeHai commented May 17, 2026

Copy link
Copy Markdown
Collaborator

fix for #5620

Summary by CodeRabbit

  • Bug Fixes
    • Improved nightlight fade and colorfade behavior by temporarily pausing strip transitions during the fade, applying the interpolated color without notifications, then restoring the prior transition timing.
    • Fixed brightness finalization when transitions are inactive by clearing pending transition-related state and ensuring the final brightness is applied reliably after related updates complete.

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e513833-c5ad-41f6-a146-ba373e5c6ac2

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0fb88 and 578017a.

📒 Files selected for processing (1)
  • wled00/led.cpp

Walkthrough

This PR refactors how transitions and brightness are finalized in LED state updates. When no transition is active, stateUpdated() clears pending transition state and calls applyFinalBri() instead of directly triggering the strip. During nightlight color fading, handleNightlight() temporarily disables transitions while applying color updates, then restores the prior transition duration.

Changes

LED transition finalization refactor

Layer / File(s) Summary
Transition state management in state and nightlight updates
wled00/led.cpp
stateUpdated() clears jsonTransitionOnce and transitionActive and routes through applyFinalBri() instead of directly calling strip.trigger() when no transition is active; handleNightlight() snapshots the transition duration, sets it to 0, calls colorUpdated(CALL_MODE_NO_NOTIFY), and restores the saved duration to isolate fade operations from transition timing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

effect

Suggested reviewers

  • blazoncek
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main issue being fixed - brightness not being applied properly in nightlight mode, which matches the core changes in stateUpdated() and handleNightlight().
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
wled00/led.cpp

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.16][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
wled00/led.cpp (1)

234-235: 💤 Low value

Nightlight brightness fix is correct; minor optimization opportunity.

The applyFinalBri() call successfully prevents transitions from blocking brightness updates during nightlight fade. This fixes the reported issue where repeated colorUpdated() calls every 100ms would restart transitions, preventing bri from changing.

However, when strip.getTransition() == 0, stateUpdated() (called by colorUpdated()) already invokes applyFinalBri() at line 128, so line 235 results in a redundant second call. While harmless, you could optimize by guarding the call:

if (strip.getTransition() > 0) applyFinalBri();

This ensures the bypass only happens when transitions are enabled. Given the 100ms rate limit and nightlight-only scope, the current unconditional approach is acceptable and keeps the fix simple.

♻️ Optional optimization to avoid redundant call
 colorUpdated(CALL_MODE_NO_NOTIFY);
-applyFinalBri(); // colorUpdated() re-starts transition (if enabled) every 100ms, preventing brightness from changing correctly (fix for `#5620`)
+if (strip.getTransition() > 0) applyFinalBri(); // bypass transition restart to allow brightness updates (fix for `#5620`)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wled00/led.cpp` around lines 234 - 235, colorUpdated() followed by an
unconditional applyFinalBri() causes a redundant call when no transition is
active because stateUpdated() already calls applyFinalBri(); update the code
around colorUpdated(CALL_MODE_NO_NOTIFY) so you only call applyFinalBri() when a
transition is enabled (check strip.getTransition() > 0) to avoid the duplicate
call while preserving the nightlight fix; reference colorUpdated(),
applyFinalBri(), strip.getTransition(), and stateUpdated() when locating the
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@wled00/led.cpp`:
- Around line 234-235: colorUpdated() followed by an unconditional
applyFinalBri() causes a redundant call when no transition is active because
stateUpdated() already calls applyFinalBri(); update the code around
colorUpdated(CALL_MODE_NO_NOTIFY) so you only call applyFinalBri() when a
transition is enabled (check strip.getTransition() > 0) to avoid the duplicate
call while preserving the nightlight fix; reference colorUpdated(),
applyFinalBri(), strip.getTransition(), and stateUpdated() when locating the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 12f2b97d-bcac-40fd-922f-ae044ec9bc59

📥 Commits

Reviewing files that changed from the base of the PR and between 0a19027 and a8eb397.

📒 Files selected for processing (1)
  • wled00/led.cpp

@DedeHai DedeHai marked this pull request as draft May 20, 2026 06:24
@softhack007 softhack007 added this to the 16.0.0 release + bugfixes milestone Jun 9, 2026
@softhack007 softhack007 added the bug label Jun 9, 2026
@softhack007 softhack007 linked an issue Jun 19, 2026 that may be closed by this pull request
1 task
@DedeHai

DedeHai commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

in order to properly fix it, transitions should be disabled in nighlight mode. @blazoncek has fixed it but the change is complex and I did not yet fully work through that change to port it upstream.

@softhack007 softhack007 marked this pull request as ready for review June 20, 2026 18:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wled00/led.cpp`:
- Around line 234-237: The issue is that the code unconditionally restores the
saved transition duration after calling colorUpdated(), but that function can
trigger callbacks through UsermodManager::onStateChange() that might modify the
transition value. To fix this, only restore the saved transition duration if the
current transition value is still 0 when checked right before the
strip.setTransition(transitionduration) call, indicating no callback has changed
it. This ensures you do not overwrite intentional transition changes made during
the colorUpdated(CALL_MODE_NO_NOTIFY) call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6f3e0bc8-001d-4383-b47e-0e9d1a4b0cbd

📥 Commits

Reviewing files that changed from the base of the PR and between a8eb397 and 0b0fb88.

📒 Files selected for processing (1)
  • wled00/led.cpp

Comment thread wled00/led.cpp Outdated
Comment on lines +234 to +237
uint16_t transitionduration = strip.getTransition();
strip.setTransition(0); // temporary disable transition and set color & brightness directly, (fix for #5620)
colorUpdated(CALL_MODE_NO_NOTIFY);
strip.setTransition(transitionduration); // restore transition time to previous value. Note: this is a dirty hack and needs proper fix by disabling transitions completely in nightlight mode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid clobbering transition updates made during colorUpdated().

colorUpdated(CALL_MODE_NO_NOTIFY) flows into stateUpdated(), which calls UsermodManager::onStateChange(callMode). Unconditionally restoring the saved transition right after that can overwrite transition changes made in that callback path.

Suggested patch
-      uint16_t transitionduration = strip.getTransition();
+      const uint16_t previousTransition = strip.getTransition();
       strip.setTransition(0); // temporary disable transition and set color & brightness directly, (fix for `#5620`)
       colorUpdated(CALL_MODE_NO_NOTIFY);
-      strip.setTransition(transitionduration); // restore transition time to previous value. Note: this is a dirty hack and needs proper fix by disabling transitions completely in nightlight mode
+      // Restore only if no callback changed transition state during colorUpdated().
+      if (strip.getTransition() == 0) {
+        strip.setTransition(previousTransition);
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uint16_t transitionduration = strip.getTransition();
strip.setTransition(0); // temporary disable transition and set color & brightness directly, (fix for #5620)
colorUpdated(CALL_MODE_NO_NOTIFY);
strip.setTransition(transitionduration); // restore transition time to previous value. Note: this is a dirty hack and needs proper fix by disabling transitions completely in nightlight mode
const uint16_t previousTransition = strip.getTransition();
strip.setTransition(0); // temporary disable transition and set color & brightness directly, (fix for `#5620`)
colorUpdated(CALL_MODE_NO_NOTIFY);
// Restore only if no callback changed transition state during colorUpdated().
if (strip.getTransition() == 0) {
strip.setTransition(previousTransition);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wled00/led.cpp` around lines 234 - 237, The issue is that the code
unconditionally restores the saved transition duration after calling
colorUpdated(), but that function can trigger callbacks through
UsermodManager::onStateChange() that might modify the transition value. To fix
this, only restore the saved transition duration if the current transition value
is still 0 when checked right before the strip.setTransition(transitionduration)
call, indicating no callback has changed it. This ensures you do not overwrite
intentional transition changes made during the colorUpdated(CALL_MODE_NO_NOTIFY)
call.

@DedeHai

DedeHai commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

I changed this into a hack-fix which is good for now but needs proper rework of how nightlight mode works.
ready to merge for the bugfix release.

@DedeHai DedeHai merged commit 6afa4ec into wled:main Jun 22, 2026
25 of 26 checks passed
@DedeHai DedeHai deleted the FixNightlighDimming branch June 22, 2026 19:28
DedeHai added a commit that referenced this pull request Jun 22, 2026
* Fix brighness not being applied properly in nightlight mode
* hacky fix also for color fade, needs proper fix later
@DedeHai

DedeHai commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

cherry picked to 16_x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nightlight problem with brightness transitions (for small changes)

2 participants