Add software brightness control for Adalight devices

Emulates hardware brightness by multiplying pixel values before serial
send. Stored per-device and persisted across restarts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 10:56:19 +03:00
parent 27c97c3141
commit 77dd342c4c
5 changed files with 31 additions and 4 deletions

View File

@@ -22,10 +22,10 @@ class AdalightDeviceProvider(LEDDeviceProvider):
@property
def capabilities(self) -> set:
# No hardware brightness control, no standby required
# manual_led_count: user must specify LED count (can't auto-detect)
# power_control: can blank LEDs by sending all-black pixels
return {"manual_led_count", "power_control"}
# brightness_control: software brightness (multiplies pixel values before sending)
return {"manual_led_count", "power_control", "brightness_control"}
def create_client(self, url: str, **kwargs) -> LEDClient:
from wled_controller.core.adalight_client import AdalightClient

View File

@@ -166,6 +166,8 @@ class DeviceState:
baud_rate: Optional[int] = None
health: DeviceHealth = field(default_factory=DeviceHealth)
health_task: Optional[asyncio.Task] = None
# Software brightness for devices without hardware brightness (e.g. Adalight)
software_brightness: int = 255
# Calibration test mode (works independently of target processing)
test_mode_active: bool = False
test_mode_edges: Dict[str, Tuple[int, int, int]] = field(default_factory=dict)
@@ -281,6 +283,7 @@ class ProcessorManager:
calibration: Optional[CalibrationConfig] = None,
device_type: str = "wled",
baud_rate: Optional[int] = None,
software_brightness: int = 255,
):
"""Register a device for health monitoring.
@@ -291,6 +294,7 @@ class ProcessorManager:
calibration: Calibration config (creates default if None)
device_type: LED device type (e.g. "wled")
baud_rate: Serial baud rate (for adalight devices)
software_brightness: Software brightness 0-255 (for devices without hardware brightness)
"""
if device_id in self._devices:
raise ValueError(f"Device {device_id} already registered")
@@ -305,6 +309,7 @@ class ProcessorManager:
calibration=calibration,
device_type=device_type,
baud_rate=baud_rate,
software_brightness=software_brightness,
)
self._devices[device_id] = state
@@ -775,6 +780,8 @@ class ProcessorManager:
if not state.is_running or state.led_client is None:
break
brightness_value = int(led_brightness * 255)
if device_state and device_state.software_brightness < 255:
brightness_value = brightness_value * device_state.software_brightness // 255
if state.led_client.supports_fast_send:
state.led_client.send_pixels_fast(state.previous_colors, brightness=brightness_value)
else:
@@ -803,6 +810,8 @@ class ProcessorManager:
if not state.is_running or state.led_client is None:
break
brightness_value = int(led_brightness * 255)
if device_state and device_state.software_brightness < 255:
brightness_value = brightness_value * device_state.software_brightness // 255
t_send_start = time.perf_counter()
if state.led_client.supports_fast_send:
state.led_client.send_pixels_fast(led_colors, brightness=brightness_value)