Add global brightness support to driver

Handle per-device global brightness via ESPNow messages and apply it alongside per-preset brightness in all patterns.
This commit is contained in:
2026-01-29 00:02:28 +13:00
parent 337e8c9906
commit f35d8f7084
2 changed files with 15 additions and 5 deletions

View File

@@ -28,9 +28,16 @@ while True:
if e.any():
host, msg = e.recv()
data = json.loads(msg)
if data["v"] != "1":
# Only handle messages with the expected version.
if data.get("v") != "1":
continue
print(data)
# Global brightness (0255) for this device
if "b" in data:
try:
patterns.b = max(0, min(255, int(data["b"])))
except (TypeError, ValueError):
pass
if "presets" in data:
for name, preset_data in data["presets"].items():
# Convert hex color strings to RGB tuples and reorder based on device color order
@@ -44,4 +51,3 @@ while True:
preset_name = select_list[0]
step = select_list[1] if len(select_list) > 1 else None
patterns.select(preset_name, step=step)