@@ -64,6 +64,22 @@ namespace {
6464 }
6565}
6666
67+ /* *
68+ * Deserialize a segment description from a JSON object and apply it to the specified segment slot.
69+ *
70+ * Parses and applies geometry, naming, grouping/spacing/offset, 2D bounds, mode, palette, colors
71+ * (supports kelvin, hex, "r" random, object or array formats), per-LED assignments, options (on/frz/sel/rev/mi),
72+ * speed/intensity, custom channels, checks, blend mode, and LOXONE mappings. The function may append a new
73+ * segment, delete a segment, perform a repeat expansion to create multiple segments, and mark global state
74+ * as changed when segment parameters differ.
75+ *
76+ * @param elem JSON object describing the segment (API format).
77+ * @param it Default segment index to use when `elem["id"]` is not provided.
78+ * @param presetId Optional preset identifier; when nonzero, preset-related side effects (e.g., playlist unloading)
79+ * are suppressed or handled differently.
80+ * @return true if the JSON was valid for the target id and the segment was applied (or created); false if the
81+ * target id is out of range or the descriptor is invalid (e.g., attempting to create an empty segment).
82+ */
6783static bool deserializeSegment (JsonObject elem, byte it, byte presetId = 0 )
6884{
6985 byte id = elem[" id" ] | it;
@@ -205,7 +221,7 @@ static bool deserializeSegment(JsonObject elem, byte it, byte presetId = 0)
205221 // JSON "col" array can contain the following values for each of segment's colors (primary, background, custom):
206222 // "col":[int|string|object|array, int|string|object|array, int|string|object|array]
207223 // int = Kelvin temperature or 0 for black
208- // string = hex representation of [WW]RRGGBB
224+ // string = hex representation of [WW]RRGGBB or "r" for random color
209225 // object = individual channel control {"r":0,"g":127,"b":255,"w":255}, each being optional (valid to send {})
210226 // array = direct channel values [r,g,b,w] (w element being optional)
211227 int rgbw[] = {0 ,0 ,0 ,0 };
@@ -229,6 +245,9 @@ static bool deserializeSegment(JsonObject elem, byte it, byte presetId = 0)
229245 if (kelvin == 0 ) seg.setColor (i, 0 );
230246 if (kelvin > 0 ) colorKtoRGB (kelvin, brgbw);
231247 colValid = true ;
248+ } else if (hexCol[0 ] == ' r' && hexCol[1 ] == ' \0 ' ) { // Random colors via JSON API in Segment object like col=["r","r","r"] · Issue #4996
249+ setRandomColor (brgbw);
250+ colValid = true ;
232251 } else { // HEX string, e.g. "FFAA00"
233252 colValid = colorFromHexString (brgbw, hexCol);
234253 }
@@ -1240,4 +1259,4 @@ bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient)
12401259 #endif
12411260 return true ;
12421261}
1243- #endif
1262+ #endif
0 commit comments