Fix numpy serialization and add comprehensive error logging
Some checks failed
Validate / validate (push) Failing after 9s

Server fixes:
- Fix numpy uint8 JSON serialization by converting to Python int
- Change WLED payload to flat array format [r,g,b,r,g,b,...]
- Add payload debugging logs (size, LED count, sample data)

Web UI improvements:
- Add comprehensive console logging for device errors
- Log actual error messages from state.errors array
- Log device operations (start/stop/add) with details
- Fix password field form validation warning

The HTTP API may have payload size limitations for large LED counts.
Consider UDP protocols (DDP/E1.31) for better real-time performance.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 20:25:58 +03:00
parent eca81e11cf
commit ec3c40d59c
4 changed files with 84 additions and 41 deletions

View File

@@ -234,26 +234,35 @@ class WLEDClient:
if not 0 <= brightness <= 255:
raise ValueError(f"Brightness must be 0-255, got {brightness}")
# Validate pixel values
# Validate and convert pixel values to Python ints (handles numpy types)
# WLED expects a flat array: [r1, g1, b1, r2, g2, b2, ...]
flat_pixels = []
for i, (r, g, b) in enumerate(pixels):
if not (0 <= r <= 255 and 0 <= g <= 255 and 0 <= b <= 255):
raise ValueError(f"Invalid RGB values at index {i}: ({r}, {g}, {b})")
# Convert to Python int and flatten to [r, g, b, r, g, b, ...]
flat_pixels.extend([int(r), int(g), int(b)])
# Build WLED JSON state
# Build WLED JSON state with flat pixel array
payload = {
"on": True,
"bri": brightness,
"bri": int(brightness), # Ensure brightness is also a Python int
"seg": [
{
"id": segment_id,
"i": pixels, # Individual LED colors
"i": flat_pixels, # Individual LED colors as flat array
}
],
}
# Log payload details for debugging
logger.debug(f"Sending {len(pixels)} LEDs ({len(flat_pixels)} values) to WLED")
logger.debug(f"Payload size: ~{len(str(payload))} bytes")
logger.debug(f"First 3 LEDs: {flat_pixels[:9] if len(flat_pixels) >= 9 else flat_pixels}")
try:
await self._request("POST", "/json/state", json_data=payload)
logger.debug(f"Sent {len(pixels)} pixel colors to WLED device")
logger.debug(f"Successfully sent pixel colors to WLED device")
return True
except Exception as e: