Skip to content

Add support for usermod palettes#2058

Merged
frenck merged 4 commits into
frenck:mainfrom
mik-laj:fix/wled-usermod-palettes
May 20, 2026
Merged

Add support for usermod palettes#2058
frenck merged 4 commits into
frenck:mainfrom
mik-laj:fix/wled-usermod-palettes

Conversation

@mik-laj
Copy link
Copy Markdown
Collaborator

@mik-laj mik-laj commented May 8, 2026

Proposed Changes

(Describe the changes and rationale behind them)

This PR adds support for synthesizing “usermod palettes” into the Device.palettes mapping based on firmware-reported counts/names. It follows custom palettes flow.

Related Issues

(GitHub link to related issues or pull requests)

Summary by CodeRabbit

  • New Features

    • Added support for usermod (user-created) palettes with automatic fallback naming on compatible firmware versions.
    • Extended palette management to properly synthesize and display usermod palette entries alongside built-in and custom palettes.
  • Tests

    • Added comprehensive test coverage for usermod palette behavior, including edge cases and version compatibility.

Review Change Stack

Copilot AI review requested due to automatic review settings May 8, 2026 19:30
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Warning

Rate limit exceeded

@mik-laj has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 10 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ef4ce1f-bbf0-4cae-a70d-024107460033

📥 Commits

Reviewing files that changed from the base of the PR and between cd217c6 and 6bc66ee.

📒 Files selected for processing (2)
  • tests/__snapshots__/test_models.ambr
  • tests/test_models.py
📝 Walkthrough

Walkthrough

This PR extends the WLED Python library to support usermod palettes, a firmware feature available in version 16.0.0 and later. The changes reorganize the palette ID space, extend the Info model to deserialize usermod metadata (count and optional names), implement a synthesis helper, integrate it into Device deserialization and updates, and add comprehensive test coverage for different firmware versions and edge cases.

Changes

Usermod Palette Support

Layer / File(s) Summary
Palette ID constants and Info model fields
src/wled/models.py
Defined WLED_USERMOD_PALETTE_ID_BASE (255), WLED_CUSTOM_PALETTE_ID_BASE (200), WLED_CUSTOM_PALETTE_ID_BASE_LEGACY (255), and derived WLED_USERMOD_PALETTE_MAX_COUNT. Extended Info dataclass with usermod_palette_count (alias umpalcount) and usermod_palette_names (alias umpalnames) fields.
Usermod palette builder implementation
src/wled/models.py
Added Device._build_usermod_palettes() static method that synthesizes usermod palette entries gated to firmware >= 16.0.0, generates palette IDs descending from WLED_USERMOD_PALETTE_ID_BASE, caps synthesis to WLED_USERMOD_PALETTE_MAX_COUNT, and produces fallback names when umpalnames is absent.
Device palette synthesis integration
src/wled/models.py
Updated Device.pre_deserialize and Device.update_from_dict to synthesize and incorporate usermod palettes alongside built-in and custom palettes, merging custom and usermod dictionaries during palette updates.
Usermod palette test coverage
tests/test_models.py
Added five test cases: correct inclusion on firmware 16.0.0, re-synthesis and persistence after update_from_dict, capping to maximum slot count, fallback naming when umpalnames is null, and skipping synthesis on pre-16.0.0 firmware.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • frenck/python-wled#1603: Prior custom palette synthesis in Device.pre_deserialize/update_from_dict that this PR extends with usermod palette support.
  • frenck/python-wled#2057: Refactors palette synthesis around firmware-versioned ID bases and usermod palette builders with matching test coverage for palette ID/name behavior.

Suggested reviewers

  • frenck

Poem

🐰 Palettes bloom like carrots in the garden,
Usermod friends arrive in version sixteen,
Built-in, custom, synthesized with care—
Each ID descends from two-fifty-five,
A rainbow of light, forever to thrive! 🎨✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add support for usermod palettes' is concise, clear, and directly summarizes the main change—adding usermod palette support to the Device model.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for synthesizing “usermod palettes” (and updated custom-palette ID behavior) into the Device.palettes mapping based on firmware-reported counts/names, and updates tests/snapshots accordingly.

Changes:

  • Add Info.usermod_palette_count / Info.usermod_palette_names and synthesize usermod palettes into Device.palettes.
  • Make custom palette IDs depend on a firmware version threshold (legacy 255-descending vs new 200-descending layout).
  • Expand unit tests and update snapshots to cover version-dependent palette IDs and usermod palettes.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.

File Description
src/wled/const.py Introduces the firmware version threshold constant for the custom-palette ID layout change.
src/wled/models.py Adds usermod palette fields on Info and synthesizes usermod/custom palette entries during deserialization and updates.
tests/test_models.py Adds/updates tests for version-dependent custom palette IDs and usermod palette synthesis/update behavior.
tests/__snapshots__/test_models.ambr Updates snapshots to include new Info fields (usermod_palette_count, usermod_palette_names).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wled/const.py
Comment thread src/wled/models.py
Comment thread src/wled/models.py
Comment thread src/wled/models.py Outdated
Comment thread tests/test_models.py
Comment thread tests/test_models.py
Comment thread tests/test_models.py
@mik-laj mik-laj force-pushed the fix/wled-usermod-palettes branch from 9eccbd6 to 58a0ad0 Compare May 8, 2026 21:13
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.34%. Comparing base (3e87d76) to head (6bc66ee).
⚠️ Report is 611 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2058       +/-   ##
===========================================
+ Coverage   58.61%   97.34%   +38.73%     
===========================================
  Files           6        8        +2     
  Lines         662     1131      +469     
  Branches      143      114       -29     
===========================================
+ Hits          388     1101      +713     
+ Misses        270       20      -250     
- Partials        4       10        +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mik-laj mik-laj added the new-feature New features or options. label May 8, 2026
Copilot AI review requested due to automatic review settings May 8, 2026 23:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/wled/models.py
Comment thread src/wled/models.py Outdated
Comment thread src/wled/models.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

@mik-laj mik-laj marked this pull request as ready for review May 9, 2026 01:14
mik-laj and others added 3 commits May 14, 2026 00:26
Fixes three issues identified in code review:

1. Bound umpalcount to 55 slots (reserved ID space 255-201) to prevent
   collision with custom palette IDs. Previously umpalcount > 55 would
   generate IDs <= 200 and silently overwrite custom palette entries.

2. Handle null umpalnames from JSON by normalizing to empty list before
   use, preventing TypeError on null input.

3. Gate usermod palette synthesis on firmware >= 16.0.0, matching the
   version when the usermod feature was introduced. Pre-16.0.0 firmware
   may have custom palettes in the same ID space (255 down), so
   unexpected usermod fields would corrupt that data.

Implementation mirrors _build_custom_palettes pattern: version check
inside the function for clarity and consistency.

Added three regression tests covering edge cases:
- Excess count bounded to 55 max
- null names list handled gracefully
- Pre-16.0.0 firmware skips usermod synthesis

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@mik-laj mik-laj force-pushed the fix/wled-usermod-palettes branch from 86f5645 to cd217c6 Compare May 13, 2026 22:27
Copilot AI review requested due to automatic review settings May 20, 2026 11:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@frenck frenck merged commit f3b5cdf into frenck:main May 20, 2026
22 checks passed
@mik-laj mik-laj mentioned this pull request May 20, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants