Skip to content

Commit

Permalink
added support for custom palettes
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Pearce committed Dec 24, 2024
1 parent 7f05ac7 commit 6879987
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/wled/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 20 additions & 2 deletions src/wled/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 6879987

Please sign in to comment.