#!/usr/bin/env python3 """ Test script to verify that selected color is used for patterns """ import json import os import sys # Add src to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from control_server import LightingController def test_color_selection(): """Test that the first selected color is used as RGB""" # Create controller (without connecting) controller = LightingController(transport="spi") # Load config controller._load_config() print("Color Palette Selection Test") print("=" * 50) print(f"\nColor Palette:") for i, color in enumerate(controller.color_palette): r, g, b = color['r'], color['g'], color['b'] print(f" Slot {i}: RGB({r:3d}, {g:3d}, {b:3d})") print(f"\nSelected Indices: {controller.selected_color_indices}") if controller.selected_color_indices: first_index = controller.selected_color_indices[0] print(f"First Selected: Slot {first_index}") selected_color = controller.color_palette[first_index] print(f" RGB({selected_color['r']}, {selected_color['g']}, {selected_color['b']})") # Test the _current_color_rgb method rgb = controller._current_color_rgb() print(f"\nPattern RGB (from _current_color_rgb): RGB{rgb}") # Verify it matches the first selected color if controller.selected_color_indices: first_index = controller.selected_color_indices[0] expected_color = controller.color_palette[first_index] expected_rgb = (expected_color['r'], expected_color['g'], expected_color['b']) if rgb == expected_rgb: print("\n✅ SUCCESS: Pattern RGB matches first selected color!") else: print(f"\n❌ FAIL: Expected {expected_rgb}, got {rgb}") print("=" * 50) if __name__ == "__main__": test_color_selection()