Extract shared deserialize helpers on Device#2076
Draft
frenckatron wants to merge 2 commits into
Draft
Conversation
Both `Device.__pre_deserialize__` and `Device.update_from_dict` carried near-identical logic for effects filtering, palette synthesis, and preset/playlist splitting. Any fix on one side risked silently drifting from the other. Introduce three helpers — `_filter_effects`, `_build_palette_dict`, and `_split_presets_playlists` — alongside the existing palette builders. They return raw `dict[str, Any]` so the pre-deserialize path (which hands off to mashumaro) and the `update_from_dict` path (which constructs typed objects via `from_dict` / `**kwargs`) can share the same source of truth. Behavior is preserved: RSVD skip, null-palette fallback, defensive copy of the presets payload, and `pop(0, None)` on both maps.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extract three shared helpers (
_filter_effects,_build_palette_dict,_split_presets_playlists) onDeviceand call them from both__pre_deserialize__andupdate_from_dict.Why
The two methods carried near-identical logic for effects filtering,
palette synthesis, and preset/playlist splitting. Any fix landing in one
risked silently diverging from the other — a real dual-maintenance
hazard. This is the refactor specced for
src/wled/models.py:865-1011.How
_build_custom_palettes/_build_usermod_palettesstatics._build_palette_dictis a@classmethodbecause it composes the other two; the rest are@staticmethod.dict[str, Any]. The pre-deserialize pathhands the dicts to mashumaro directly;
update_from_dictwraps themwith
Effect(**…),Palette(**…), andPreset.from_dict/Playlist.from_dict. One source of truth, two output shapes.RSVDskip, null-palette fallback forless-capable devices, defensive
_presets.copy(), andpop(0, None)on both presets and playlists. Version-check /
WLEDUnsupportedVersionErrorstays inside
__pre_deserialize__since it's deserialization-specific.Testing
ruff check src/wled/models.pyclean.Quality Report
Changes: 1 file changed, 118 insertions(+), 72 deletions(-)
Code scan: clean
Tests: failed (command not found)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline