Skip to content

Presets are state documents #196

Closed
Closed

Description

@MoonModules

Plan 2026-10-02, closed 2026-10-25, shipped.

Goal

A preset becomes any part of the device's state, one hierarchical JSON document, and that document becomes the one shape for everything that holds state: a REST call, a preset file, a card's { }, a gallery entry, a config file, a device model and a scenario fixture. A preset was one whole container, so a palette could only be saved with the driver's pins; adding an effect with its controls took several requests (a user reported it); six shapes described one tree, each with its own parser.

Outcome

JSON Merge Patch (RFC 7386) over the module tree, with "$patch": "replace" for "exactly these children" and null removing, one prepare at the end. PATCH /api/state adds an effect with its controls in one request. A preset is a document, a palette-only preset possible. Each card's { } shows its document with copy; each card saves itself as a preset; the gallery installs with a click and holds a hundred entries with thumbnails, search, filter, sort and a detail view. Config files, deviceModels.json, Improv's apply op and scenario fixtures are documents, each old reader removed. Verified on the desktop, the Olimex and two S3s; provisioning over Improv and the web installer on a P4; a flat backup restored on the P4; documents of up to 30 KB on an S3; a palette-only preset over an effects preset.

Decisions

  • One JSON for everything that holds state (the product owner, 2026-10-04): end state B of three weighed. A, REST and presets only, left config files flat, two shapes for one subtree. C, A plus deviceModels.json, converted an installer file and kept the flat config format beside the document engine. B cost more steps and a config file shape change, which MIGRATING records, and removed the positional key code and three list formats.
  • The directive is "$patch": "replace", Kubernetes' strategic merge patch spelling, since Merge Patch has no word for "exactly these children" and a $ key is one no control can carry.
  • The UI's schema stays its own shape: GET /api/state and the WebSocket carry each control's type, range and options, which a card needs to draw and a document does not hold.
  • One create path in core: every add, replace and delete applies a one-member document.
  • Config files apply leniently as a stored file: a type this build lacks and a key no control matches are skipped and logged, and a value clamps.
  • Playlists stay out: a preset listing presets with durations is a later step on this engine.
  • WLED is the prior art: a preset is a stored /json/state body. Here the state is a tree of modules, so a document also creates and removes them.

Where it lives

What Home
The apply engine: Merge Patch, the directive, null, one prepare Integrating, Setting everything at once
PATCH /api/state The REST API
What a preset holds, applying and arranging one Presets, the process
A card's { } Web UI
The gallery Install from the gallery
Config files as documents MoonModule, Persistence, MIGRATING, MIGRATING, a preset
deviceModels.json entries and Improv's apply op MoonInstaller
Scenario fixtures as apply_state documents testing.md
The engine StateDocument.h, unit_StateDocument.cpp

Steps

  • The apply engine in core
  • PATCH /api/state
  • Presets as documents, the role following from the containers touched
  • A card's { } shows its document, the diagnostic dump a link beside it
  • A save-as-preset button on each card
  • The gallery in the UI
  • A gallery that holds a hundred entries
  • Config files, deviceModels.json and scenario fixtures as documents, each removing its old reader

Shipped in

#125 (commit 5189985), #127 (54a2f33; 84c176c, the browsable gallery; 33fb432), #133 (171f355, every config a state document), #155 (3beece2). The restore found a write refused while its file was read, fixed in the HTTP server, and a P4 panic on flash writes, fixed by placing FreeRTOS in IRAM.

Still open

Activity

  1. added
    plan
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions