From 6879987d5db8c2abad3a472998aacc28d0c95692 Mon Sep 17 00:00:00 2001 From: Benjamin Pearce Date: Tue, 24 Dec 2024 00:06:07 -0500 Subject: [PATCH] added support for custom palettes --- src/wled/cli/__init__.py | 3 +++ src/wled/models.py | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/wled/cli/__init__.py b/src/wled/cli/__init__.py index 3c3483dd..77cd0e14 100644 --- a/src/wled/cli/__init__.py +++ b/src/wled/cli/__init__.py @@ -115,6 +115,9 @@ async def command_info( info_table.add_section() info_table.add_row("Effect count", f"{device.info.effect_count} effects") info_table.add_row("Palette count", f"{device.info.palette_count} palettes") + info_table.add_row( + "Custom palette count", f"{device.info.custom_palette_count} custom palettes" + ) info_table.add_section() info_table.add_row("Sync UDP port", str(device.info.udp_port)) diff --git a/src/wled/models.py b/src/wled/models.py index 7acea0f2..68383d80 100644 --- a/src/wled/models.py +++ b/src/wled/models.py @@ -2,6 +2,7 @@ from __future__ import annotations +import itertools from dataclasses import dataclass, field from datetime import UTC, datetime, timedelta from functools import cached_property @@ -464,6 +465,11 @@ class Info(BaseModel): # pylint: disable=too-many-instance-attributes palette_count: int = field(default=0, metadata=field_options(alias="palcount")) """Number of palettes configured.""" + custom_palette_count: int = field( + default=0, metadata=field_options(alias="cpalcount") + ) + """Number of custom palettes configured.""" + product: str = "DIY Light" """The product name. Always FOSS for standard installations.""" @@ -744,7 +750,13 @@ def __pre_deserialize__(cls, d: dict[Any, Any]) -> dict[Any, Any]: if _palettes := d.get("palettes"): d["palettes"] = { palette_id: {"palette_id": palette_id, "name": name} - for palette_id, name in enumerate(_palettes) + for palette_id, name in itertools.chain( + enumerate(_palettes), + ( + (255 - i, f"~ Custom {i} ~") + for i in range(d.get("info", {}).get("cpalcount", 0)) + ), + ) } elif _palettes is None: # Some less capable devices don't have palettes and @@ -802,7 +814,13 @@ def update_from_dict(self, data: dict[str, Any]) -> Device: if _palettes := data.get("palettes"): self.palettes = { palette_id: Palette(palette_id=palette_id, name=name) - for palette_id, name in enumerate(_palettes) + for palette_id, name in itertools.chain( + enumerate(_palettes), + ( + (255 - i, f"~ Custom {i} ~") + for i in range(self.info.custom_palette_count) + ), + ) } if _presets := data.get("presets"):