Guidance for coding agents (and humans) working in this repository. Read this before making changes; it captures the project's purpose, conventions, commands and gotchas so a change can be made safely without prior conversation history.
WLED.NET is a strongly typed, hard-to-misuse .NET client for the
WLED JSON API. It turns the device's loosely
typed JSON (/json, /json/state, /json/info, /json/eff, /json/pal, /json/cfg,
/json/fxdata, /json/nodes, presets.json, …) into expressive C# types.
Model things well so they're easy to use. Make it impossible to send the wrong information by how we model the library.
Concretely:
- Types over primitives. Prefer value types, enums and command types over raw
int/byte/magic strings (RgbColor,SegmentColors,Selector,ByteAdjust,Toggleable,LightCapability[Flags], the*Id/*Boundsvalue types, …). - Validation at construction. Where WLED documents a range (e.g.
c3is 0–31,briis 0–255, ledmap is 0–9), the constructing type guards it so an out-of-range value throws before it hits the wire. - Read model ≠ write model. Responses are immutable/total; requests/builders expose only what is settable.
- Builders, not nullable bags. High-level fluent builders (
StateUpdate,SegmentUpdate,PlaylistBuilder,ConfigUpdate) sit on top of the raw DTOs.
- Dual DTO layer. Each JSON object is a pair: an immutable
XResponse(all fields, non-null) and a sparse mutableXRequest(nullable fields with[JsonIgnore(WhenWritingNull)]), usually with a staticRequest.From(Response)factory and an implicit operator. The wire format never leaks into the public happy path. [JsonPropertyName]always carries the raw WLED key; the C# member uses a descriptive .NET name (e.g.EffectId→"fx").- Every new endpoint adds a method to
IWLedClient+WLedClient, with GET/POST tests intest/Kevsoft.WLED.Tests(extendJsonBuilderandMockHttpMessageHandler). - Custom
JsonConverters carry the "impossible to misuse" types across the wire and are unit-tested in both directions against realistic WLED payloads. - Unknown keys round-trip. Config sections use
[JsonExtensionData](Unknown) so a read-modify-write cycle never drops firmware-specific fields.
- The library multi-targets
netstandard2.0;net8.0;net9.0;net10.0(seeDirectory.Build.props). Tests run onnet8.0;net9.0;net10.0. - Because of
netstandard2.0, do not use:Math.Clamp— clamp manually.System.HashCode— implementGetHashCode()withuncheckedarithmetic.- newer async/Span API shapes that aren't available there.
- Prefer
readonly struct+IEquatable<T>for small value types.
dotnet build WLED.NET.sln -c Release
dotnet test WLED.NET.sln -c Release- No
[Obsolete]compatibility shims unless explicitly requested. - Record user-facing and breaking changes in
CHANGELOG.md. - Keep raw
XResponse/XRequestDTOs available as escape hatches even when adding ergonomic builders/value types on top.
A feature isn't done when it compiles and tests pass. Also:
- Update the root
README.mdfeature matrix and add/refresh a short usage snippet. - Keep
samples/BasicConsoleexemplary — demonstrate the ergonomic path (builders, intent methods, catalogs, snapshots), not raw DTOs. - Update
CHANGELOG.md.
- WLED JSON API docs: https://kno.wled.ge/interfaces/json-api/
- This repo's
plans/folder contains the staged roadmap (Plans 0–13) and the conventions every plan must uphold.