feat(zones): profile-scoped groups, zone modes, sequence brightness
- Optional profile_id on groups; UI and API for shared vs profile-only groups\n- Zone content_kind (presets vs sequences); edit modal shows matching sections; devices via groups only\n- Server sequence playback folds zone brightness into preset wire b (per MAC where needed)\n- Related preset/sequence/audio/beat-route and client updates Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -78,13 +78,49 @@ def build_select_message(device_name, preset_name, step=None):
|
||||
return {device_name: select_list}
|
||||
|
||||
|
||||
def build_preset_dict(preset_data):
|
||||
def _hex_from_background_raw(bg_raw):
|
||||
"""Coerce ``background`` / ``bg`` field to a ``#RRGGBB`` string (driver wire format)."""
|
||||
if isinstance(bg_raw, str):
|
||||
bg = bg_raw if bg_raw.startswith("#") else f"#{bg_raw}"
|
||||
return bg
|
||||
if isinstance(bg_raw, (list, tuple)) and len(bg_raw) == 3:
|
||||
return f"#{int(bg_raw[0]):02x}{int(bg_raw[1]):02x}{int(bg_raw[2]):02x}"
|
||||
return "#000000"
|
||||
|
||||
|
||||
def resolve_preset_background_hex(preset_data, palette_colors=None):
|
||||
"""
|
||||
Resolved background as ``#RRGGBB``. When ``palette_colors`` is a non-empty list and
|
||||
``background_palette_ref`` is set, uses that palette index; otherwise stored ``background`` / ``bg``.
|
||||
"""
|
||||
if not isinstance(preset_data, dict):
|
||||
return "#000000"
|
||||
pal = list(palette_colors) if isinstance(palette_colors, list) else []
|
||||
ref = preset_data.get("background_palette_ref", preset_data.get("backgroundPaletteRef"))
|
||||
if pal and ref is not None:
|
||||
try:
|
||||
idx = int(ref)
|
||||
except (TypeError, ValueError):
|
||||
idx = None
|
||||
else:
|
||||
if isinstance(idx, int) and 0 <= idx < len(pal):
|
||||
c = pal[idx]
|
||||
if isinstance(c, str) and c.strip().startswith("#"):
|
||||
s = c.strip()
|
||||
if len(s) == 7 and all(ch in "0123456789abcdefABCDEF" for ch in s[1:]):
|
||||
return s.upper()
|
||||
bg_raw = preset_data.get("background", preset_data.get("bg", "#000000"))
|
||||
return _hex_from_background_raw(bg_raw)
|
||||
|
||||
|
||||
def build_preset_dict(preset_data, palette_colors=None):
|
||||
"""
|
||||
Convert preset data to API-compliant format.
|
||||
|
||||
Args:
|
||||
preset_data: Dictionary with preset fields (may include name, pattern, colors, etc.)
|
||||
|
||||
palette_colors: Optional list of ``#RRGGBB`` strings for ``background_palette_ref`` resolution.
|
||||
|
||||
Returns:
|
||||
Dictionary with preset in API-compliant format (without name field)
|
||||
|
||||
@@ -137,13 +173,7 @@ def build_preset_dict(preset_data):
|
||||
auto_raw = preset_data.get("auto", preset_data.get("a", True))
|
||||
auto_bool = _coerce_auto(auto_raw)
|
||||
|
||||
bg_raw = preset_data.get("background", preset_data.get("bg", "#000000"))
|
||||
if isinstance(bg_raw, str):
|
||||
bg = bg_raw if bg_raw.startswith("#") else f"#{bg_raw}"
|
||||
elif isinstance(bg_raw, (list, tuple)) and len(bg_raw) == 3:
|
||||
bg = f"#{int(bg_raw[0]):02x}{int(bg_raw[1]):02x}{int(bg_raw[2]):02x}"
|
||||
else:
|
||||
bg = "#000000"
|
||||
bg = resolve_preset_background_hex(preset_data, palette_colors)
|
||||
|
||||
# Build payload using the short keys expected by led-driver
|
||||
preset = {
|
||||
@@ -164,13 +194,14 @@ def build_preset_dict(preset_data):
|
||||
return preset
|
||||
|
||||
|
||||
def build_presets_dict(presets_data):
|
||||
def build_presets_dict(presets_data, palette_colors=None):
|
||||
"""
|
||||
Convert multiple presets to API-compliant format.
|
||||
|
||||
Args:
|
||||
presets_data: Dictionary mapping preset names to preset data
|
||||
|
||||
palette_colors: Optional list of ``#RRGGBB`` strings for background palette ref resolution.
|
||||
|
||||
Returns:
|
||||
Dictionary mapping preset names to API-compliant preset objects
|
||||
|
||||
@@ -190,7 +221,7 @@ def build_presets_dict(presets_data):
|
||||
"""
|
||||
result = {}
|
||||
for preset_name, preset_data in presets_data.items():
|
||||
result[preset_name] = build_preset_dict(preset_data)
|
||||
result[preset_name] = build_preset_dict(preset_data, palette_colors)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user