Files
wled-screen-controller-mixed/server/src/wled_controller/api/schemas/gradients.py
alexei.dolgolyov c26aec916e feat: add gradient entity with CRUD API and storage
Reusable gradient definitions with built-in presets (rainbow, sunset,
ocean, etc.) and user-created gradients. Includes model, JSON store,
Pydantic schemas, REST routes (list/create/update/clone/delete), and
backup/restore integration.
2026-03-24 13:58:04 +03:00

52 lines
2.0 KiB
Python

"""Gradient schemas (CRUD)."""
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field
class GradientStopSchema(BaseModel):
"""A single gradient color stop."""
position: float = Field(description="Position along gradient (0.0-1.0)", ge=0.0, le=1.0)
color: List[int] = Field(description="RGB color [R, G, B]", min_length=3, max_length=3)
class GradientCreate(BaseModel):
"""Request to create a gradient."""
name: str = Field(description="Gradient name", min_length=1, max_length=100)
stops: List[GradientStopSchema] = Field(description="Color stops", min_length=2)
description: Optional[str] = Field(None, description="Optional description", max_length=500)
tags: List[str] = Field(default_factory=list, description="User-defined tags")
class GradientUpdate(BaseModel):
"""Request to update a gradient."""
name: Optional[str] = Field(None, description="Gradient name", min_length=1, max_length=100)
stops: Optional[List[GradientStopSchema]] = Field(None, description="Color stops", min_length=2)
description: Optional[str] = Field(None, description="Optional description", max_length=500)
tags: Optional[List[str]] = None
class GradientResponse(BaseModel):
"""Gradient response."""
id: str = Field(description="Gradient ID")
name: str = Field(description="Gradient name")
stops: List[GradientStopSchema] = Field(description="Color stops")
is_builtin: bool = Field(description="Whether this is a built-in gradient")
description: Optional[str] = Field(None, description="Description")
tags: List[str] = Field(default_factory=list, description="User-defined tags")
created_at: datetime = Field(description="Creation timestamp")
updated_at: datetime = Field(description="Last update timestamp")
class GradientListResponse(BaseModel):
"""List of gradients."""
gradients: List[GradientResponse] = Field(description="List of gradients")
count: int = Field(description="Number of gradients")