@@ -253,6 +253,12 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
253253 // segment has RGB or White
254254 for (size_t i = 0 ; i < 3 ; i++)
255255 {
256+ // JSON "col" array can contain the following values for each of segment's colors (primary, background, custom):
257+ // "col":[int|string|object|array, int|string|object|array, int|string|object|array]
258+ // int = Kelvin temperature or 0 for black
259+ // string = hex representation of [WW]RRGGBB or "r" for random color
260+ // object = individual channel control {"r":0,"g":127,"b":255,"w":255}, each being optional (valid to send {})
261+ // array = direct channel values [r,g,b,w] (w element being optional)
256262 int rgbw[] = {0 ,0 ,0 ,0 };
257263 bool colValid = false ;
258264 JsonArray colX = colarr[i];
@@ -265,6 +271,9 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
265271 if (kelvin == 0 ) seg.setColor (i, 0 );
266272 if (kelvin > 0 ) colorKtoRGB (kelvin, brgbw);
267273 colValid = true ;
274+ } else if (hexCol[0 ] == ' r' && hexCol[1 ] == ' \0 ' ) { // Random colors via JSON API in Segment object like col=["r","r","r"] · Issue #4996
275+ setRandomColor (brgbw);
276+ colValid = true ;
268277 } else { // HEX string, e.g. "FFAA00"
269278 colValid = colorFromHexString (brgbw, hexCol);
270279 }
0 commit comments